How to zip and unzip files in Linux

Опубликовано: 22 Февраль 2025
на канале: LinuxHowTo
953
3

---ZIP---

1) install zip and unzip
#sudo apt install zip unzip

2) compressing
#zip myfiles.zip filespath
or
#zip myfiles.zip file1 file2 file3

3) To list files on zip
#unzip -l myfiles.zip
or
#less myfiles.zip

4) compress recursively (use -r option)
#zip -r myfiles.zip filespath

5) secure zip with password (use -e option)
#zip -e myfiles.zip filespath
//recursively and with password
#zip -re myfiles.zip filespath

6) include only specified files (use -i option)
#zip myfiles.zip filespath -i file1 file2 file3
//with wildcard expressions (pattern)
#zip myfiles.zip filespath -i \*.txt
will only compress all the files that end with ".txt"
//recursively
#zip -r myfiles.zip filespath -i \*.txt

7) exclude files (use -x option)
#zip myfiles.zip filespath -x file1 file2 file3


8) delete files (use -d option)
#zip myfiles.zip filespath -d file1 file2 file3
#zip myfiles.zip -d "New Folder/*"
delete the folder with all its content

9) add files
just compess as normal
#zip myfiles.zip file1 file2 file3
it will append files to myfiles.zip


---UNZIP---

#unzip myfiles.zip
to extract zip file in the current directory

#unzip myfiles.zip file1 file2
to extract just file1 and file2

#unzip myfiles.zip -x file1 file2
-x option to exclude files from extraction

#unzip myfiles -d directoryName
-d option to specify extraction directory