Linux system management and maintenance -zip/unzip command

  

1. The function description compresses or decompresses the general file or directory. By default, the compressed package with the suffix "<;zip”" is generated. The zip command is similar to the winzip compression program in Windows
. The format is as follows: zip [options] compressed file name list of documents to be compressed unzip [options] The options for the compressed file name zip command and their descriptions are shown in Table 4.27. Table 4.27 Options and Descriptions of the zip Command

Option Meaning-r Recursive compression, all files and subdirectories under the specified directory are compressed -d Delete the specified file from the compressed file -i “ ” Only compress the files in the file list -x “file list” Exclude the file specified in the file list when compressing -u Update the file to the compressed file -m Add the file to the compressed file and compress it, delete the original file, ie Files are moved to a compressed file -F Try to repair corrupted compressed files -T Check that each file in the compressed file is correct - Compression level compression level is a 1 to 9 numeric unzip command option and its description is shown in Table 4.28 Show. Table 4.28 Options and Descriptions of the unzip Command

Option Meaning -x "File List" Unzip the file, but do not include the file specified in the file list -t Test the compressed file for damage, no decompression - v View the details of the compressed file, including the file size, file name, and compression ratio contained in the compressed file. It does not decompress -n. It does not overwrite existing files when decompressing. -o Overwrite existing files when unpacking, and does not require The user confirms the -d directory name to extract the compressed file to the specified directory. Example (1) Compress all files and directories in the /etc directory, set the compression level to the highest, and save to the file /opt/etc.zip. [root@mylinux ~]# zip -9r /opt/etc.zip /etc(2) Compress all files and subdirectories in the /var directory, save the compressed files to /opt except for the files of “*.log” Under contents. [root@mylinux ~]#zip –r /opt/var.zip /var –x “*.log”(3) Remove the etc/passwd file from /opt/etc.zip above from the archive . [root@mylinux ~]#zip /opt/etc.zip –d etc/passwddeleting: etc/passwd(4) Modified the /etc/inittab file and hope to update the changes to the /opt/etc.zip package. [root@mylinux ~]#zip –u /opt/etc.zip /etc/inittab If many files in the /etc directory have been modified or a lot of files have been added, you need to update all the information in the /etc directory to /Opt/etc.zip file. You can use the following command: [root@mylinux ~]#zip –u /opt/etc.zip /etc/* or use [root@mylinux ~]# zip –ru /opt/etc.zip /etc to see the point Is it mysterious? In the above example, in fact, "/etc/*” represents all the files and subdirectories in the /etc directory, and this is exactly the function of the zip command "-r". (5) Decompress the /opt/etc.zip compressed file to the /etc directory, except for the etc/inittab file, and if the same file appears during the decompression process, it will be overwritten without requiring the user to confirm. You can use the following command: [root@mylinux ~]#unzip –o /opt/etc.zip –x etc/inittab –d /etc

Copyright © Windows knowledge All Rights Reserved