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

相關文章
相關標籤/搜索