How to archive files and folders in Linux



In order to archive files and folders in linux shell using “tar” you can use the following commands:

 tar   -cvzf  example.tgz   *


which will add all files from current directory to archive called  example.tgz or you can do:


tar -czvf archive.tar.gz /example/for/directory

and this will add the folder /example/for/directory to archive called  archive.tar.gz. The meaning of the directives in both cases is:


-c — create a new archive

-f — specifies the filename used to tar into or from

-v — show the progress of the files being archived

-z — compress the tar file with gzip


Now in order to extract data from archive you will need to use an additional directive “x” instead of “c”:

x --- extract (restore) the contents of the tar file.

Here is an example:

tar -xzvf filename.tgz

which will extract files from filename.tgz  archive.

Was this article helpful?
0 out of 0 found this helpful

Have more questions? Contact our support instantly via Live Chat