🖥️zip

➡️This is a command-line reference manual for commands and command combinations that you don’t use often enough to remember it. This cheatsheet explains the zip command with important options and switches using examples.

▁ ▂ ▃ ▄ ꧁ 🔴☠ COMMANDLINE-KUNGFU WITH CHEATSHEETS ☠🔴꧂▅ ▃ ▂ ▁

#                ███████╗██╗██████╗ 
#                ╚══███╔╝██║██╔══██╗
#                  ███╔╝ ██║██████╔╝
#                 ███╔╝  ██║██╔═══╝ 
#                ███████╗██║██║     
#                ╚══════╝╚═╝╚═╝     
                                   
                                  

# Create zip file
zip archive.zip file1 directory/

# To list, test and extract zip archives, see unzip
cheat unzip

# Bash command to zip some content - This command will zip the file file.txt and all the sh files contained in setup folder in a zip named myzip.zip.
# Then adds the file Third/otherfile.txt in then same archive with the last command               
ZIP_NAME="myzip.zip"
zip "$SETUP_ZIP_DIR"/$ZIP_NAME setup/*.sh file.txt
zip -g "$SETUP_ZIP_DIR"/$ZIP_NAME Third/otherfile.txt

# Recreate or update an existing zip file and remove files that do not exist anymore
zip --filesync -r /path/to/out.zip /path/to/dir

# Explanation: zip does not have an explicit option to overwrite/recreate an existing zip file. If the specified destination file already exists, zip updates it. The problem is that files you did not specify to add to the zip but they already existed in the zip, will not be removed.

# For example let's say you created a zip file from a directory with the command:
zip -r /path/to/out.zip /path/to/dir

# Next you delete some files from the directory and repeat the command to recreate the zip. But that will not recreate the zip, it will only update it, and so the file you deleted from the directory will still be there in the zip.

# One way to recreate the zip is to delete the file first. Another, better way is to use the --filesync or -FS flag. With this flag zip will remove files from the zip that do not exist anymore in the filesystem. This is more efficient than recreating the zip.

# zip-dir -  zip directories
# Zip all top level directories
for i in */; do if [ ! -f "${i%/}.zip" ]; then zip -r "${i%/}.zip" "$i"; fi done

#==============================##==============================#
# CMD ZIP						       #
#==============================##==============================#
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

  █║▌│║█║▌★ KALI ★ PARROT ★ DEBIAN 🔴 PENTESTING ★ HACKING ★ █║▌│║█║▌

              ██╗ ██╗ ██████╗  ██████╗ ██╗  ██╗███████╗██████╗
             ████████╗██╔══██╗██╔═══██╗╚██╗██╔╝██╔════╝██╔══██╗
             ╚██╔═██╔╝██║  ██║██║   ██║ ╚███╔╝ █████╗  ██║  ██║
             ████████╗██║  ██║██║   ██║ ██╔██╗ ██╔══╝  ██║  ██║
             ╚██╔═██╔╝██████╔╝╚██████╔╝██╔╝ ██╗███████╗██████╔╝
              ╚═╝ ╚═╝ ╚═════╝  ╚═════╝ ╚═╝  ╚═╝╚══════╝╚═════╝

               █║▌│║█║▌ WITH COMMANDLINE-KUNGFU POWER █║▌│║█║▌

░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░