Compressing files and directories in Linux helps save disk space and makes file management easier. Bundling multiple files or folders into a single compressed zip archive reduces the size and allows for quicker file transfers. Zip archives are commonly used because of their efficiency and compatibility across operating systems like Windows, macOS, and Linux.
The zip utility is available in most Linux distributions, providing a straightforward way to compress files and folders. This format is widely supported, making it ideal for users who need to share files across different platforms. Using zip, users can combine multiple files into one, reducing the clutter of many individual files and simplifying backup or sharing processes.
Compressing files and folders using zip in Linux is quick and efficient. Whether you're working with individual files or entire directories, the process is the same. With a few basic commands, you can easily compress and manage your data in a flexible and organized way.
Steps to zip files and folders in Linux:
- Open the terminal.
- Navigate to the directory where the files or folders are located.
$ cd /path/to/directory/
- Enter the zip command followed by the output file name and the file or folder name to compress.
$ zip output_filename.zip file_or_folder_name adding: file_or_folder_name (deflated 63%)
Replace output_filename.zip with the desired name for your archive, and file_or_folder_name with the file or folder you wish to compress.
- To compress multiple files or folders, list them with spaces between each one.
$ zip archive.zip file1.txt file2.txt folder1/ adding: file1.txt (stored 0%) adding: file2.txt (deflated 53%) adding: folder1/ (stored 0%)
- To compress an entire directory and its contents, use the recursive option with the zip command.
$ zip -r output_foldername.zip folder_name/ adding: folder_name/file3.txt (deflated 47%) adding: folder_name/subfolder/ (stored 0%)
This will include all files and subdirectories inside folder_name in the compressed archive.
- Verify the creation of the zip archive by listing the files in the directory.
$ ls -lh total 4.0K -rw-r--r-- 1 user user 3.5K Sep 14 12:00 output_filename.zip
You should see the newly created .zip file listed among the other files.
- Optionally, check the contents of the zip archive without extracting it.
$ unzip -l output_filename.zip Archive: output_filename.zip Length Date Time Name --------- ---------- ----- ---- 1234 2024-09-14 11:59 file_or_folder_name
This command will display a list of files and directories inside the zip archive.
Mohd Shakir Zakaria is an experienced cloud architect with a strong development and open-source advocacy background. He boasts multiple certifications in AWS, Red Hat, VMware, ITIL, and Linux, underscoring his expertise in cloud architecture and system administration.
Comment anonymously. Login not required.