Zip Command
On Linux, the zip command is used to package and compress (archive) files. Here are some basic usages of the zip command:
-
Compress files into zip format:
zip archive_name.zip file1 file2 file3Here,
archive_name.zipis the name of the zip file you want to create, andfile1,file2, andfile3are the files you want to compress. -
Compress an entire directory into zip format:
zip -r archive_name.zip directory_nameThe
-rflag means recursive processing, compressing all files and subdirectories under the specified directory into the zip file. -
Compress specific file types using wildcards:
zip archive_name.zip *.txtThis command compresses all files with the
.txtextension intoarchive_name.zip. -
Compress files into zip format with encryption:
zip -e encrypted_archive.zip file1 file2The
-eflag encrypts the compressed file. After running this command, the system will prompt you to enter a password. -
Exclude specific files or directories:
zip -r archive_name.zip folder_to_zip -x file_to_exclude \*.logThe
-xflag specifies files or patterns to exclude. The above command compresses thefolder_to_zipdirectory but excludes all.logfiles andfile_to_exclude. -
View the contents of a zip file:
zip -sf archive_name.zipThe
-sfflag displays the file list inside the zip file without extracting it. -
Extract specific files from a zip file:
unzip archive_name.zip file_to_extractThis command only extracts
file_to_extractfromarchive_name.zip. -
Extract a zip file to a specified directory:
unzip archive_name.zip -d destination_directoryThe
-dflag specifies the destination directory for extraction.
These are the basic usages of the zip command. The zip command has many other options and parameters. You can view more detailed help by entering man zip in the terminal.