How do I Compress a Whole Folder Linux?

How can I compress a whole directory under a Linux command prompt?

You will be using tar command to compress a folder in linux:

tar -zcvf archive-name.tar.gz your-directory-name

Where,

  • -z : Compress archive using gzip program
  • -c: Create archive
  • -v: Verbose i.e display progress while creating archive
  • -f: Archive File name

For example, you have a direcotrey called mysite.com in /var/www/html, the code would be $ tar -zcvf mysite.com.tar.gz /var/www/html/mysite.com

Editorial Staff
 

Editorial Staff at tutsplanet is a dedicated team to write various tutorial articles.