In the process of using the windows system, when we want to transfer some large files, we have to compress them. When using the linux system, the files are compressed and decompressed very frequently. For example, when the server-side program runs, a large number of logs will be generated. To analyze the operation of the application and so on. Let's learn how to use the tar command together:
-c: create a compressed archive
-x: decompress
-t: view content
-r: append files to the end of the compressed archive
-u: update the files in the original compressed package
-z: with gzip attribute
-j: with bz2 attribute
-Z: with compress attribute
-v: show all processes
-O: unpack file to stdout
The following parameter -f is required
-f: Use the file name, remember, this parameter is the last parameter, only the file name can be followed.
Package all shell scripts in the shell directory
[root@localhost shell]# tar -cf all.jar ./*.* [c means create]
[root@localhost shell]# ll
-rw-r--r -- 1 root root 20480 September 13 22:06 all.jar
Create a new file:
[root@localhost shell]# echo "hello world" >> b.txt
Append the b.txt file to the all.jar compressed file
[root@localhost shell]# tar -rf all.jar ./b.txt [r means append]
add content to b.txt file aaaa
[root@localhost shell]# echo "aaaa" >> b.txt
will be modified Re-append the b.txt file to the all.jar compressed file
[root@localhost shell]# tar -uf all.jar ./b.txt
[root@localhost shell]# tar -tf all.jar [t means list files]
./09101.sh
./09102.sh
./arg.sh
./a.txt
. /demo.sh
./file.sh
./hello.sh
./if.sh
./lsSh.sh
./name.sh
./b.txt
./b.txt
[root@localhost shell]# mkdir demo
Move the compressed package file to the demo directory for decompression
[root@localhost shell]# mv all.jar ./demo
[root@localhost shell]#tar -xf all.jar [x means decompression]
[root@localhost shell]#tar -cvf shell.tar ./*.sh //Package all shell files in the directory into tar
[root@localhost shell]#tar -czf shell.tar.gz ./*.sh //Package all jpg files in the directory into jpg.tar, and compress it with gzip to generate a gzip compressed package, named shell.tar.gz
[root@localhost shell]#tar -cjf shell.tar.bz2 ./*.jpg //Pack all jpg files in the directory into jpg.tar, and compress them with bzip2 to generate a bzip2 compressed package, Name it shell.tar.bz2
[root@localhost shell]#tar -cZf shell.tar.Z ./*.jpg //Pack all jpg files in the directory into jpg.tar, and compress them with compress to generate a umcompress compressed package, named shell.tar.Z
[root@localhost shell]#rar a shell.rar ./*.shell//rar format compression, you need to download rar for linux first
[root@localhost shell]#zip shell.zip ./*.shell//zip format compression, you need to download zip for linux first
decompress
[root@localhost shell]#tar -xvf shell.tar //Unzip the tar package
[root@localhost shell]#tar -xzvf shell.tar.gz //解压tar.gz
[root@localhost shell]#tar -xjvf shell.tar.bz2 //解压 tar.bz2
[root@localhost shell]#tar -xZvf shell.tar.Z //解压tar.Z
[root@localhost shell]#unrar e shell.rar //解压rar
[root@localhost shell]#unzip shell.zip //Unzip zip