linux

How to compress a linux or unix directory?

Compressing a linux/unix directory is very easy. This is useful if you wish to compress your linux folder to save space, to send file, to email or to create a backup of an existing site. This command can be done on a console on a linux or unix box.

To compress a Linux/Unix directory, we will use a GNU tar command. This will create and compress the archive.

The syntax of a tar command works in this way:

tar -zvcf name-of-archived.tar.gz directory-name

where,

  • -z : uses GZIP program to compress the archive
  • -v: display progress on screen while compressing the archive
  • -c: creates the archive
  • -f: archive filename

Let’s take for example that you wish to compress the directory under the /home/ebugger/pictures , you can then type the tar command below:

tar -zvcf pictures.tar.gz /home/ebugger/pictures

The command above will create an archive in the current directory, if you wish to restore the files, it will then extract the files in the current directory as well, please take note that this may overwrite your current files so please be careful in using the command.

the command is,

tar -zvxf pictures.tar.gz

where,

  • -x: extracts the archives in the current directory

Now if you wish to extract the archive in another directory, you may use the “-C” syntax like this:

tar -zvxf pictures.tar.gz -C /tmp

where.

  • -C: extracts to a specific directory with a path

 

Leave a Reply