Search blog

Saturday, March 11, 2017

How to Zip/Compress files using Terminal in Ubuntu/Linux

Use the following commands to compress your files using terminal. First, make sure you have Zip already installed in your system.

>> To install Zip: Open you terminal (CTRL+ALT+T) and enter the command below:
 sudo apt-get install zip gzip tar  

>> To Zip:
 zip -r compressed_filename.zip foldername  

where:
  • r: recursive
  • compressed_filename.zip: name of your .zip folder you want to create. Example: magento-file-sys.zip
  • folder_name: name of the folder that you want to compress
Seems to be much faster and consume almost 80%-90% less CPU processes than the one using GUI/Archive Manager.; but file size seems to be large by 10-20 MB than the one created using the menu option available in GUI/Archive Manager.

>> To Unzip:
 unzip my_arch.zip  

Zip stores relative path names by default. There are several parameter-options available for zip. For that read: the manual (man zip). For a starting this will do.

Most often you will see .tar.gz endings in linux-world. That's the product of two tools: TAR (the tape archiver) and GZIP (the GNU-Zip). Tar has got the call option to automatically gzip/gunzip files after "taring".
 tar -cvzf may_arch.tar.gz my_folder  

where:
  • -c means "create"
  • -v means "verbose" (sometimes bothersome and slowing down...)
  • -z means "use (GNU)zip"
  • -f XYZ declares the name of the output file. (You should chose a helping name like XYZ.tar.gz)
There may also be .tar.bz2 endings. This is the product of the -j parameter instead of the -z parameter: you will choose compression with BZIP2 (-> man bzip2).

To extract you simply use -x (eXtract) instead of -c (Create):
 tar -xvzf may_arch.tar.gz  

No comments:

Post a Comment

Thank you for your Feedback!
www.evagabond.me

Top 5 Posts (Weekly)