How To Zip All Files In A Folder In Linux

Whether you’re archiving your files or compressing them to save space, knowing how to zip files in a folder is a useful skill when working in a Linux environment. In this blog post, we will walk you through the process of zipping all files in a folder using the Linux command line.

Prerequisites

You should have a running Linux system and basic knowledge of Linux commands. The command to zip files is not always installed by default on certain Linux distributions. To ensure it is installed, you can do so by using the following command:

sudo apt-get install zip

Zipping the Files

To zip all files within a folder, navigate to the directory that contains the files you want to compress. Once you’re inside the directory, use the following command:

zip -r compressed_filename.zip .

Let’s break this command down:

  • zip: This is the command that initiates the compression process.
  • -r: This option allows the zip command to travel the directory structure recursively. If there are subdirectories within the folder you’re zipping, this option ensures that those files get included.
  • compressed_filename.zip: Replace this with whatever you’d like to name your zipped file. Ensure it ends with the .zip extension.
  • .: This represents your current directory. If you want to compress files in a different directory, replace this with the path to that directory.

Unzipping the Files

In case you need to unzip the file at a later date, you can use the following command:

unzip compressed_filename.zip

Replace compressed_filename.zip with the name of the file you want to unzip.

Conclusion

Zipping files in Linux is a straightforward process once you get the hang of it. The zip command, coupled with the -r option, makes compressing an entire directory of files a breeze. Whether you’re trying to save space, streamline file transfer, or archive your files, zipping is an invaluable tool in your Linux toolkit.