Big data learning monk 2022-02-13 07:18:24 阅读数:490
Package large files or directories 、 Compress and split into files of specified size , stay Linux Can be used in combination tar,bzip2( perhaps gzip),split Command to implement .
Command grid test tar zcvf - [ file_directory ] |sqlit -b [ file_size ][ m,k ] - [ file.tar.gz ]
take file The files in the directory are compressed and divided into each size of 4G file
shell > tar zcvf - file_name |split -b 4096m - file_name.tar.gz
shell > ls
-rw-r--r-- 1 root root 4294967296 Mar 9 10:40 file_name.tar.gzaa
-rw-r--r-- 1 root root 4294967296 Mar 9 10:48 file_name.tar.gzab
-rw-r--r-- 1 root root 2282762240 Mar 9 10:52 file_name.tar.gzac
cat file_name.tar.gza* |tar zxv
explain :
use cat To read all the compressed packets , utilize tar To decompress
1、 Ordinary tar Compress command
tar -zcvf cm-11.tar.gz cm-11
// take cm-11 Folder compressed into cm-11.tar.gz
2、 The compressed file is too large , Need to put cm-11.tar.gz Divided into N A file of specified size , What do I do ? One command is done
split -b 4000M -d -a 1 cm-11.tar.gz cm-11.tar.gz.
// Use split command ,-b 4000M Indicates setting the size of each split package , The unit can still k
// -d " Parameter specifies that the generated split package suffix is in the form of a number
//-a x To set the length of the sequence ( The default value is 2), Here, set the length of the sequence to 1
After executing the command , The generated compressed package is as follows :
-rw-r--r-- 1 root root 4194304000 May 20 14:00 cm-11.tar.gz.0
-rw-r--r-- 1 root root 4194304000 May 20 14:02 cm-11.tar.gz.1
-rw-r--r-- 1 root root 4194304000 May 20 14:03 cm-11.tar.gz.2
-rw-r--r-- 1 root root 4194304000 May 20 14:05 cm-11.tar.gz.3
-rw-r--r-- 1 root root 4194304000 May 20 14:06 cm-11.tar.gz.4
-rw-r--r-- 1 root root 4194304000 May 20 14:08 cm-11.tar.gz.5
-rw-r--r-- 1 root root 4194304000 May 20 14:09 cm-11.tar.gz.6
-rw-r--r-- 1 root root 2256379886 May 20 14:10 cm-11.tar.gz.7
3、 In fact, the above two steps can also be combined into one step
tar -zcvf cm-11.tar.gz cm-11 | split -b 4000M -d -a 1 - cm-11.tar.gz.
// Pipeline , among - Parameter indicates that the created file is output to standard output
4、 Ordinary decompression command
tar -zxvf cm-11.tar.gz
5、 The decompression command of the split compressed package is as follows
cat cm-11.tar.gz.* | tar -zxv
6、 Enclosed tar Parameter interpretation of the command
tar Can be used to compress packing list files 、 Multiple files 、 Single directory 、 Multiple directories .
Linux Packing command tar
tar The command can be used to compress a single file 、 Multiple files 、 Single directory 、 Multiple directories .
Common formats :
Single file compression package
tar -czvf my.tar.gz file1
Multiple files are compressed and packaged
tar -czvf my.tar.gz file1 file2,...(file*)( You can also give file* file mv The directory is being compressed )
Single directory compression packaging
tar -czvf my.tar.gz dir1
Multiple directories are compressed and packaged
tar -czvf my.tar.gz dir1 dir2
Unpack to current directory :
tar -xzvf my.tar.gz
cpio
With subdirectories find x* | cpio -o > /y/z.cpio
No subdirectories ls x* | cpio -o > /y/z.cpio
Unpack : cpio -i < /y/z.cpio
[[email protected] ~]# tar [-cxtzjvfpPN] Files and directories …
Parameters :
-c : Create a parameter instruction for the compressed file (create It means );
-x : Unpack the parameter instruction of a compressed file !
-t : see tarfile The documents inside !
Particular attention , In the release of parameters , c/x/t There can only be one ! Can't exist at the same time !
Because it's impossible to compress and decompress at the same time .
-z : Whether it has at the same time gzip Properties of ? That is, whether it is necessary to use gzip Compress ?
-j : Whether it has at the same time bzip2 Properties of ? That is, whether it is necessary to use bzip2 Compress ?
-v : Display files during compression ! This is often used , But it's not recommended for background execution !
-f : Use file name , Please pay attention. , stay f After that, we need to pick up the file name immediately ! No more parameters !
For example, using 『 tar -zcvfP tfile sfile』 It's the wrong way to write , To write
『 tar -zcvPf tfile sfile』 That's right !
-p : Use the original properties of the original file ( Properties don't change depending on the user )
-P : You can use absolute paths to compress !
-N : Than the date that follows (yyyy/mm/dd) New ones are needed to be packaged into new files !
–exclude FILE: During compression , Don't put FILE pack !
copyright:author[Big data learning monk],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/02/202202130718214266.html