tar命令的使用

tar命令ide

做用:打包,压缩文件spa

[root@localhost test]# tar --helpip

打包:it

例如:class

[root@localhost test]# tar  -cvf grub.tar /boot/grub   #c 建立  v 详细   f filename
[root@localhost test]# file grub.tar
grub.tar: POSIX tar archive (GNU)
test

file命令:肯定文件类型打包

语法:file /etc/passwd软件

注意:Linux系统不根据后缀名识别文件类型file

用file命令查看文件的类型语法


例如:把两个目录或目标+文件打包成一个软件包

[root@localhost test]# tar -cvf ss.tar /boot/ /etc/passwd


不解包,查看tar中的内容:

例如:

[root@localhost test]# tar -tvf ss.tar


作对比:[root@localhost test]# tar -tf ss.tar


解包:

[root@localhost test]# tar -xvf ss.tar 


指定解压路径:

#tar -xf newfile.tar -C

例如:

[root@localhost test]# tar xvf ss.tar -C /opt/


对比大小;

[root@localhost test]# du -sh /boot/
24M     /boot/

[root@localhost test]# ll -h boot.tar
-rw-r--r--. 1 root root 24M Dec 21 12:40 boot.tar


tar归档+压缩:

格式:(后缀名): .tar.gz  或  .tgz

语法:tar czvf newfile.tar.gz SOURCE


解压:#tar zxvf newfile.tar.gz -C /path/to/distdir/


归档+压缩:   bz2

[root@localhost boot]# tar cjvf grub.tar.gz /boot/grub/


解压:#tar jxvf newfile.tar.gz  -C /path/to/distdir/


例如:

[root@localhost boot]# tar -jxvf grub.tar.bz2 /boot/grub/

[root@localhost boot]# ll -h grub.tar*


zip软件包解压命令:

zip是压缩程序,unzip是解压程序


压缩文件:

[root@localhost boot]# zip a.zip /etc/passwd

#zip all.zip *.jpg  #这条命令是将全部.jpg的文件压缩成一个zip包


压缩一个目录:

[root@localhost boot]# zip -r grup.zip /boot/grub


解压缩:

[root@localhost boot]# unzip  grup.zip  -d /opt

相关文章
相关标签/搜索