zip/unzip

What is "zip" and "unzip"

zip (in linux) is a command-line utility that is used to compress files, the opposite of zip is unzip. Unzip is used to decompress zip files to their original state.

How to use zip

  • zip is used to compress multiple files

  • unzip is used to decompress those files

# zip syntax, options are optional
zip <OPTIONS> <TOBEMADEZIPFILE> <FILE1> <FIL2>

##### examples with zip, and parameters
zip -e <toBeMadeZipFile> <FILE1> <FIL2> # encrypt the files
zip -u <toBeMadeZipFile> <FILE1> <FIL2> # update only changed or new files
zip -9 <toBeMadeZipFile> <FILE1> <FIL2> # compress better
zip -q <toBeMadeZipFile> <FILE1> <FIL2> # no output will be generated in the terminal

zip --help # shows all other options zip has to offer.

# unzip syntax, options are optional
unzip <options> <zipefile>

##### examples with unzip, and parameters
unzip -q <zipfile> # decompress without any output generated in the terminal
unzip -o <zipfile> # overwrite files without prompting
unzip -n <zipfile> # never overwrite existing files.ls

zip and unzip examples

# Compress with zip
root@Corrosie:~/test/test# ls
hello.jpeg  test1.txt  test3.txt
root@Corrosie:~/test/test# zip test test1.txt test3.txt hello.jpeg 
  adding: test1.txt (stored 0%)
  adding: test3.txt (stored 0%)
  adding: hello.jpeg (stored 0%)
root@Corrosie:~/python3/test# ls
hello.jpeg  test1.txt  test3.txt  test.zip
root@Corrosie:~/test/test# 

# Decompress with unzip
root@Corrosie:~/test/test# rm -rf test1.txt hello.jpeg test3.txt 
root@Corrosie:~/test/test# ls
test.zip
root@Corrosie:~/test/test# unzip test.zip 
Archive:  test.zip
  inflating: test1.txt               
 extracting: test3.txt              
 extracting: hello.jpeg                
root@Corrosie:~/test/test# ls
hello.jpeg  test1.txt  test3.txt  test.zip

Last updated