天天看點

切割檔案

split指令

檔案過濾分割與合并

split指令可以将一個大檔案分割成很多個小檔案,有時需要将檔案分割成更小的片段,比如為提高可讀性,生成日志等。

選項

-b:值為每一輸出檔案的大小,機關為 byte。

-C:每一輸出檔中,單行的最大 byte 數。

-d:使用數字作為字尾。

-l:值為每一輸出檔的列數大小。

執行個體

生成一個大小為100KB的測試檔案:

[root@localhost split]# dd if=/dev/zero bs=100k count=1 of=date.file

使用split指令将上面建立的date.file檔案分割成大小為10KB的小檔案:

[root@localhost split]# split -b 10k date.file

[root@localhost split]# ls

date.file  xaa  xab  xac  xad  xae  xaf  xag  xah  xai  xaj

檔案被分割成多個帶有字母的字尾檔案,如果想用數字字尾可使用-d參數,同時可以使用-a length來指定字尾的長度:

[root@localhost split]# split -b 10k date.file -d -a 3

date.file  x000  x001  x002  x003  x004  x005  x006  x007  x008  x009

為分割後的檔案指定檔案名的字首:

[root@localhost split]# split -b 10k date.file -d -a 3 split_file

date.file  split_file000  split_file001  split_file002  split_file003  

split_file004  split_file005  split_file006  split_file007  

split_file008  split_file009