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
zip
followed 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.txt
will create an archive namedarchive.zip
containingfile1.txt
andfile2.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 directoryname
will compress the entire directory nameddirectoryname
and its contents intoarchive.zip
.Compression Levels:
zip
allows specifying the compression level with-0
(no compression) to-9
(best compression). If not specified,zip
uses a default compression level. Example:zip -9 archive.zip file.txt
uses maximum compression forfile.txt
.Excluding Files: If you want to exclude certain files from the zip archive, use the
-x
option. For example:zip archive.zip * -x exclude.txt
will 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
zip
command. For example,zip archive.zip newfile.txt
addsnewfile.txt
toarchive.zip
.Splitting Zip Files: For large archives,
zip
can split the file into smaller parts. This is done using the-s
option followed by the size (e.g.,-s 100m
for 100 MB parts).Zip Options:
zip
has many options for customization, like adjusting compression method, adding comments to archives, and more.
Last updated