In Linux, it is common to use the tar command to package and compress files. However, the Linux File System has a limit on the file size. That is to say, a file cannot exceed 2 GB. If the content of the compressed package is large, the final result will exceed 2 GB, so what should we do? Or if the compressed package needs to be backed up through a CD, and the size of each CD is only 700 mb, how should we store it? The solution is to split the final compressed package according to the specified size, which requires the split command.
Example:
To package and compress the logs directory and split it into multiple 1 m Files, run the following command:
Tar CJF-logs/| split-B 1 m-logs.tar.bz2.
The following files are generated:
-RW-r -- 1 httpd nobody 1048576 Oct 5 :37 logs.tar.bz2. AA
-RW-r -- 1 httpd nobody 1048576 Oct 5 :37 logs.tar.bz2. AB
-RW-r -- 1 httpd nobody 1048576 Oct 5 :37 logs.tar.bz2. AC
-RW-r -- 1 httpd nobody 1048576 Oct 5 :38 logs.tar.bz2. ad
-RW-r -- 1 httpd nobody 1048576 Oct 5 :38 logs.tar.bz2. AE
-RW-r -- 1 httpd nobody 829440 Oct 5 :39 logs.tar.bz2. af
In this way, the goal of storing the compressed package is achieved, but what should we do when we need to decompress the package? You just need to execute the following command:
Cat logs.tar.bz2. A * | tar XJ
Here we will explain some commands.
The red part of the compressed and split command line is the corresponding I/O file name parameter, where-indicates the standard input or output. .. The two then connect their standard input and output through the pipeline.
Here we will explain the parameter Meanings of the split command:
-B Size indicates the size of each file. The unit can be B (512 bytes), K (1 K), and M (1 m)
-D. Use numbers instead of letters as the suffix.
-A x indicates the length of the suffix. The default value is 2 characters.
In this way, the preceding command can be changed:
Tar CJF-logs/| split-B 1 m-D-A 1-logs.tar.bz2.