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
b2zip
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
compress/uncompress
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
tar zcvfP www.test.com.tar.gz /www/test.com/www.test.com/ tar zxvfP www.test.com.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
排除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 -
追加最近7天更改过的文件
find / -type f -mtime -7 | xargs tar -rf weekly_incremental.tar
tar -jcpvf - file | ssh remote "tar -jxpvf -"
tar -jcpvf - file.php | ssh root@172.16.3.1 "tar -jxpvf -"
find /opt -print | cpio -o > opt.cpio find . -type f -name '*.sh' -print | cpio -o | gzip >sh.cpio.gz cpio –i < opt.cpio
gzip/gunzip
# ls access.2010-{10,11}-??.log access.2010-10-01.log access.2010-10-17.log access.2010-11-02.log access.2010-11-18.log access.2010-10-02.log access.2010-10-18.log access.2010-11-03.log access.2010-11-19.log access.2010-10-03.log access.2010-10-19.log access.2010-11-04.log access.2010-11-20.log access.2010-10-04.log access.2010-10-20.log access.2010-11-05.log access.2010-11-21.log access.2010-10-05.log access.2010-10-21.log access.2010-11-06.log access.2010-11-22.log access.2010-10-06.log access.2010-10-22.log access.2010-11-07.log access.2010-11-23.log access.2010-10-07.log access.2010-10-23.log access.2010-11-08.log access.2010-11-24.log access.2010-10-08.log access.2010-10-24.log access.2010-11-09.log access.2010-11-25.log access.2010-10-09.log access.2010-10-25.log access.2010-11-10.log access.2010-11-26.log access.2010-10-10.log access.2010-10-26.log access.2010-11-11.log access.2010-11-27.log access.2010-10-11.log access.2010-10-27.log access.2010-11-12.log access.2010-11-28.log access.2010-10-12.log access.2010-10-28.log access.2010-11-13.log access.2010-11-29.log access.2010-10-13.log access.2010-10-29.log access.2010-11-14.log access.2010-11-30.log access.2010-10-14.log access.2010-10-30.log access.2010-11-15.log access.2010-10-15.log access.2010-10-31.log access.2010-11-16.log access.2010-10-16.log access.2010-11-01.log access.2010-11-17.log # gzip access.2010-{10,11}-??.log
# ls access.2010-{0?,10,11}-??.log access.2010-08-28.log access.2010-10-02.log access.2010-10-13.log access.2010-10-27.log access.2010-11-06.log access.2010-11-17.log access.2010-11-26.log access.2010-08-31.log access.2010-10-03.log access.2010-10-14.log access.2010-10-28.log access.2010-11-08.log access.2010-11-18.log access.2010-11-27.log access.2010-09-24.log access.2010-10-04.log access.2010-10-15.log access.2010-10-29.log access.2010-11-09.log access.2010-11-19.log access.2010-11-28.log access.2010-09-25.log access.2010-10-06.log access.2010-10-17.log access.2010-10-30.log access.2010-11-10.log access.2010-11-20.log access.2010-11-29.log access.2010-09-26.log access.2010-10-07.log access.2010-10-19.log access.2010-10-31.log access.2010-11-11.log access.2010-11-21.log access.2010-11-30.log access.2010-09-27.log access.2010-10-08.log access.2010-10-20.log access.2010-11-02.log access.2010-11-12.log access.2010-11-22.log access.2010-09-29.log access.2010-10-09.log access.2010-10-22.log access.2010-11-03.log access.2010-11-14.log access.2010-11-23.log access.2010-09-30.log access.2010-10-10.log access.2010-10-23.log access.2010-11-04.log access.2010-11-15.log access.2010-11-24.log access.2010-10-01.log access.2010-10-12.log access.2010-10-25.log access.2010-11-05.log access.2010-11-16.log access.2010-11-25.log # gzip access.2010-{0?,10,11}-??.log &
*.zip
zip/unzip file[.zip]http://www.7-zip.org/
如果你仅仅是解压文件,只需安装下面的包即可
$ sudo apt-get install p7zip
如果你要创建7zip文件就需要安装p7zip-full
$ sudo apt-get install p7zip-full
$ unrar test.rar
原文出处:Netkiller 系列 手札
本文作者:陈景峯
转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。