How to uncompress a file on mac/Linux using Terminal

1. Uncompress a Zip File:

i. Extract in the same dir:

Here is the command in case you want to extract in the present directory


unzip <source_file_path>.zip 



ii. unzip Password Protected File:

if there a password you can also use -P not -p it’s a different option


unzip -P <password> <sorce_file_path>.zip 


unzip -P 123456

iii. Extract to a particular destination folder

if you want to extract to a particular destination folder, you can use


unzip <sorce_file_path>.zip -d <destination_path>


unzip -d /User/admin/Desktop

And if there a password you can also use -P .

If the unzip package isn’t already installed on your system, then run:

sudo apt-get install unzip

2. Uncompress a tar File:

To extract a simple archive of using tar, the syntax is

$ tar -xvf output.tar /path/input

here, -x will extract an archive,

-v, will enable verbose mode & will show the progress,

-f, allows us to name the archive


3. Uncompress a GZip File:

To extract a compressed archive with tar, the syntax will be

$ tar -zxvf input.tar.gz /path/output

here, -z option used with the above mentioned command will help us extract a Gzip compression based archive.

4. Uncompress a Bzip2 File:

Now for some reason, if we want to extract an archive that used Bzip2 as the compression method, then we can use the following syntax to extract a compressed archive

$ tar -jxvf input.tgz2 /path/output

Here, -j option will extract a Bzip2 based tar archive.