How to Create and Extract Zip Files to Specific Directory in Linux

[‘

n

In one of our several articles about the tar command, we showed you how to extract tar files to a specific or different directory in Linux. This short guide explains to you how to extract/unzip .zip archive files to a specific or different directory in Linux.

n

Zip is a simple, cross-platform file packaging and compression utility for Unix-like systems including Linux and Windows OS; plus many other operating systems. The “zip” format is a common archiving file format used on Windows PC’s and most importantly, it enables you to specify the compression level between 1 and 9 as an option.

n

Read Also: 5 Best Command Line Archive Tools for Linux

n

Create Zip Archive File in Linux

n

To create a .zip (packaged and compressed) file from the command line, you can run a similar command like the one below, The -r flag enables recursive reading of files directory structure.

n

$ zip -r tecmint_files.zip tecmint_files rn

n

Create Zip File in Linux
Create Zip File in Linux

n

To unzip the tecmint_files.zip archive file you have just created above, you can run the unzip command as follows.

n

$ unzip tecmint_files.ziprn

n

The above command will extract the files into the current working directory. What if you want to send the unzipped files into a specific or different directory – you can learn this in the next section.

n

Extract Zip File to Specific or Different Directory

n

To extract/unzip .zip archive files to specific or different directory from the command line, include the -d unzip command flag as shown below. We will use the same example above to demonstrate this.

n

This will extract the .zip file content into the /tmp directory:

n

$ mkdir -p /tmp/unzipedrn$ unzip tecmint_files.zip -d /tmp/unzipedrn$ ls -l /tmp/unziped/rn

n

Extract Zip Files to Specific Directory
Extract Zip Files to Specific Directory

n

For more usage information, read zip and unzip command man pages.

n

$ man ziprn$ man unzip rn

n

You may also like to read the following related articles.

n

    n

  1. How to Archive/Compress Files & Directories in Linux
  2. n

  3. How to Open, Extract and Create RAR Files in Linux
  4. n

  5. Peazip – A Portable File Manager and Archive Tool for Linux
  6. n

  7. Dtrx – An Intelligent Archive Extraction (tar, zip, cpio, rpm, deb, rar) Tool for Linux
  8. n

n

In this short article, we have explained how to extract/unzip .zip archive files to a specific or different directory in Linux. You can add your thoughts to this article via the feedback form below.

n

‘]