I’m trying to compress a directory into a .zip file on a Linux system, but I find the zip -h help output a bit confusing. I just want a simple command to create a zip archive from a folder without having to deal with too many options.
For example, if I have a directory called my_folder, how can I easily make my_folder.zip from it using the terminal?
What’s the recommended approach to create zip file linux that’s straightforward and works recursively for all files and subdirectories inside the folder?
Any examples or tips would be really helpful.
The simplest and most reliable way I use is the recursive -r flag, which ensures all files and subdirectories are included:
zip -r my_folder.zip my_folder
This will take the my_folder directory and create a my_folder.zip archive containing everything inside it. Super straightforward and works in almost all Linux distros.
Sometimes I only want to zip the folder but skip certain files like temporary files or logs. You can do this with the -x flag:
zip -r my_folder.zip my_folder -x "*.log" "*.tmp"
This will create the zip archive but ignore files ending with .log or .tmp. I found this handy when packaging projects for deployment without including unnecessary files.
On some systems, I prefer using tar with gzip compression because it feels more flexible for large directories:
tar -czvf my_folder.tar.gz my_folder
This creates a compressed archive my_folder.tar.gz containing the folder recursively. Later, it’s easy to unzip with:
tar -xzvf my_folder.tar.gz
While it’s technically not a .zip file, for Linux workflows it often works just as well and can be faster for very large directories.
Tip: Always double-check the archive contents with unzip -l my_folder.zip or tar -tzvf my_folder.tar.gz to make sure all files are included as expected.