2014年11月3日 星期一

Sort Tutorail

原文轉載:How to Sort Files in Linux using Sort Command

Sort command is helpful to sort/order lines in text files. You can sort the data in text file and display the output on the screen, or redirect it to a file. Based on your requirement, sort provides several command line options for sorting data in a text file.

$ sort [-options]
  • -M: compare (unknown) < `JAN' < ... < `DEC'
  • -h: compare human readable numbers (e.g., 2K 1G)
  • -n: compare according to string numerical value
  • -r: reverse the result of comparisons
  • -k: start a key at POS1 (origin 1), end it at POS2 (default end of line).
  • -o: write result to FILE instead of standard output

2014年11月2日 星期日

Ack-grep Tutorial

Recently, ack became the replacement for grep when I need to spot editing point in my code bases. It wins over grep in terms of:
  • A better pattern match syntax with Perl regular expressions
  • Smarter to limit searches in directories or certain file types
  • Much prettier display of result
  • Config files to make customization permanent

2014年11月1日 星期六

How to Read Tcpdump Output

學習過 tcpdump 用法以後,發現 tcpdump 輸出了很多文字訊息,讓我們花點時間仔細分析一下這些訊息的內容,魔鬼可是藏在細節中喔。下面是一個很常見的封包,裡面有許多的單字,好像在哪裡看過。如果對於 IP datagram 和 TCP packet 格式熟悉的話,應該可以從這裡產生一些印象與連結。
root@ip-10-0-20-60:~# tcpdump -nnvvXSs 0 host 10.0.30.21
12:32:38.887309 IP (tos 0x0, ttl 64, id 4945, offset 0, flags [DF], proto TCP (6), length 60)
    10.0.30.21.55390 > 10.0.20.60.80: Flags [S], cksum 0x0dff (correct), seq 711110784, win 26883, options [mss 8961,sackOK,TS val 368813009 ecr 0,nop,wscale 9], length 0
        0x0000:  4500 003c 1351 4000 4006 e11a 0a00 1e15  E..<.Q@.@.......
        0x0010:  0a00 143c d85e 0050 2a62 b080 0000 0000  ...<.^.P*b......
        0x0020:  a002 6903 0dff 0000 0204 2301 0402 080a  ..i.......#.....
        0x0030:  15fb a3d1 0000 0000 0103 0309            ............