Linux中tar命令使用详解
|
4.还是刚才那个tmp.tar.bz2包 我只想把其中的 "tmp/man.config.bz2" 解压到当前目录,怎么做? [root@localhost ~]# ll total 56 -rw-------. 1 root root 1350 Jul 8 22:03 anaconda-ks.cfg -rw-r--r--. 1 root root 24606 Jul 8 22:03 install.log -rw-r--r--. 1 root root 7345 Jul 8 22:01 install.log.syslog -rw-r--r--. 1 root root 9947 Aug 17 18:10 tmp.tar.bz2 [root@localhost ~]# tar -xjvf tmp.tar.bz2 tmp/man.config.bz2 tmp/man.config.bz2 [root@localhost ~]# ll ./tmp total 4 -rw-r--r--. 1 root root 2195 Aug 17 12:37 man.config.bz2 可以看到只有 man.config.bz2 被解压出来了 5.打包时不包含某些文件的做法 [root@localhost ~]# ll /tmp total 24 -rw-r--r--. 1 root root 4940 Aug 17 12:37 man.config -rw-r--r--. 1 root root 2332 Aug 17 13:14 man.config1.gz -rw-r--r--. 1 root root 2184 Aug 17 13:15 man.config9.gz -rw-r--r--. 1 root root 2195 Aug 17 12:37 man.config.bz2 drwxr-xr-x. 3 root root 4096 Aug 17 18:47 tar -rw-r--r--. 1 root root 0 Aug 17 19:13 tartest.out 本例中 不想包含 tar 这个文件夹, 可以这么做 [root@localhost ~]# tar -cjvf tmp.tar.bz2 --exclude=/tmp/tar /tmp tar: Removing leading `/' from member names /tmp/ /tmp/man.config1.gz /tmp/man.config /tmp/tartest.out /tmp/.ICE-unix/ /tmp/man.config9.gz /tmp/man.config.bz2 [root@localhost ~]# tar -tjvf tmp.tar.bz2 |grep "/$" drwxrwxrwt root/root 0 2013-08-17 19:13 tmp/ drwxrwxrwt root/root 0 2013-08-17 12:36 tmp/.ICE-unix/ 可以看到打包后的文件中确实没有 tar 这个目录 查看本栏目更多精彩内容:http://www.bianceng.cn/OS/Linux/ 6.这次我们要将 /tmp 目录下 8月17日 18:00 以后生成的文件打包,可以这样做 [root@localhost ~]# ll /tmp total 24 -rw-r--r--. 1 root root 4940 Aug 17 12:37 man.config -rw-r--r--. 1 root root 2332 Aug 17 13:14 man.config1.gz -rw-r--r--. 1 root root 2184 Aug 17 13:15 man.config9.gz -rw-r--r--. 1 root root 2195 Aug 17 12:37 man.config.bz2 drwxr-xr-x. 3 root root 4096 Aug 17 18:47 tar -rw-r--r--. 1 root root 0 Aug 17 19:13 tartest.out [root@localhost ~]# tar -cjvf tmp.tar.bz2 --newer-mtime="2013-08-17 18:00:00" /tmp tar: Removing leading `/' from member names /tmp/ tar: /tmp/man.config1.gz: file is unchanged; not dumped tar: /tmp/man.config: file is unchanged; not dumped /tmp/tartest.out /tmp/.ICE-unix/ tar: /tmp/man.config9.gz: file is unchanged; not dumped /tmp/tar/ /tmp/tar/tmp/ tar: /tmp/tar/tmp/man.config1.gz: file is unchanged; not dumped tar: /tmp/tar/tmp/man.config: file is unchanged; not dumped /tmp/tar/tmp/.ICE-unix/ tar: /tmp/tar/tmp/man.config9.gz: file is unchanged; not dumped tar: /tmp/tar/tmp/man.config.bz2: file is unchanged; not dumped tar: /tmp/man.config.bz2: file is unchanged; not dumped [root@localhost ~]# tar -tjvf tmp.tar.bz2 drwxrwxrwt root/root 0 2013-08-17 19:42 tmp/ -rw-r--r-- root/root 0 2013-08-17 19:13 tmp/tartest.out drwxrwxrwt root/root 0 2013-08-17 12:36 tmp/.ICE-unix/ drwxr-xr-x root/root 0 2013-08-17 18:47 tmp/tar/ drwxrwxrwt root/root 0 2013-08-17 14:16 tmp/tar/tmp/ drwxrwxrwt root/root 0 2013-08-17 12:36 tmp/tar/tmp/.ICE-unix/ 这个功能在备份时比较有用,可以做差异备份,如果用tar来做系统备份的话,为了保证备份资料保持原来的权限与属性,可以加入 -p 参数 (编辑:佛山站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |

