Compress a Whole Linux or UNIX Directory

system
ID: 20170620 ACCESSING DATA...
SYSTEM: ARCHIVE FILE: COMPRESS A WHOLE LINUX OR UNIX DIRECTORY STATUS: ACTIVE

Ok, that’s a simple one, but it’s always nice to have a quick syntax remainder. So, here’s the best way to compress a whole directory under Linux/UNIX using a shell prompt.

This technique is often used to backup files or to move data using a compressed archive. The GNU tar command is best for this work. This command does two things for you:

You need to use the tar command as follows:

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

With the arguments,

For example, you have directory called /home/sm2g/stuff and you would like to compress this directory then you can type tar command as follows:

tar -zcvf backup-2017.tar.gz /home/sm2g/stuff

The above command will create an archive file called backup-2017.tar.gz in current directory. Now, eventually you’ll want to restore your archive. Just use following command (it will extract all files in current directory):

tar -zxvf backup-2017.tar.gz

With,

If you wish to extract files in particular directory, for example in /tmp then you need to use following command:

tar -zxvf backup-2017.tar.gz -C /tmp
cd /tmp
ls -lhart

Tags: