First, basic usage
Parameters:
-C: Create a compressed file
-x: Unlock a compressed file
-T: View the files in the compressed package
Second, compression
Scene:
# Tree/var/www/var/www├──blog│├──index.php│├──update││└──a.txt│└──websource│└──blog.html├──c ms│├──index.php│├──update││└──b.txt│└──websource│└──home.html├──license.txt└──log└──2015 0429.log
1. Package directory blog, where there will be/var/www/* directory prefix in compressed file test1.tar.gz
# tar-zcvf/var/www/test1.tar.gz/var/www/blogtar:removing Leading '/' from member names/var/www/blog//var/www/blog/ index.php/var/www/blog/update//var/www/blog/update/a.txt/var/www/blog/websource//var/www/blog/websource/ Blog.html
2. Remove the directory prefix
① into the blog directory, where the compressed file test2.tar.gz even the blog directory is also removed
# cd/var/www/blog# tar-zcvf/var/www/test2.tar.gz./././index.php./update/./update/a.txt./websource/./websource/ Blog.html
② into the upper directory of the blog directory/var/www
# cd/var/www# tar-zcvf/var/www/test3.tar.gz blogblog/blog/index.phpblog/update/blog/update/a.txtblog/websource/ Blog/websource/blog.html
Note: If you want to package both the blog directory and the CMS directory
# tar-zcvf/var/www/test4.tar.gz Blog cmsblog/blog/index.phpblog/update/blog/update/a.txtblog/websource/blog/ Websource/blog.htmlcms/cms/index.phpcms/update/cms/update/b.txtcms/websource/cms/websource/home.html
③ If you do not want to CD to the equivalent directory, add-c parameter,-C is a temporary switch working directory
# pwd/# Tar-zcvf/var/www/test5.tar.gz-c/var/www blogblog/blog/index.phpblog/update/blog/update/a.txtblog/ Websource/blog/websource/blog.html
# tar-zcvf/var/www/test6.tar.gz-c/var/www/blog./././index.php./update/./update/a.txt./websource/./websource/ Blog.html
3. Exclude certain directories or files when compressing a directory
TAR-ZCVF **.tar.gz--exclude=xx yy Note XX and yy is either a relative path at the same time, or it is an absolute path, otherwise it cannot exclude directories or files
E.g compress all files except CMS outside/var/www directory
① relative path
# cd/var# tar-zcvf/var/www/test7.tar.gz--exclude=www/cms www
② Absolute Path
# pwd/# tar-zcvf/var/www/test8.tar.gz--exclude=/var/www/cms/var/www
Note:/var/www/cms cannot be followed by A/
Third, decompression
From the second part of the compression experiment can be seen, command tar [OPTION ...] [FILE] ... where [FILE] defaults to the current directory
Extract to current directory
# pwd/# Tar-zxvf/var/www/test5.tar.gz
2. Unzip to the specified directory
# pwd/# Tar-zxvf/var/www/test5.tar.gz-c/Home
3. Unzip the specified directory or file in the compressed file
# Tar-zxvf/var/www/test4.tar.gz-c/Home blog# tar-zxvf/var/www/test4.tar.gz-c/Home blog/index.php
This article is from the "Freedom Trail" blog, be sure to keep this source http://wangy8961.blog.51cto.com/10174968/1640355
A slight gain--tar command