windows下的压缩文件有:.rar .zip .7z
linux下的压缩文件有:.zip ## .gz ## .bz2 ## .xz ## .tar.gz ## .tar.bz2 ## .tar.xz ##
linux下的压缩工具:
gzip:
压缩命令:gzip 【文件名】
-a或–ascii 使用ASCII文字模式。
-c或–stdout或–to-stdout 把压缩后的文件输出到标准输出设备,不去更动原始文件。
-d或–decompress或----uncompress 解开压缩文件。
-f或–force 强行压缩文件。不理会文件名称或硬连接是否存在以及该文件是否为符号连接。
-h或–help 在线帮助。
-l或–list 列出压缩文件的相关信息。
-L或–license 显示版本与版权信息。
-n或–no-name 压缩文件时,不保存原来的文件名称及时间戳记。
-N或–name 压缩文件时,保存原来的文件名称及时间戳记。
-q或–quiet 不显示警告信息。
-r或–recursive 递归处理,将指定目录下的所有文件及子目录一并处理。
-S<压缩字尾字符串>或----suffix<压缩字尾字符串> 更改压缩字尾字符串。
-t或–test 测试压缩文件是否正确无误。
-v或–verbose 显示指令执行过程。
-V或–version 显示版本信息。
-<压缩效率> 压缩效率是一个介于1-9的数值,预设值为"6",指定愈大的数值,压缩效率就会愈高。
–best 此参数的效果和指定"-9"参数相同。
–fast 此参数的效果和指定"-1"参数相同。
实例:
[root@localhost d6z]# find /etc/ -type f -name "*.conf" ##查找/etc/目录下所有的以.conf结尾的文件
/etc/resolv.conf
/etc/libaudit.conf
/etc/security/pwquality.conf
/etc/security/access.conf
/etc/security/chroot.conf
/etc/security/group.conf
/etc/security/limits.conf
/etc/security/limits.d/20-nproc.conf
/etc/security/namespace.conf
/etc/security/pam_env.conf
/etc/security/sepermit.conf
/etc/security/time.conf
/etc/dracut.conf
/etc/depmod.d/dist.conf
/etc/prelink.conf.d/nss-softokn-prelink.conf
/etc/prelink.conf.d/fipscheck.conf
/etc/prelink.conf.d/grub2.conf
/etc/modprobe.d/firewalld-sysctls.conf
/etc/modprobe.d/dccp-blacklist.conf
/etc/modprobe.d/tuned.conf
/etc/rsyslog.d/listen.conf
/etc/systemd/bootchart.conf
/etc/systemd/coredump.conf
/etc/systemd/journald.conf
/etc/systemd/logind.conf
/etc/systemd/system.conf
/etc/systemd/user.conf
/etc/host.conf
/etc/dbus-1/system.d/org.freedesktop.hostname1.conf
/etc/dbus-1/system.d/org.freedesktop.import1.conf
/etc/dbus-1/system.d/org.freedesktop.locale1.conf
/etc/dbus-1/system.d/org.freedesktop.login1.conf
/etc/dbus-1/system.d/org.freedesktop.machine1.conf
/etc/dbus-1/system.d/org.freedesktop.systemd1.conf
/etc/dbus-1/system.d/org.freedesktop.timedate1.conf
/etc/dbus-1/system.d/org.freedesktop.PolicyKit1.conf
/etc/dbus-1/system.d/wpa_supplicant.conf
/etc/dbus-1/system.d/nm-dispatcher.conf
/etc/dbus-1/system.d/nm-ifcfg-rh.conf
/etc/dbus-1/system.d/org.freedesktop.NetworkManager.conf
/etc/dbus-1/system.d/teamd.conf
/etc/dbus-1/system.d/FirewallD.conf
/etc/dbus-1/system.d/com.redhat.tuned.conf
/etc/dbus-1/session.conf
/etc/dbus-1/system.conf
/etc/udev/udev.conf
/etc/lvm/lvm.conf
/etc/lvm/lvmlocal.conf
/etc/NetworkManager/NetworkManager.conf
/etc/X11/xorg.conf.d/00-keyboard.conf
/etc/pki/ca-trust/ca-legacy.conf
/etc/ld.so.conf
/etc/ld.so.conf.d/mariadb-x86_64.conf
/etc/ld.so.conf.d/kernel-3.10.0-957.el7.x86_64.conf
/etc/nsswitch.conf
/etc/sestatus.conf
/etc/yum/protected.d/systemd.conf
/etc/yum/pluginconf.d/fastestmirror.conf
/etc/yum/pluginconf.d/langpacks.conf
/etc/yum/version-groups.conf
/etc/krb5.conf
/etc/sysctl.conf
/etc/sasl2/smtpd.conf
/etc/fuse.conf
/etc/openldap/ldap.conf
/etc/GeoIP.conf
/etc/libuser.conf
/etc/logrotate.conf
/etc/asound.conf
/etc/selinux/semanage.conf
/etc/selinux/targeted/setrans.conf
/etc/wpa_supplicant/wpa_supplicant.conf
/etc/plymouth/plymouthd.conf
/etc/yum.conf
/etc/firewalld/firewalld.conf
/etc/tuned/tuned-main.conf
/etc/vmware-tools/guestproxy-ssl.conf
/etc/vmware-tools/vgauth.conf
/etc/kdump.conf
/etc/audisp/audispd.conf
/etc/audisp/plugins.d/af_unix.conf
/etc/audisp/plugins.d/syslog.conf
/etc/audit/auditd.conf
/etc/rsyslog.conf
/etc/chrony.conf
/etc/man_db.conf
/etc/e2fsck.conf
/etc/mke2fs.conf
/etc/sudo-ldap.conf
/etc/sudo.conf
/etc/vconsole.conf
/etc/locale.conf
[root@localhost d6z]# find /etc/ -type f -name "*.conf" -exec cat {} >>1.txt \; ##将所有的.conf文件的内容追加到1.txt
#############################################################################################
find 是我们很常用的一个Linux命令,但是我们一般查找出来的额并不仅仅是看看而已,还会有进一步的操作,这个时候exec的作用就显现出来了。
exec解释:
-exec 参数后面跟的是 command 命令,它的终止是以“;”为结束标志的,所以这句命令后面的分号是不可缺少的,考虑到各个系统中分号会有不同的意义,所以前面加反斜杠。
{} 花括号代表前面find查找出来的文件名。
使用find时,只要把想要的操作写在一个文件里,就可以用exec来配合find 查找,很方便的。在有些操作系统中,只允许 -exec 选项执行诸如 ls 或 ls -l 这样的命令。大多数用户使用着一些选项是为了查找旧文件并删除它们。建议再真正执行 rm 命令删除文件之前,最好先用 ls 命令看一下,确认他们是所要删除的文件。 exec 选项后面跟随着所要执行的命令或脚本,然后是一对儿{},一个空格和一个\,最后是一个分号。为了使用 exec 选项,必须要同时使用 print 选项。如果验证一下 find 命令,会发现该命令只输出从当前路径起的相对路径及文件名。
#############################################################################################
[root@localhost d6z]# find /etc/ -type f -name "*.conf" -exec cat {} >>1.txt \;
[root@localhost d6z]# du -sh 1.txt ##查看1.txt文件大小
2.2M 1.txt
[root@localhost d6z]# gzip 1.txt ##压缩1.txt文件
[root@localhost d6z]# ls
1.txt.gz ##目录下1.txt文件消失,出现已压缩文件1.txt.gz
[root@localhost d6z]# du -sh 1.txt.gz ##查看1.txt.gz文件大小
316K 1.txt.gz ##压缩后的文件仅316K 压缩成功
[root@localhost d6z]# wc -l 1.txt ##查看文本一共的行数
31956 1.txt
解压命令:gzip -d 【压缩包文件名】或 gunzip 【压缩包文件名】
[root@localhost d6z]# gzip -d 1.txt.gz ##解压缩1.txt.gz文件
[root@localhost d6z]# ls ##查看当前目录是否解压成功
1.txt ##成功解压
[root@localhost d6z]# du -sh 1.txt ##查看解压后的文件大小
1.3M 1.txt ##解压成功(解压后的文件大小比压缩前的文件大小要小,是因为文件有水分PS:水真多!!!)
gzip -【数字1-9】【文件名】 ##-num 用指定的数字 num 调整压缩的速度,-1 或 --fast 表示最快压缩方法(低压缩比),-9 或--best表示最慢压缩方法(高压缩比)。系统缺省值为 6。
[root@localhost d6z]# gzip -1 1.txt ##用最快速度来压缩
[root@localhost d6z]# du -sh 1.txt.gz
372K 1.txt.gz ##最快速压缩后文件大小为372k
[root@localhost d6z]# gzip -d 1.txt.gz
[root@localhost d6z]# gzip -6 1.txt ##用第六级速度压缩
[root@localhost d6z]# du -sh 1.txt.gz
316K 1.txt.gz ##压缩后文件大小为316k
[root@localhost d6z]#
zcat 【压缩包文件名】 ##查看压缩文件的内容,相当于cat普通文件一样。
[root@localhost d6z]# cat /etc/sudo.conf >2.txt ##将sudo.conf追加到2.txt中
[root@localhost d6z]# ls
1.txt.gz 2.txt
[root@localhost d6z]# cat 2.txt ##查看2.txt内容
#
# Default /etc/sudo.conf file
#
# Format:
[root@localhost d6z]# gzip 2.txt ##压缩2.txt
[root@localhost d6z]# ls
1.txt.gz 2.txt.gz
[root@localhost d6z]# zcat 2.txt.gz ##用zcat查看2.txt.gz的文件内容
#
# Default /etc/sudo.conf file
#
# Format:
gzip -c 【文件名】>【路径】 ##把压缩后的文件输出,不去更动原始文件。
[root@qiaojidong 123]# ls
1.txt
[root@qiaojidong 123]# gzip -c 1.txt >1.txt.gz
[root@qiaojidong 123]# ls
1.txt 1.txt.gz
bzip2(bunzip2)压缩工具
bzip2默认没有安装,可以用yum安装
[root@qiaojidong 123]# yum install -y bzip2
已加载插件:fastestmirror
base | 3.6 kB 00:00
epel | 4.7 kB 00:00
extras | 3.4 kB 00:00
updates | 3.4 kB 00:00
(1/3): epel/x86_64/updateinfo | 1.0 MB 00:00
(2/3): updates/7/x86_64/primary_db | 3.4 MB 00:00
(3/3): epel/x86_64/primary_db | 6.6 MB 00:00
Determining fastest mirrors
软件包 bzip2-1.0.6-13.el7.x86_64 已安装并且是最新版本
无须任何处理
[root@qiaojidong 123]#
bzip2 压缩文件,无法压缩目录
[root@linux-01 ~]# bzip2 3.txt
[root@linux-01 ~]# ll
总用量 448
-rw-r--r--. 1 root root 425886 3月 26 22:26 1.txt
-rw-r--r--. 1 root root 3147 3月 26 22:31 2.txt
-rw-r--r--. 1 root root 453 3月 26 23:18 3.txt.bz2
-rw-------. 1 root root 1420 3月 14 01:02 anaconda-ks.cfg
-rw-r--r--. 1 root root 17301 3月 26 22:20 bb.log
【bzip2 -c 3.txt >3.txt.bz2】压缩文件,源文件保留
[root@linux-01 ~]# bzip2 -c 3.txt > 3.txt.bz2
[root@linux-01 ~]# ll
总用量 452
-rw-r--r--. 1 root root 425886 3月 26 22:26 1.txt
-rw-r--r--. 1 root root 3147 3月 26 22:31 2.txt
-rw-r--r--. 1 root root 933 3月 26 23:18 3.txt
-rw-r--r--. 1 root root 453 3月 27 00:36 3.txt.bz2
-rw-------. 1 root root 1420 3月 14 01:02 anaconda-ks.cfg
-rw-r--r--. 1 root root 17301 3月 26 22:20 bb.log
[root@linux-01 ~]#
【bzip2 -1 文件名】压缩级别
[root@linux-01 ~]# bzip2 -1 3.txt
[root@linux-01 ~]# file 3.txt.bz2
3.txt.bz2: bzip2 compressed data, block size = 100k ###与gzip一样,压缩等级一共有9个,但是默认压缩等级为9
[root@linux-01 ~]# bzip2 -d 3.txt.bz2 # 解压文件
[root@linux-01 ~]# bzip2 -9 3.txt
[root@linux-01 ~]# file 3.txt.bz2
3.txt.bz2: bzip2 compressed data, block size = 900k
bzip2 解压文件
【bzip2 -c 文件名】解压文件
[root@linux-01 ~]# bzip2 -d 3.txt.bz2
[root@linux-01 ~]# ll
总用量 448
-rw-r--r--. 1 root root 425886 3月 26 22:26 1.txt
-rw-r--r--. 1 root root 3147 3月 26 22:31 2.txt
-rw-r--r--. 1 root root 933 3月 26 23:18 3.txt
-rw-------. 1 root root 1420 3月 14 01:02 anaconda-ks.cfg
-rw-r--r--. 1 root root 17301 3月 26 22:20 bb.log
[root@linux-01 ~]#
【bzip2 -c -d 3.txt.bz2 > 3.txt】解压文件,源文件保留
[root@linux-01 ~]# bzip2 -c -d 3.txt.bz2 > 3.txt
[root@linux-01 ~]# ll
总用量 452
-rw-r--r--. 1 root root 425886 3月 26 22:26 1.txt
-rw-r--r--. 1 root root 3147 3月 26 22:31 2.txt
-rw-r--r--. 1 root root 933 3月 27 00:56 3.txt
-rw-r--r--. 1 root root 453 3月 26 23:18 3.txt.bz2
-rw-------. 1 root root 1420 3月 14 01:02 anaconda-ks.cfg
-rw-r--r--. 1 root root 17301 3月 26 22:20 bb.log
【bzcat 3.txt.bz2 】 查看bzip2 压缩文件中的内容
[root@linux-01 ~]# bzcat 3.txt.bz2
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:999:998:User for polkitd:/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
xihaji:x:1000:1000::/home/xihaji:/bin/bash
xihaji2:x:1001:1001::/home/xihaji2:/bin/bash
readonly:x:1002:1002::/home/readonly:/bin/bash
xz 解压工具
xz压缩文件,无法压缩目录
【xz 文件名】压缩文件,源文件消失
[root@linux-01 ~]# xz 3.txt
[root@linux-01 ~]# ll
总用量 448
-rw-r--r--. 1 root root 425886 3月 26 22:26 1.txt
-rw-r--r--. 1 root root 3147 3月 26 22:31 2.txt
-rw-r--r--. 1 root root 472 3月 27 00:56 3.txt.xz
-rw-------. 1 root root 1420 3月 14 01:02 anaconda-ks.cfg
-rw-r--r--. 1 root root 17301 3月 26 22:20 bb.log
[root@linux-01 ~]#
【xz -c 2.txt > 2.txt.xz】压缩文件,保留源文件
[root@linux-01 ~]# xz -c 2.txt > 2.txt.xz
[root@linux-01 ~]# ll
总用量 452
drwxr-xr-x. 2 root root 6 3月 27 02:47 111
-rw-r--r--. 1 root root 425886 3月 26 22:26 1.txt
-rw-r--r--. 1 root root 3147 3月 26 22:31 2.txt
-rw-r--r--. 1 root root 904 3月 27 02:50 2.txt.xz
-rw-r--r--. 1 root root 472 3月 27 00:56 3.txt.xz
-rw-------. 1 root root 1420 3月 14 01:02 anaconda-ks.cfg
-rw-r--r--. 1 root root 17301 3月 26 22:20 bb.log
[root@linux-01 ~]#
【xz -1 1.txt】压缩级别
xz与bzip2和gzip类似, -0 到 -9调节压缩率。如果不设置,默认压缩等级是6.
[root@linux-01 ~]# xz -1 1.txt
[root@linux-01 ~]# ll
总用量 88
drwxr-xr-x. 2 root root 6 3月 27 02:47 111
-rw-r--r--. 1 root root 52372 3月 26 22:26 1.txt.xz
-rw-r--r--. 1 root root 3147 3月 26 22:31 2.txt
-rw-r--r--. 1 root root 904 3月 27 02:50 2.txt.xz
-rw-r--r--. 1 root root 472 3月 27 00:56 3.txt.xz
-rw-------. 1 root root 1420 3月 14 01:02 anaconda-ks.cfg
-rw-r--r--. 1 root root 17301 3月 26 22:20 bb.log
xz 解压文件
【xz -d 文件名】解压文件,源文件消失
[root@linux-01 ~]# xz -d 1.txt.xz
[root@linux-01 ~]# ll
总用量 452
drwxr-xr-x. 2 root root 6 3月 27 02:47 111
-rw-r--r--. 1 root root 425886 3月 26 22:26 1.txt
-rw-r--r--. 1 root root 3147 3月 26 22:31 2.txt
-rw-r--r--. 1 root root 904 3月 27 02:50 2.txt.xz
-rw-r--r--. 1 root root 472 3月 27 00:56 3.txt.xz
-rw-------. 1 root root 1420 3月 14 01:02 anaconda-ks.cfg
-rw-r--r--. 1 root root 17301 3月 26 22:20 bb.log
【xz -d -c 3.txt.xz >3.txt】解压文件,源文件保留
[root@linux-01 ~]# xz -d -c 3.txt.xz >3.txt
[root@linux-01 ~]# ll
总用量 456
drwxr-xr-x. 2 root root 6 3月 27 02:47 111
-rw-r--r--. 1 root root 425886 3月 26 22:26 1.txt
-rw-r--r--. 1 root root 3147 3月 26 22:31 2.txt
-rw-r--r--. 1 root root 904 3月 27 02:50 2.txt.xz
-rw-r--r--. 1 root root 933 3月 27 02:58 3.txt
-rw-r--r--. 1 root root 472 3月 27 00:56 3.txt.xz
-rw-------. 1 root root 1420 3月 14 01:02 anaconda-ks.cfg
-rw-r--r--. 1 root root 17301 3月 26 22:20 bb.log
【xzcat 3.txt.xz 】查看 xz 压缩文件中的内容
[root@linux-01 ~]# xzcat 3.txt.xz
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:999:998:User for polkitd:/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
xihaji:x:1000:1000::/home/xihaji:/bin/bash
xihaji2:x:1001:1001::/home/xihaji2:/bin/bash
readonly:x:1002:1002::/home/readonly:/bin/bash
[root@linux-01 ~]#
zip文件,可以压缩文件夹
zip可以用yum安装
[root@linux-01 ~]# yum install -y zip
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: ap.stykers.moe
* extras: mirrors.zju.edu.cn
* updates: mirrors.njupt.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 zip.x86_64.0.3.0-11.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
=====================================================================================================================================
Package 架构 版本 源 大小
=====================================================================================================================================
正在安装:
zip x86_64 3.0-11.el7 base 260 k
事务概要
=====================================================================================================================================
安装 1 软件包
总下载量:260 k
安装大小:796 k
Downloading packages:
zip-3.0-11.el7.x86_64.rpm | 260 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : zip-3.0-11.el7.x86_64 1/1
验证中 : zip-3.0-11.el7.x86_64 1/1
已安装:
zip.x86_64 0:3.0-11.el7
完毕!
zip 压缩文件
【zip 压缩后的文件名 源文件】压缩文件
[root@linux-01 ~]# zip 2.txt.zip 2.txt
adding: 2.txt (deflated 74%)
[root@linux-01 ~]# ll
总用量 568
drwxr-xr-x. 2 root root 6 3月 27 02:47 111
-rw-r--r--. 1 root root 425886 3月 26 22:26 1.txt
-rw-r--r--. 1 root root 108925 3月 27 03:12 1.txt.zip
-rw-r--r--. 1 root root 3147 3月 26 22:31 2.txt
-rw-r--r--. 1 root root 904 3月 27 02:50 2.txt.xz
-rw-r--r--. 1 root root 966 3月 27 03:15 2.txt.zip
-rw-r--r--. 1 root root 933 3月 27 02:58 3.txt
-rw-r--r--. 1 root root 472 3月 27 00:56 3.txt.xz
-rw-------. 1 root root 1420 3月 14 01:02 anaconda-ks.cfg
-rw-r--r--. 1 root root 17301 3月 26 22:20 bb.log
[root@linux-01 ~]#
【zip 压缩后的文件名 源文件1 目录1】压缩目录
[root@linux-01 ~]# zip 1.txt.zip 1.txt 2.txt 3.txt 111/
adding: 1.txt (deflated 75%)
adding: 2.txt (deflated 74%)
adding: 3.txt (deflated 58%)
adding: 111/ (stored 0%)
[root@linux-01 ~]# ll
总用量 564
drwxr-xr-x. 2 root root 6 3月 27 02:47 111
-rw-r--r--. 1 root root 425886 3月 26 22:26 1.txt
-rw-r--r--. 1 root root 108925 3月 27 03:12 1.txt.zip
-rw-r--r--. 1 root root 3147 3月 26 22:31 2.txt
-rw-r--r--. 1 root root 904 3月 27 02:50 2.txt.xz
-rw-r--r--. 1 root root 933 3月 27 02:58 3.txt
-rw-r--r--. 1 root root 472 3月 27 00:56 3.txt.xz
-rw-------. 1 root root 1420 3月 14 01:02 anaconda-ks.cfg
-rw-r--r--. 1 root root 17301 3月 26 22:20 bb.log
[root@linux-01 ~]#
unzip 解压文件
unzip可以用yum安装
[root@linux-01 ~]# yum install -y unzip
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: ap.stykers.moe
* extras: mirrors.zju.edu.cn
* updates: mirrors.njupt.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 unzip.x86_64.0.6.0-19.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
=====================================================================================================================================
Package 架构 版本 源 大小
=====================================================================================================================================
正在安装:
unzip x86_64 6.0-19.el7 base 170 k
事务概要
=====================================================================================================================================
安装 1 软件包
总下载量:170 k
安装大小:365 k
Downloading packages:
unzip-6.0-19.el7.x86_64.rpm | 170 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : unzip-6.0-19.el7.x86_64 1/1
验证中 : unzip-6.0-19.el7.x86_64 1/1
已安装:
unzip.x86_64 0:6.0-19.el7
完毕!
[root@linux-01 ~]#
【unzip 文件名】解压缩文件
[root@linux-01 ~]# unzip 1.txt.zip
Archive: 1.txt.zip
replace 1.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
inflating: 1.txt
replace 2.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
inflating: 2.txt
replace 3.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
inflating: 3.txt
【unzip 文件名 -d 目标路径】解压缩文件到指定目录
[root@linux-01 ~]# unzip 1.txt.zip -d /root/test/
Archive: 1.txt.zip
inflating: /root/test/1.txt
inflating: /root/test/2.txt
inflating: /root/test/3.txt
creating: /root/test/111/
[root@linux-01 ~]# ll test/
总用量 424
drwxr-xr-x. 2 root root 6 3月 27 02:47 111
-rw-r--r--. 1 root root 425886 3月 26 22:26 1.txt
-rw-r--r--. 1 root root 3147 3月 26 22:31 2.txt
-rw-r--r--. 1 root root 933 3月 27 02:58 3.txt
[root@linux-01 ~]#
【unzip -l 1.txt.zip 】查看压缩文件的文件列表
[root@linux-01 ~]# unzip -l 1.txt.zip
Archive: 1.txt.zip
Length Date Time Name
--------- ---------- ----- ----
425886 03-26-2019 22:26 1.txt
3147 03-26-2019 22:31 2.txt
933 03-27-2019 02:58 3.txt
0 03-27-2019 02:47 111/
--------- -------
429966 4 files
[root@linux-01 ~]#
tar打包文件
## 基本格式:tar [Options] file_archive //注意tar的第一参数必须为命令选项,即不能直接接待处理文件
- 常用命令参数:
-c #创建一个新的打包文件(archive)
-x # 对打包文件(archive)进行解压操作
-t # 查看打包文件(archive)的内容,主要是构成打包文件(archive)的文件名
-z # 使用gzip进行压缩/解压,一般使用.tar.gz后缀
-j # 使用bzip2进行压缩/解压,一般使用.tar.bz2后缀
-f # 指定tar指令使用的文件,若没有压缩操作,则以.tar作为后缀
-v # 详细显示正在处理的文件名
-C Dir # 将解压文件放置在 -C 指定的目录下
-p(小写) # 保留文件的权限和属性,在备份文件时较有用
-P(大写) # 保留原文件的绝对路径,即不会拿掉文件路径开始的根目录,则在还原时会覆盖对应路径上的内容
--exclude=file # 排除不进行打包的文件
【tar -cvf 111.tar 111】打包一个文件夹
[root@linux-01 ~]# tar -cvf 111.tar 111
111/
111/1.txt
111/1.txt.zip
111/2.txt.xz
111/3.txt.xz
111/3.txt
111/2.txt
111/test/
[root@linux-01 ~]# ll
总用量 564
drwxr-xr-x. 3 root root 106 3月 28 03:08 111
-rw-r--r--. 1 root root 552960 3月 28 03:11 111.tar
-rw-------. 1 root root 1420 3月 14 01:02 anaconda-ks.cfg
-rw-r--r--. 1 root root 17301 3月 26 22:20 bb.log
drwxr-xr-x. 3 root root 56 3月 27 03:27 test
[root@linux-01 ~]#
## 打包文件排除某些文件 ##
[root@linux-01 ~]# tar -cvf 111.tar 111/ --exclude 1.txt --exclude 2.txt
111/
111/test/
111/1.txt.zip
111/2.txt.xz
111/3.txt.xz
111/3.txt
[root@linux-01 ~]#
【tar -xvf 111.tar 】解包文件
[root@linux-01 ~]# tar -xvf 111.tar
111/
111/1.txt
111/1.txt.zip
111/2.txt.xz
111/3.txt.xz
111/3.txt
111/2.txt
111/test/
【tar -tf 111.tar 】查看打包文件的文件列表
[root@linux-01 ~]# tar -tf 111.tar
111/
111/1.txt
111/1.txt.zip
111/2.txt.xz
111/3.txt.xz
111/3.txt
111/2.txt
111/test/
tar打包并压缩
打包压缩
tar打包压缩gz格式(加-z选项)
[root@linux-01 ~]# tar -czvf 111.tar.gz 111/
111/
111/test/
111/1.txt
111/1.txt.zip
111/2.txt.xz
111/3.txt.xz
111/3.txt
111/2.txt
[root@linux-01 ~]# ll
总用量 360
drwxr-xr-x. 3 root root 106 3月 28 03:08 111
-rw-r--r--. 1 root root 122880 3月 28 03:20 111.tar
-rw-r--r--. 1 root root 221138 3月 28 03:23 111.tar.gz
-rw-------. 1 root root 1420 3月 14 01:02 anaconda-ks.cfg
-rw-r--r--. 1 root root 17301 3月 26 22:20 bb.log
drwxr-xr-x. 3 root root 56 3月 27 03:27 test
[root@linux-01 ~]# du -sh 111.tar.gz
216K 111.tar.gz
[root@linux-01 ~]#
tar打包压缩bz2格式(加-j选项)
[root@linux-01 ~]# tar -cjvf 111.tar.bz2 111/
111/
111/test/
111/1.txt
111/1.txt.zip
111/2.txt.xz
111/3.txt.xz
111/3.txt
111/2.txt
[root@linux-01 ~]# du -sh 111.tar.bz2
176K 111.tar.bz2
[root@linux-01 ~]#
tar打包压缩xz格式(加-J选项)
[root@linux-01 ~]# tar -cJvf 111.tar.xz 111/
111/
111/test/
111/1.txt
111/1.txt.zip
111/2.txt.xz
111/3.txt.xz
111/3.txt
111/2.txt
[root@linux-01 ~]# du -sh 111.tar.xz
156K 111.tar.xz
解压解包
解压tar.gz文件
[root@linux-01 222]# tar -zxvf 111.tar.gz
111/
111/test/
111/1.txt
111/1.txt.zip
111/2.txt.xz
111/3.txt.xz
111/3.txt
111/2.txt
解压tar.bzip2文件
[root@linux-01 222]# tar -jxvf 111.tar.bz2
111/
111/test/
111/1.txt
111/1.txt.zip
111/2.txt.xz
111/3.txt.xz
111/3.txt
111/2.txt
解压tar.xz文件
[root@linux-01 222]# tar -Jxvf 111.tar.xz
111/
111/test/
111/1.txt
111/1.txt.zip
111/2.txt.xz
111/3.txt.xz
111/3.txt
111/2.txt
压缩比例xz>bz2>gzip。
注: zip、bzip2、xz仅能对文件进行压缩,不能对目录进行压缩。