我们可以使用-d选项更改为数字标识符:

john@sles01:~/split> split -d file1
john@sles01:~/split> ls -l
total 372
-rw-r--r-- 1 john users 112000 May  7 10:26 file1
-rw-r--r-- 1 john users  14000 May  7 10:33 x00
-rw-r--r-- 1 john users  14000 May  7 10:33 x01
-rw-r--r-- 1 john users  14000 May  7 10:33 x02
-rw-r--r-- 1 john users  14000 May  7 10:33 x03
-rw-r--r-- 1 john users  14000 May  7 10:33 x04
-rw-r--r-- 1 john users  14000 May  7 10:33 x05
-rw-r--r-- 1 john users  14000 May  7 10:33 x06
-rw-r--r-- 1 john users  14000 May  7 10:33 x07

分割命令

使用split命令分割文件。split命令是一个非常有用的实用程序,可让您将大文件拆分为较小的文件。

在下面的示例中,我们将一个大文件拆分为多个小文件:

john@sles01:~/split> ls -l
total 116
-rw-r--r-- 1 john users 112000 May  7 10:26 file1
john@sles01:~/split> wc -l file1
8000 file1

从上面我们可以看到文件file1包含8000行。

默认情况下,当我们指定split命令时,文件被分解为最多包含1000行的文件。该值可以修改。

john@sles01:~/split> split file1
john@sles01:~/split> ls -l
total 244
-rw-r--r-- 1 john users 112000 May  7 10:26 file1
-rw-r--r-- 1 john users  14000 May  7 10:29 xaa
-rw-r--r-- 1 john users  14000 May  7 10:29 xab
-rw-r--r-- 1 john users  14000 May  7 10:29 xac
-rw-r--r-- 1 john users  14000 May  7 10:29 xad
-rw-r--r-- 1 john users  14000 May  7 10:29 xae
-rw-r--r-- 1 john users  14000 May  7 10:29 xaf
-rw-r--r-- 1 john users  14000 May  7 10:29 xag
-rw-r--r-- 1 john users  14000 May  7 10:29 xah

john@sles01:~/split> wc -l xaa
1000 xaa

对file1运行split命令后,我们可以看到现在有八个较小的文件,每个文件包含1000行。

八个文件中的每个文件都被赋予一个唯一的名称,以xaa,xab,xac等开头。

我们还可以使用-l选项指定每个文件中所需的行数:

john@sles01:~/split> split -l4000 file1
john@sles01:~/split> ls -l
total 236
-rw-r--r-- 1 john users 112000 May  7 10:26 file1
-rw-r--r-- 1 john users  56000 May  7 10:39 xaa
-rw-r--r-- 1 john users  56000 May  7 10:39 xab
john@sles01:~/split> wc -l xaa
4000 xaa

通过在-l选项之后指定4000,我们将文件数减少到两个。每个文件现在包含4000行!

split命令-分割较大的文件

使用split命令将较大的文件拆分为较小的文件。

使用cat命令将文件重新结合在一起。

cat通常用于快速向stdout显示文件的内容,但是,其真正功能是连接文件。在下面的示例中,我们将文件xaa与文件xab联接(连接):

john@sles01:~/split> rm file1
john@sles01:~/split> cat xaa xab > file1
john@sles01:~/split> ls -l
total 236
-rw-r--r-- 1 john users 112000 May  7 11:08 file1
-rw-r--r-- 1 john users  56000 May  7 11:08 xaa
-rw-r--r-- 1 john users  56000 May  7 11:08 xab

我们还可以使用-n选项将大文件拆分为指定数量的

john@sles01:~/split> split -n4 file1
john@sles01:~/split> ls -l
total 228
-rw-r--r-- 1 john users 112000 May  7 10:26 file1
-rw-r--r-- 1 john users  28000 May  7 10:36 xaa
-rw-r--r-- 1 john users  28000 May  7 10:36 xab
-rw-r--r-- 1 john users  28000 May  7 10:36 xac
-rw-r--r-- 1 john users  28000 May  7 10:36 xad
john@sles01:~/split> wc -l xaa
2000 xaa

现在我们有四个文件,每个文件有2000行。

日期:2019-04-29 03:17:28 来源:oir作者:oir