Friday, 14 October 2016

How do I Compress a Whole Linux/UNIX Folder



This is task that you will do many times when working with Linux/UNIX. This can be automated or done just as a simple one time task.

Best tool for this job is tar 
  • GNU tar  saves many files together into a single tape or disk archive, and can
    restore individual files from the archive.
GNU tar comes with many options but for my task i will use the following options only:
Shell

tar -zcvf wwww_QTS_bkp.tar.gz www/
  • this command will create gziped archive containing the entire content of the www/ folder called www_QTS_bkp.tar.gz.
Options  used and their purpose:
  • -z Compress archive using the gzip program
  • -c  Create archive
  • -v  Verbose i.e display progress while creating archive
  • -f  Archive File name
To extract the content of a tar archive use the following command:
  • -C Extract location
  • -x Extract the content
Shell

tar -zxvf wwww_QTS_bkp.tar.gz
  • this will extract to the current working directory.
Shell

tar -zxvf wwww_QTS_bkp.tar.gz -C /folder
  • this will extract the content into /folder directory.
GNU tar come very handy to be used on a daily basis by any system admin.
Hops this was helpful

No comments: