打包压缩
tar -zcvf /tmp/bin-backup.tar.gz /home/vivek/bin/
tar -jcvf filename.tar.bz2 /home/vivek/bin/
打包排除文件
打包时排除不备份的文件 排除3.txt这个文件
[root@localhost 1]# ls
1.txt 2.txt 3.txt
[root@localhost ~]# tar --exclude /root/1/3.txt -zcvf ha.tar.gz /root/1
tar: 从成员名中删除开头的“/”
/root/1/
/root/1/1.txt
/root/1/2.txt
[root@localhost ~]# tar -tvf ha.tar.gz
drwxr-xr-x root/root 0 2023-11-27 21:04 root/1/
-rw-r--r-- root/root 0 2023-11-27 21:04 root/1/1.txt
-rw-r--r-- root/root 0 2023-11-27 21:04 root/1/2.txt
只打包不压缩
tar -cvf archive.tar /home/cyberpunk/testdir/
-c 建立新的备份文件
-v 显示指令执行过程
-f 指定归档文件的文件名
解压
#解压到当前路径
tar -zxvf bin-backup.tar.gz
#解压到指定目录
tar -jxv -f filename.tar.bz2 -C /home
#解压gz格式部分文件出来
tar -zxvf /opt/soft/test/log30.tar.gz log2013.log
查看压缩包的内容
tar -tvf archive.tar
tar -jtv -f filename.tar.bz2
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容