zip
The zip command in Linux is commonly used for file compression and packaging. It allows you to create .zip files, which are compressed archives containing one or more files or directories. Here are the key functionalities and usage examples of the zip command:
Creating Zip Archives: To create a zip archive, use
zipfollowed by the name of the archive you want to create, and then list the files or directories to be included. For example:zip archive.zip file1.txt file2.txtwill create an archive namedarchive.zipcontainingfile1.txtandfile2.txt.Recursive Compression: To include a directory along with all its subdirectories and files, use the
-r(recursive) option. For instance:zip -r archive.zip directorynamewill compress the entire directory nameddirectorynameand its contents intoarchive.zip.Compression Levels:
zipallows specifying the compression level with-0(no compression) to-9(best compression). If not specified,zipuses a default compression level. Example:zip -9 archive.zip file.txtuses maximum compression forfile.txt.Excluding Files: If you want to exclude certain files from the zip archive, use the
-xoption. For example:zip archive.zip * -x exclude.txtwill zip all files in the current directory exceptexclude.txt.Listing Zip Contents: To view the contents of a zip archive without extracting it, use
zip -l archive.zip. This command lists the files included inarchive.zip.Adding Files to Existing Archive: You can add files to an existing zip archive with the same
zipcommand. For example,zip archive.zip newfile.txtaddsnewfile.txttoarchive.zip.Splitting Zip Files: For large archives,
zipcan split the file into smaller parts. This is done using the-soption followed by the size (e.g.,-s 100mfor 100 MB parts).Zip Options:
ziphas many options for customization, like adjusting compression method, adding comments to archives, and more.
Last updated