文件的归档

  tar命令的使用

tar 文件是把几个文件和(或)目录集合在一个文件夹里。是创建备份和归档的最佳工具

作用:打包、压缩文件

[root@localhost ~]# tar --help

Usage: tar [OPTION...][FILE]...

GNU `tar' saves manyfiles together into a single tape or disk archive, and can

restore individual filesfrom the archive.

 

Examples:

  tar -cf archive.tar foo bar  # Create archive.tar from files foo and bar.  创建存档

  tar -tvf archive.tar         # List all files in archive.tarverbosely.列出所有文件

  tar -xf archive.tar          # Extract all files from archive.tar.从archive.tar提取所有文件。

 

打包:

tar 选项 包的名称  目标文件/目录

[root@localhost ~]# tarcvf grub2.tar /boot/grub2/

# c  create 创建

#v  详细

#f  filename

 

file命令

作用:确定文件类型

语法:file  文件名

 

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

用file命令查看文件的类型。

 

[root@localhost ~]# filea.txt

a.txt: POSIX tar archive(GNU)

[root@localhost ~]# file/etc/passwd

/etc/passwd: ASCII text

 

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

[root@localhost ~]# tarcvf aa.tar /boot/  /etc/passwd

 

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

[root@localhost ~]# tartvf grub2.tar

 

操作-解包:

[root@localhost ~]# tarxvf grub2.tar

 

操作-解压指定路径:

[root@localhost ~]# tarxvf grub2.tar -C /opt/

 

操作-对比文件的大小:

[root@localhost ~]# du-sh /boot/grub2/

8.1M    /boot/grub2/

[root@localhost ~]# ll -hgrub2.tar

-rw-r--r-- 1 root root7.7M Feb 17 07:40 grub2.tar

 

 tar  归档 + 压缩

 

gzip bzip2  zip tar

压缩格式:gz, bz2, xz, zip, Z

 

格式(文件名格式): .tar.gz   或  .tgz

 

语法格式:tar  zcvf  newfile.tar.gz   SOURCE

压缩:

[root@localhost ~]# tarzcvf grub2.tar.gz /boot/grub2/

 

 对比大小

[root@localhost ~]# ll -hgrub2.tar*

-rw-r--r-- 1 root root7.7M Feb 17 07:40 grub2.tar

l   -rw-r--r-- 1 root root 3.1M Feb 17 07:56 grub2.tar.gz

 

 解压

[root@localhost ~]# tarzxvf grub2.tar.gz -C /opt/

 

归档+压缩 :bz2

格式(文件名格式): .tar.bz2

语法格式:tar  jcvf  newfile.tar.gz   SOURCE

压缩:

[root@localhost ~]# tar jcvf grub2.tar.bz2/boot/grub2/

 

对比大小

[root@localhost ~]# ll -hgrub2.tar*

-rw-r--r-- 1 root root7.7M Feb 17 07:40 grub2.tar

-rw-r--r-- 1 root root 2.5M Feb 17 08:02 grub2.tar.bz2

-rw-r--r-- 1 root root 3.1M Feb 17 07:56 grub2.tar.gz

 

解压:

[root@localhost ~]# tar jxvf grub2.tar.bz2-C /opt/

 

zip软件包解压缩命令

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

压缩文件

[root@localhost ~]# zippasswd.zip /etc/passwd

 -r  压缩目录

格式”zip 选项 名称 源”

[root@localhost ~]# zip-r grub2.zip /boot/grub2/

[root@localhost ~]# ll -hgrub2.*

-rw-r--r-- 1 root root7.7M Feb 17 07:40 grub2.tar

-rw-r--r-- 1 root root2.5M Feb 17 08:02 grub2.tar.bz2

-rw-r--r-- 1 root root3.1M Feb 17 07:56 grub2.tar.gz

-rw-r--r-- 1 root root 3.2M Feb 17 08:11 grub2.zip

 

 解压

[root@localhost ~]# unzipgrub2.zip -d /opt/ 

-d指定路径

 

任务:Linux系统能不能解压rar格式的压缩包?能的话,如何解压? 

补充:

压缩命令:gzip  bzip2 xz

语法格式:

gzip   文件

bzip2  文件

xz     文件

 

解压:

gzip  -d   文件

bzip2 -d   文件

xz  -d   文件   或   unxz  文件

 

不解压的情况查看压缩文件内容分别用zcat   和   bzcat 、xzcat

 

特点:只能对文件进行压缩,且压缩后源文件消失(其中xz命令可以加上-k参数保留源文件)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值