How to Compress a Directory in Linux

Compressing a directory and all of its contents is an east task in linux. The linux command line allows easy compressing and uncompressing of files and whole directories. It actually only takes a single linux command to compress a directory and all of its contents.

What linux actually does is it first creates an archive of all the files and then it compresses those file.

To compress a directory in linux (or unix) use the following 'tar' command:

tar -zcvf ARCHIVE.tar.gz DIRECTORY

Where ARCHIVE.tar.gz is the name of the compressed archive you are creating (the new file). and DIRECTORY is the location of the directory you are compressing. Once compressed this archive file can then be moved around, sent to different computers or used as a backup file.

Uncompressing a tar.gz archive is just as easy. Again, using the 'tar' commmand you uncompress files by typing:

tar -zxvf ARCHIVE.tar.gz

This linux command will uncompress all of the contents of ARCHIVE.tar.gz into the current directory.