Linux / Unix

Linux: Compress or uncompress files

How do I compress a linux or unix folder?

It’s quite simple to compress whole directory in linux/unix, most possible and useful actions would be:

  • Compress folder (archive)
  • Listing files from archive
  • updated compress

Compress a folder

Run following command to compress a folder.

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

Where -zcvf

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

Let’s suppose you need to archive a folder, you will run following command

tar -zcvf images-01jan2019.tar.gz /home/USER/images

Above command will compressed images in current folder with given name. Now if you need to extract archive run following command.

Uncompress archive

tar -zxvf images-01jan2019.tar.gz

Where -x: Extract files from the archive

But if you want to extract archive in specific folder run following command.

tar -zxvf images-01jan2019.tar.gz -C /static/restore

Compress multiple folders in same archive

tar -zcvf compressed-folders.tar.gz /path/to/folder1/ /path/to/folder2/
Author: Danyal
I'm a skilled programmer specializing in Vue.js/Nuxt.js for front-end development and PHP Laravel for back-end solutions. I have a strong focus on API design and development, complemented by experience in web server setup and maintenance. My versatile expertise ensures seamless creation and maintenance of web applications, covering everything from intuitive user interfaces to robust server-side functionality. Passionate about coding and driven by a lifelong learning mindset, I invite you to explore more at danyal.dk.