压缩和解压类:
gzip/gunzip压缩与解压:1.不能压缩目录| 2.不保留原文件
压缩:
[root@future damo]# ll
-rwxrwxrwx. 1 root root 67 11月 7 15:57 bb.txt
[root@future damo]# gzip bb.tx
[root@future damo]# ll
-rwxrwxrwx. 1 root root 79 11月 7 15:57 bb.txt.gz
解压:
[root@future damo]# ll
-rwxrwxrwx. 1 root root 79 11月 7 15:57 bb.txt.gz
[root@future damo]# gunzip bb.txt.gz
[root@future damo]# ll
-rwxrwxrwx. 1 root root 67 11月 7 15:57 bb.txt
zip/unzip压缩与解压: Windows和Linux是通用的,可以压缩目录且保留源文件
1.1压缩单个文件:
[root@future damo]# ll
-rwx-wxrwx. 1 root root 0 11月 7 14:31 aa.txt
[root@future damo]# zip a.zip aa.txt
adding: aa.txt (stored 0%)
[root@future damo]# ll
-rwx-wxrwx. 1 root root 0 11月 7 14:31 aa.txt
-rw-r--r--. 1 root root 162 11月 7 16:06 a.zip
1.2压缩多个文件:
[root@future damo]# ll
-rwx-wxrwx. 1 root root 0 11月 7 14:31 aa.txt
-rw-r--r--. 1 damo shaolin 50 11月 7 14:23 a.txt
-rwxrwxrwx. 1 root root 67 11月 7 15:57 bb.txt
[root@future damo]# zip file1.zip a.txt aa.txt b.tx.gz
adding: a.txt (deflated 8%)
adding: aa.txt (stored 0%)
adding: b.tx.gz (stored 0%)
[root@future damo]# ll
-rwx-wxrwx. 1 root root 0 11月 7 14:31 aa.txt
-rw-r--r--. 1 damo shaolin 50 11月 7 14:23 a.txt
-rw-r--r--. 1 damo root 107 12月 6 2021 b.tx.gz
-rw-r--r--. 1 root root 595 11月 7 16:05 file1.zip
1.3压缩目录: -d
[root@future damo]# ll
drwxr-xr-x. 2 damo shaolin 20 11月 7 14:25 hello
[root@future damo]# zip -r h.zip hello/
adding: hello/ (stored 0%)
adding: hello/mm.txt (stored 0%)
[root@future damo]# ll
drwxr-xr-x. 2 damo shaolin 20 11月 7 14:25 hello
-rw-r--r--. 1 root root 314 11月 7 16:10 h.zip
2.1解压文件
[root@future damo]# ll
-rw-r--r--. 1 root root 162 11月 7 16:06 a.zip
[root@future damo]# unzip a.zip
Archive: a.zip
extracting: aa.txt
[root@future damo]# ll
-rwx-wxrwx. 1 root root 0 11月 7 14:31 aa.txt
-rw-r--r--. 1 root root 162 11月 7 16:06 a.zip
2.2解压文件到xx目录 -d
[root@future damo]# ll
-rw-r--r--. 1 root root 314 11月 7 16:10 h.zip
[root@future damo]# unzip h.zip -d /home
Archive: h.zip
creating: /home/hello/
extracting: /home/hello/mm.txt
[root@future damo]# ll ./../
drwxr-xr-x. 2 root root 20 11月 7 14:25 hello
tar 压缩与解压
压缩: tar -zcvf 压缩包名称 压缩文件
解压:tar -zxvf 压缩包名称 压缩文件
解压具体目录:tar -zxvf 压缩包名称 -C 压缩文件
压缩文件(多个文件,单个文件): ====== c
[root@future damo]# ll
-rwx-wxrwx. 1 root root 0 11月 7 14:31 aa.txt
-rw-r--r--. 1 root root 162 11月 7 16:06 a.zip
-rwxrwxrwx. 1 root root 67 11月 7 15:57 bb.txt
[root@future damo]# tar -zcvf tt.tar.gz aa.txt a.zip bb.txt
aa.txt
a.zip
bb.txt
[root@future damo]# ll
总用量 40
-rwx-wxrwx. 1 root root 0 11月 7 14:31 aa.txt
-rw-r--r--. 1 root root 162 11月 7 16:06 a.zip
-rwxrwxrwx. 1 root root 67 11月 7 15:57 bb.txt
-rw-r--r--. 1 root root 308 11月 7 16:20 tt.tar.gz
压缩目录:
[root@future home]# tar -zcvf damo.tar.gz damo/
damo/
damo/.mozilla/
damo/.mozilla/extensions/
damo/.mozilla/plugins/
damo/.bash_logout
damo/.bash_profile
damo/.bashrc
damo/.cache/
damo/.cache/abrt/
damo/.cache/abrt/lastnotification
damo/.config/
damo/.config/abrt/
damo/.bash_history
damo/good
damo/.viminfo
damo/person.java
damo/lingpingzhi.txt
damo/b.tx.gz
damo/bb.txt
damo/file1.zip
damo/a.zip
damo/h.zip
damo/aa.txt
damo/tt.tar.gz
[root@future home]# ll
总用量 12
drwx------. 5 damo shaolin 4096 11月 7 16:20 damo
-rw-r--r--. 1 root root 2644 11月 7 16:24 damo.tar.gz
解压: ====== x
解压到当前目录:
[root@future home]# ll
总用量 12
drwx------. 5 damo shaolin 4096 11月 7 16:20 damo
-rw-r--r--. 1 root root 2644 11月 7 16:24 damo.tar.gz
[root@future home]# rm -rf damo
[root@future home]# ll
-rw-r--r--. 1 root root 2644 11月 7 16:24 damo.tar.gz
[root@future home]# tar -zxvf damo.tar.gz
damo/
damo/.mozilla/
damo/.mozilla/extensions/
damo/.mozilla/plugins/
damo/.bash_logout
damo/.bash_profile
damo/.bashrc
damo/.cache/
damo/.cache/abrt/
damo/.cache/abrt/lastnotification
tar: damo/.cache/abrt/lastnotification:时间戳 2021-12-06 16:31:55 是未来的 2505876.892170975 秒之后
damo/.config/
tar: damo/.cache/abrt:时间戳 2021-12-06 16:31:55 是未来的 2505876.892035937 秒之后
tar: damo/.cache:时间戳 2021-12-06 16:09:18 是未来的 2504519.892023284 秒之后
damo/.config/abrt/
damo/.bash_history
tar: damo/.config/abrt:时间戳 2021-12-06 16:09:18 是未来的 2504519.891961329 秒之后
tar: damo/.config:时间戳 2021-12-06 16:09:18 是未来的 2504519.891952056 秒之后
tar: damo/.bash_history:时间戳 2021-12-06 16:34:08 是未来的 2506009.891917554 秒之后
damo/good
damo/.viminfo
tar: damo/.viminfo:时间戳 2021-12-06 16:33:01 是未来的 2505942.891700317 秒之后
damo/person.java
damo/lingpingzhi.txt
damo/b.tx.gz
tar: damo/b.tx.gz:时间戳 2021-12-06 16:17:35 是未来的 2505016.891467654 秒之后
damo/bb.txt
damo/file1.zip
damo/a.zip
damo/h.zip
damo/aa.txt
damo/tt.tar.gz
tar: damo/good:时间戳 2021-12-06 16:24:54 是未来的 2505455.890832814 秒之后
[root@future home]# ll
总用量 12
drwx------. 5 damo shaolin 4096 11月 7 16:20 damo
-rw-r--r--. 1 root root 2644 11月 7 16:24 damo.tar.gz
2.2解压到指定目录 大写C指定目录
tar -zxvf
[root@future home]# ll
drwx------. 5 damo shaolin 4096 11月 7 16:20 damo
-rw-r--r--. 1 root root 2644 11月 7 16:24 damo.tar.gz
[root@future home]# tar -zxvf damo.tar.gz -C /opt
damo/
damo/.mozilla/
damo/.mozilla/extensions/
damo/.mozilla/plugins/
damo/.bash_logout
damo/.bash_profile
damo/.bashrc
damo/.cache/
damo/.cache/abrt/
damo/.cache/abrt/lastnotification
tar: damo/.cache/abrt/lastnotification:时间戳 2021-12-06 16:31:55 是未来的 2505693.253622533 秒之后
damo/.config/
tar: damo/.cache/abrt:时间戳 2021-12-06 16:31:55 是未来的 2505693.253421212 秒之后
tar: damo/.cache:时间戳 2021-12-06 16:09:18 是未来的 2504336.253411984 秒之后
damo/.config/abrt/
damo/.bash_history
tar: damo/.config/abrt:时间戳 2021-12-06 16:09:18 是未来的 2504336.25334474 秒之后
tar: damo/.config:时间戳 2021-12-06 16:09:18 是未来的 2504336.253338071 秒之后
tar: damo/.bash_history:时间戳 2021-12-06 16:34:08 是未来的 2505826.253310655 秒之后
damo/good
damo/.viminfo
tar: damo/.viminfo:时间戳 2021-12-06 16:33:01 是未来的 2505759.253016475 秒之后
damo/person.java
damo/lingpingzhi.txt
damo/b.tx.gz
tar: damo/b.tx.gz:时间戳 2021-12-06 16:17:35 是未来的 2504833.252843244 秒之后
damo/bb.txt
damo/file1.zip
damo/a.zip
damo/h.zip
damo/aa.txt
damo/tt.tar.gz
tar: damo/good:时间戳 2021-12-06 16:24:54 是未来的 2505272.252361352 秒之后
[root@future home]# ll /opt
drwx------. 5 damo shaolin 4096 11月 7 16:20 damo