shell script (6) B plan

1, with a tar archive

Description
tar can save multiple files and folders into a single file, while preserving all file attributes, such as owner, permissions, and so on. All of the Unix operating system by default will contain tar command
basic usage of
tar -cf output.tar [SOURCES] // - c (create) a file created on behalf of
EG: tar -cf output.tar file1 file2 file3 folder1 ......
-t: Column the files in the archive contains
tar -tf archive.tar
file1
file2
-v / -vv: verbose mode (verbose), for most commands, this pattern will break kinds of output in more detail in
tar -tvf archive .tar
file name must immediately follow the -f, and the -f option should be the last. -f (specify filename) specified file
additional knowledge
1, add files to the archive
tar -rf original.tar new_file
2, extracted from the archive file or folder
tar -xf archive.tar -C my_directory // x ( exact ) extract, -C extracted directory designated
3, two splice archive
tar -Af file1.tar file2.tar // mac a terminal without this parameter
4, to update the contents of the document by time stamp
tar -uf archive.tar filea // if the same name in the archive file already exists, it will add two files with the same name, we can use the -u parameter indicates: is added only when newer than the archive file
5, from the archive files deleted files
tar --delete archive.tar -f file1 file2 ......
tar --delete --file archive.tar [the LIST fILE]
6, compressed tar archive
tar command can only be used to archive files, do not have compression. For this reason, most users will use some form of archive compression when an archive, so you can significantly reduce file size.
tar -acvf archive.tar.gz filea fileb filec // use -a --auto-compress or tar will compression processing parameters (mac terminal without -a parameter) The automatic extension.
7, in part excluded from the archive file
tar -cf archive.tar * --exclude "* txt " // exclude all txt file, the style should use double quotes, avoid using shell be extended
tar -cf archive. tar * -X list // may need to exclude a list of files in the file list in conjunction with -X parameters to achieve exclude archive files
8, the total number of bytes in the print archive
tar -cf archive.tar * --exclude "* txt " --totoals

2, data compression using gzip

Description
gzip can compress a single file or data stream, and can not be archived on the directories and multiple files. So we need to create a tar archive file, and then use gzip compression.
Basic usage
1, archive
the gzip filename
2, unzip the file
gunzip filename.gz
. 3, the compressed file attribute information listed in
the gzip -l text.txt.gz
. 4, the specified compression level
the gzip filename --fast
the gzip filename or --best
added the contents of
a compressed archive
gzip archive.tar
2, no need to unpack, read directly gzip format file
zcat test.gz
3, the compression ratio
gzip -5 test.img // a total of 9 file compression rate, compression rate is the lowest level of 1 but the fastest compression; compression ratio 9 the highest, but slowest compression
4, with bzip2
use gzip bzip2 generally associated with use, but has a higher compression ratio than gzip.
bzip2 filename // compression
bunzip2 filename.bz2 // decompress
5, using LZMA
LZMA there than gzip, bzip2 higher compression ratio, but the compression is slower
lzma filename // compression
unlzma filename // decompression

3, using the zip archive and compression

Description
In the Linux system, not as good as his application gzip and bzip2 so widely used, but the files on the Internet often use this format, mac system is to use this compressed file format. Although most of us have been through the same archiving, compression tool is similar, but does not delete the source zip file after the completion of the archive, which is the luma, gzip, bzip2 different. The most important thing is, although the imagination and tar, zip archive can be both, can also be compressed, tar and alone, you can not compress operation.
Basic usage
1, using zip archive file compression
zip archive_name.zip [the SOURCE the FILES / the DIRS]
zip file.zip File
2, directories and files recursively operate
zip -R & lt Archive.zip Folder1 folder2
. 3, extracted from the zip file content
unzip file.zip
supplement
1, update the contents of the zip file update
ZIP file.zip -u newfile
2, delete the contents from the compressed file in
ZIP file.zip file.txt -d
3, list the contents of compressed files
unzip -l archive.zip

4, faster archiving tool pbzip2

pbzip2 can use multiple threads to archive, so the speed will be faster

5, using rsync backup system snapshot

Previously used cp command synchronizes the local and remote computers files
rsync command can also do this thing
rsync command to connect to a remote host using SSH, so you must use this form to set user @ host address of the remote host, where user represents the user name, host represents the remote host's IP address or host name. The path on the PATH need to copy data from a remote host.

The contents of a directory to another directory synchronization
rsync -av / home / test / / home / backups // test directory to copy the contents (not including the test directory) to the directory backups
rsync -av / home / test / home / backups // the test directory contents (including test directory) to the directory backups
rsync -av / home / test / home / backups / // will test directory contents (not including the test directory) to the directory backups
rsync -av / home / test / home / backups // the test directory contents (including test directory) copied to the backups directory in
the directory with / at the end, just copy the contents of the directory; no / end, copy the contents of the directory tree itself

Spread

cronttab: open regular tasks

Reproduced in: https: //www.jianshu.com/p/960eb4c52f0d

Guess you like

Origin blog.csdn.net/weixin_34075268/article/details/91186384