liunx 分割合併文件


dd的作用是轉換和拷貝文件,我們可以利用它來分割文件,相關的選項如下:

if=filename:輸入的文件名

of=finename:輸出的文件名

bs=bytes:一次讀寫的字節數,默認是512bytes

skip=blocks:拷貝前,跳過的輸入文件的前blocks塊,塊的大小有bs決定

count=blocks:只拷貝輸入文件的前blocks塊 

例如,現在有一個文件file,大小爲116616字節:

  1. [root]# du -b file  

  2. 116616  file  

將其分割爲兩文件file1和file2,那我們就設置每塊爲1024字節,將file的前60塊放入file1,餘下的放入file2:

  1. [root]# dd if=file bs=1024 count=60 skip=0  of=file1  

  2. [root]# dd if=file bs=1024 count=60 skip=60 of=file2  

然後用cat將兩個文件合併爲file.bak,要注意文件的順序:

  1. [root]# cat file1 file2 > file.bak  

可以用md5sum驗證一下file和file.bak:

  1. [root]# md5sum file  

  2. 3ff53f7c30421ace632eefff36148a70  file  

  3. [root]# md5sum file.bak  

  4. 3ff53f7c30421ace632eefff36148a70  file.bak  

可以證明兩個文件時完全相同的。


grep手冊中的解釋:

Context Line Control

-A NUM, --after-context=NUM
   Print NUM  lines  of  trailing  context  after  matching  lines.
   Places   a  line  containing  a  group  separator  (--)  between
   contiguous groups of matches.  With the  -o  or  --only-matching
   option, this has no effect and a warning is given.

-B NUM, --before-context=NUM
   Print  NUM  lines  of  leading  context  before  matching lines.
   Places  a  line  containing  a  group  separator  (--)   between
   contiguous  groups  of  matches.  With the -o or --only-matching
   option, this has no effect and a warning is given.

-C NUM, -NUM, --context=NUM
   Print NUM lines of output context.  Places a line  containing  a
   group separator (--) between contiguous groups of matches.  With
   the -o or --only-matching option,  this  has  no  effect  and  a
   warning is given.

簡單翻譯就是,-A -B -C 後面都跟阿拉伯數字,-A是顯示匹配後和它後面的n行。-B是顯示匹配行和它前面的n行。-C是匹配行和它前後各n行。總體來說,-C覆蓋面最大。用它保險些。哈哈。這3個開關都是關於匹配行的上下文的(context)。

於是,

  grep -A 4 wikipedia 密碼文件.txt

grep -A 100000 "/pic/" t_pic_queue



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章