Put a bunch of files together and move them easily
Save space after compression, text saves 2/3
Implement the backup function
Packing and compression tools: tar, gzip, unzip, zip
1.1. tarPacking and compression (generally use this extension .tar.gz)
1.1.1 tar packing
Packaging combination: zcvf
letter
meaning
z
compression
c
rebuild file
v
display output
f
show file compression
grammar:tar zcvf 压缩包的名字 要打包的内容
Example: pack the files in the ect directory into etc.tar.gz in the current directory (create if not)tar zcvf etc.tar.gz /etc/
Details: After packaging, the symbol of the root of the directory will be removed /etc( etcif not, the source file that may be updated will be replaced when decompressing)
1.1.2. tar unpacking
combination of options
letter
meaning
z
compression
x
unpack
v
display output
f
show file compression
Unpack to the current directory:tar zxvf 包名
Unpack to the specified directory:tar zxvf 包名 -C 指定目录
Common methods when unpacking
Do not unpack to see the content:tar tf 包
Let the packaged path take time (backup):
反引号and $()you can put commands inside
method [root@localhost ~]# tar zcvf etc_$(date +%F).tar.gz /etc/
result
[root@localhost ~]ls
anaconda-ks.cfg etc.tar.gz oldboy.txt
etc_2023-07-21.tar.gz m1 test
1.2 gzipPackage compression (delete the original file after compression and decompression)
Pack into the current directory:gzip a.txt
View the contents of the package:zcat a.txt.gz
Pack and compress multiple files:gzip -r oldboy
Unzip:gzip -d a.txt.gz
1.3 zipDecompression
Uses: Unzip the Windows zip file to the current directory
Method 1 (use curly braces to move the position of the found file) (xargs -i is to put the found content in curly braces) find /data -name "file*" -mtime +5|xargs -i cp {} /tmp
Method 2 (use cp parameters to adjust cp syntax source and target position sequence) find /data/ -type f -mtime +3|xargs cp -t /tmp
2.3.3 Pack and compress the things found by find
Find and package all files starting with ip under /sbin find /sbin/ -type f -name "ip*"|xargs tar zcvf ip.tar.gz
2.3.4 Use find to find the file containing a certain string
find / -type f -mtime -7|xargs grep "oldboy"
2.3.5 Logical operators of find
And and -a defaults to the fact that -a is omitted in the middle of multiple conditions.