分割文件命令split

使用Linux自带的split命令,可以将很大的文件分割成若干个小文件,以方便传送和使用。

命令格式:

split [option] [input file] [output file]

常用选项:

l:按行对文件进行分割。

b:按字节对文件进行分割。

C:按字节对文件进行分割,split会尽量保持一个整行。

d:使用数字作为输出文件的后缀。

在指定输出文件名称后,split会将分割的小文件以指定的名称为前缀,在其后加上诸如aa、ab等后缀作为分割后的文件名。

用法示例:

(1)按行分割:

[root@localhost test]# cat students
2821020225 Liulu        Sichuan Lixia   01/23/93        89 76 88 72 325 81
2821020115 Liumin       Henan   lixia   05/14/94        78 65 59 78 280 70
2721020321 Xuli         Jiangsu Luolei  12/25/92        76 81 85 79 321 80
2921020632 Xiayu        Shanxi  Hetao   03/26/93        78 86 92 78 334 84
2721010409 Liwei        Sichuan tangwei 11/21/92        98 88 85 85 356 89
2921050313 Heli         Xizang  Tangwei 07/12/94        56 78 80 45 259 65
2721030227 Wangtao      Yunnan  Huli    03/21/93        87 76 69 88 320 80
[root@localhost test]# split -l 3 students student
#上面命令执行完会生成如下3个文件:
-rw-r--r-- 1 root root  181 Dec  9 09:31 studentaa
-rw-r--r-- 1 root root  183 Dec  9 09:31 studentab
-rw-r--r-- 1 root root   59 Dec  9 09:31 studentac

[root@localhost test]# cat  studentaa
2821020225 Liulu        Sichuan Lixia   01/23/93        89 76 88 72 325 81
2821020115 Liumin       Henan   lixia   05/14/94        78 65 59 78 280 70
2721020321 Xuli         Jiangsu Luolei  12/25/92        76 81 85 79 321 80
[root@localhost test]# cat  studentab
2921020632 Xiayu        Shanxi  Hetao   03/26/93        78 86 92 78 334 84
2721010409 Liwei        Sichuan tangwei 11/21/92        98 88 85 85 356 89
2921050313 Heli         Xizang  Tangwei 07/12/94        56 78 80 45 259 65
[root@localhost test]# cat  studentac
2721030227 Wangtao      Yunnan  Huli    03/21/93        87 76 69 88 320 80

(2)按字节分割:

[root@localhost test]# ls -al smb.conf
-rw-r--r-- 1 root root 9780 Dec  9 09:36 smb.conf
[root@localhost test]# split -b 1024 smb.conf smb
[root@localhost test]# ls -al smb*
-rw-r--r-- 1 root root 1024 Dec  9 09:36 smbaa
-rw-r--r-- 1 root root 1024 Dec  9 09:36 smbab
-rw-r--r-- 1 root root 1024 Dec  9 09:36 smbac
-rw-r--r-- 1 root root 1024 Dec  9 09:36 smbad
-rw-r--r-- 1 root root 1024 Dec  9 09:36 smbae
-rw-r--r-- 1 root root 1024 Dec  9 09:36 smbaf
-rw-r--r-- 1 root root 1024 Dec  9 09:36 smbag
-rw-r--r-- 1 root root 1024 Dec  9 09:36 smbah
-rw-r--r-- 1 root root 1024 Dec  9 09:36 smbai
-rw-r--r-- 1 root root  564 Dec  9 09:36 smbaj
-rw-r--r-- 1 root root 9780 Dec  9 09:36 smb.conf

利用split对文件按字节进行分割时,split每一次读取512个字节的数据放入分割的文件中,然后进行下一次读取数据操作。因此通常推荐分割后的大小应该为512字节的倍数。

posted @ 2013-12-09 09:37  ITtecman  阅读(765)  评论(0编辑  收藏  举报