tar命令--文件打包和解包
tar语法参数
tar <operation> <options>
参数 | 单词 | 说明 |
-z | zip | 使用zip进行压缩或解压 |
-j | bzip | 使用bzip进行压缩或解压(效率高) |
-c | create | 创建一个打包文件 |
-x | extract | 打开一个打包文件 |
-v | Verbose | 显示打包或解包过程 |
-f | file | 指定文件(任何打包解包都需要) |
-C | directory DIR | 指定解压目录 |
-p | permissions | 保持文件的所有属性 |
-P | absolute-names | 保留绝对路径开头的"/" |
-X | --exclude | 排除不处理的文件 |
示例: [root@localhost tmp]# tar zcvf /tmp/etc_back.tar.gz /etc/ [root@localhost tmp]# tar jcvf /tmp/etc_back.tar.bz /etc/ [root@localhost tmp]# ll 总用量 13264 -rw-r--r--. 1 root root 6377935 11月 13 13:36 etc_back.tar.bz -rw-r--r--. 1 root root 7199812 11月 13 13:36 etc_back.tar.gz 解压: [root@localhost tmp]# tar zxvfP etc_back.tar.gz -C /tmp [root@localhost tmp]# tar jxvfP etc_back.tar.gz -C /tmp [root@localhost tmp]# ll 总用量 13268 drwxr-xr-x. 74 root root 4096 11月 13 11:26 etc 排除不解压的目录: [root@localhost tmp]# tar zxvfP etc_back.tar.gz -C /tmp --exclude=/etc/services 案例:打包网站程序,排除里面所有.doc结尾文件 [root@localhost tmp]# tar zcvfP web.tar.gz -C /tmp --exclude=\.*doc 注意:打包时若要添加时间,不能使用%T 要使用:(date +%H-%M%S) [root@localhost tmp]# tar zxvfP web$(date +%H-%M%S).tar.gz -C /tmp --exclude=/etc/services
转载于:https://blog.51cto.com/liangey/1576030