Home | Mirror | Search | ITEYE 博客 | OSChina 博客 | 51CTO 博客 |
目錄
tar
tar -cvf foo.tar foo/ tar contents of folder foo in foo.tar tar -xvf foo.tar extract foo.tar
tar -zcvf foo.tar foo/ tar contents of folder foo in foo.tar.gz
tar -xvzf foo.tar.gz extract gzipped foo.tar.gz
tar -jcvf foo.tar.bz2 foo/ tar contents of folder foo in foo.tar.bz2 tar -jxvf foo.tar.bz2 extract b2zip foo.tar.bz2
tar -Zcvf foo.tar.Z foo/ tar contents of folder foo in foo.tar.Z tar -Zxvf foo.tar.Z extract compress foo.tar.Z
-t, --list list the contents of an archive
列出tar包中的檔案
tar tvf neo.tar.gz
# mkdir -p /www/test.com/www.test.com/ # echo helloworld > /www/test.com/www.test.com/test.txt # tar zcvf www.test.com.tar.gz /www/test.com/www.test.com/ # tar ztvf www.test.com.tar.gz drwxr-xr-x root/root 0 2013-08-08 15:24 www/test.com/www.test.com/ -rw-r--r-- root/root 11 2013-08-08 15:24 www/test.com/www.test.com/test.txt # tar zxvf www.test.com.tar.gz www/test.com/www.test.com/ www/test.com/www.test.com/test.txt # find www www www/test.com www/test.com/www.test.com www/test.com/www.test.com/test.txt
-P, --absolute-names don't strip leading `/'s from file names
$ tar -czvPf neo.tar.gz /home/neo/ $ tar -xzvPf neo.tar.gz
-C, --directory=DIR change to directory DIR
解壓到目標目錄
tar -xzvf neo.tar.gz -C /tmp
# tar zxvf www.test.com.tar.gz -C /tmp www/test.com/www.test.com/ www/test.com/www.test.com/test.txt # find /tmp/www/ /tmp/www/ /tmp/www/test.com /tmp/www/test.com/www.test.com /tmp/www/test.com/www.test.com/test.txt # rm -rf /www/test.com/* # tar zxvf www.test.com.tar.gz -C / www/test.com/www.test.com/ www/test.com/www.test.com/test.txt # find /www/test.com/ /www/test.com/ /www/test.com/www.test.com /www/test.com/www.test.com/test.txt
tar zcvfP www.test.com.tar.gz /www/test.com/www.test.com/ tar zxvfP www.test.com.tar.gz
排除neo目錄
tar --exclude /home/neo -zcvf myfile.tar.gz /home/* /etc tar zcvf rpmbuild/SOURCES/netkiller-1.0.tar.gz ~/workspace/public_html/* --exclude .git --exclude .svn
find . -name "*.jpg" -print >list tar -T list -czvf picture.tar.gz find /etc/ | tar czvf xxx1.tar.gz -T -
tar -jcpvf - file.php | ssh root@172.16.3.1 "tar -jxpvf -"