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 skilled programmer with expertise in Vue.js/Nux.js for front-end development and PHP Laravel for back-end development. I excel in building APIs and services, and also have experience in web server setup & maintenance. My versatile skill set allows you to develop and maintain web applications effectively, from the user interface to the server-side functionality. I love coding with never ending learning attitude, thanks for visiting