Use the zip
command to compress the files into a zip file, and the unzip
command to extract the compressed files from a zip archive.
zip
Command
To compress file
zip -r file.zip file_or_folder
Compresses folders and/or files and turns them into file.zip
.
unzip
Command
The unzip
command has a really simple syntax (see below). If you use it to extract a zip file without any options, it will extract all the files in the current directory.
unzip [option] zip_file
Note: By default, unzip prints the names of all the files it extracted and a summary when the extraction is complete. If you want to suppress the output message of the unzip command, you can use the -q
switch to not print any of these extraction messages.
unzip -q filename.zip
Unzip to a directory
The expected behavior is that the files are extracted to a specific directory, which normally has the same name as the zip file. You can specify the target directory where you want to extract the files.
unzip -d target_directory zip_file
If the target directory does not exist, it will be created. You can also put the target directory at the end, but not all options can be appended.
Extract only to current directory
Extract files from the baransel.zip
archive only to the current directory, regardless of the archive’s internal directory structure.
unzip -j baransel.zip
The -j
command argument indicates that the directory structure of the archive is not rebuilt; all files are kept in the extraction directory (which is available by default).
Overwrite all files without prompting
If the directory from which you extracted the files already contains files with the same name, you will be upgraded for each such file. You can force overwrite all files with the -o
option.
This is a dangerous option, so use it carefully.
unzip -o -d target_directory zip_file
The -o
command argument specifies that existing files will be overwritten without prompting.
Do not overwrite any files
If you don’t want any existing files to be overwritten by newly extracted files, use the -n
option (meaning never overwrite).
unzip -n -d target_directory zip_file
-a
: make unzip auto-convert text files by default.-L
: allows it to convert filenames from uppercase to lowercase.-C
: make it match case-insensitive names.-q
: make it quieter.-o
: always overwrite.-n
: never overwrite files while extracting them.