4.linux
任务1:
1、练习使用mv命令
touch a123.txt
ll
mv a123.txt a111.txt
ll
mkdir aaa
ll
mv aaa ccc
ll
2、tar #该命令用于压缩和解压缩
#接下来,对/etc目录进行打包
[root@zhangsan101 ~]# du -sh /etc
[root@zhangsan102 ~]# tar -zcvf myetc2.tar.gz /etc #调用gzip对/etc目录打包
[root@zhangsan101 ~]# ll -h etc* #查看打包后压缩包大小
-rw-r--r-- 1 root root 4.4M 2月 6 22:56 etc.tar.bz
-rw-r--r-- 1 root root 6.0M 2月 6 22:58 etc.tar.gz #由32M变成了9.9M,gzip的压缩比不高
[root@zhangsan101 ~]# tar -jcvf etc.tar.bz /etc #调用bz2压缩工具对/etc目录进行压缩
[root@zhangsan101 ~]# ll -h etc.tar.bz
-rw-r--r-- 1 root root 4.4M 2月 6 22:56 etc.tar.bz
[root@zhangsan101 ~]# tar -Jcvf etc.tar.xz /etc #调用xz压缩工具对/etc目录进行压缩
[root@zhangsan101 ~]# ll -h etc*
-rw-r--r-- 1 root root 4.4M 2月 6 22:56 etc.tar.bz
-rw-r--r-- 1 root root 6.0M 2月 6 22:58 etc.tar.gz
-rw-r--r-- 1 root root 3.7M 2月 6 23:00 etc.tar.xz # xz的压缩比最高,但压缩过程最慢
[root@zhangsan102 ~]# tar -ztf myetc2.tar.gz #查看压缩包中包含的内容
[root@zhangsan101 ~]# file etc.tar.bz #查看压缩包是用哪种压缩工具压缩的
etc.tar.bz: bzip2 compressed data, block size = 900k
[root@zhangsan101 ~]# file etc.tar.xz
etc.tar.xz: XZ compressed data
[root@zhangsan101 ~]# file etc.tar.gz
etc.tar.gz: gzip compressed data, last modified: Sat Feb 6 14:58:30 2021, from Unix, original size 27801600
查看压缩包里面的文件内容:
tar -ztf etc1.tar.gz
tar -jtf etc2.tar.bz
tar -Jtf etc3.tar.xz
tar -zxf etc1.tar.gz -C /opt #使用gzip解压缩
tar -jxf etc2.tar.bz -C /opt #使用bzip2解压缩
tar -Jxf etc3.tar.xz -C /opt/ #使用XZ解压缩

浙公网安备 33010602011771号