1.linux下常见的压缩包类型有哪些
zip
gz 会删除源文件
bz2 会删除源文件
tar.gz
tar.bz2
2.将/etc/hosts文件用tar格式打包。
[root@liujun ~]# cd /
[root@liujun /]# tar czf hosts.tar.gz etc/hosts
3.使用tar打包/var/log/目录。
[root@liujun /]# tar czf log.tar.gz var/log
4.使用zip打包/etc目录。
[root@liujun /]# zip -r etc.zip etc/
5.查看/var/log/目录的压缩包中有哪些内容。
[root@liujun /]# tar tf log.tar.gz
6.将/var/log/目录解压到/opt目录中。
[root@centos7 /]# tar xf log.tar.gz -C /opt
7.查看/etc/目录的压缩包的压缩比率。
[root@liujun /]# du -sh /etc/
32M /etc/
[root@liujun /]# du -sh /etc.zip
12M /etc.zip
[root@liujun /]# awk 'BEGIN{print 14/32*100"%"}'
43.75%
8.查看/etc/目录的压缩包的内容是否完好
[root@liujun /]# zip -T etc.zip
[root@liujun /]# unzip -t etc.zip
9.解压/etc/目录到/opt目录中。
[root@liujun /]# unzip etc.zip -d /opt/
10.用zip打包/opt目录,要求不显示打包过程。
[root@liujun /]# zip -qr opt.zip /opt
11.打包/etc/目录,要求是.bz2格式
[root@liujun /]#tar cjf etc.tar.bz2 /etc/
12.打包/var/log目录,要求是.xz格式
[root@liujun /]#tar cJf log.tar.xz /var/log/
13.使用tar命令打包/etc/时,会出现一个删根的操作,怎样打包不会进行删根的操作
[root@liujun /]#tar czPf etc.tar.gz /etc
14.打包/etc/目录,要求不打包/etc/hosts这个文件。
[root@liujun /]# tar czf etc.tar.gz --exclude=etc/hosts etc/
15.打包/etc/目录,要求不打包/etc/hosts和/etc/hostname这两个文件。
[root@liujun /]#tar czf etc.tar.gz --exclude=etc/hosts,etc/hostname etc/
16.已知文件oldboy.zip,请问在不解压的情况下,怎样查看该文件的内容。
[root@liujun /]#unzip -l oldboy.zip
17.打包/etc/目录,命令以ip地址+当前时间方式的压缩包: 比如: 10.0.0.98_2019-4-23_etc.tar [root@centos7 ~]# tar zcf 2}')_$(date +%F)_etc.tar.gz /etc
date +%F (年月日) date +%T (十分秒)
[root@centos7 ~]# date +%T
19:38:50
[root@centos7 ~]# date -d '-1day' (显示的结果会减1天,以后备份日志有用)
Mon Jul 8 19:42:07 CST 2019












网友评论