You are here

How can I compress a whole directory under a Linux / UNIX using a shell prompt?

It is very easy to compress a Whole Linux/UNIX directory. It is useful to backup files, email all files, or even to send software you have created to friends. Technically, it is called as a compressed archive. GNU tar command is best for this work. It can be use on remote Linux or UNIX server. It does two things for you:

=> Create the archive

=> Compress the archive

You need to use the tar command as follows (syntax of tar command):
tar -zcvf archive-name.tar.gz directory-name
Where,

  • -z : Compress archive using gzip program
  • -c: Create archive
  • -v: Verbose i.e display progress while creating archive
  • -f: Archive File name

For example, say you have a directory called /home/jerry/prog and you would like to compress this directory then you can type tar command as follows:
$ tar -zcvf prog-1-jan-2005.tar.gz /home/jerry/prog
Above command will create an archive file called prog-1-jan-2005.tar.gz in current directory. If you wish to restore your archive then you need to use the following command (it will extract all files in current directory):
$ tar -zxvf prog-1-jan-2005.tar.gz
Where,

  • -x: Extract files

If you wish to extract files in particular directory, for example in /tmp then you need to use the following command:
$ tar -zxvf prog-1-jan-2005.tar.gz -C /tmp
$ cd /tmp
$ ls -

A note about non gnu/tar command

The above syntax use GNU tar command for compressing and uncompressing tar files. If your system does not use GNU tar, you can still create a compressed tar file, via the following syntax:
tar -cvf - file1 file2 dir3 | gzip > archive.tar.gz

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.
Joycelyn (not verified) - Mon, 02/05/2018 - 09:52

slot online

slot game

online gambling sites for real money

slot game

pogo casino slots

Edgar (not verified) - Thu, 03/29/2018 - 02:34

online gambling casino

online casino

online casino slots

slot game

online casino games

Alvaro (not verified) - Sun, 01/07/2018 - 23:08

cheap viagra alternative

generic viagra

viagra for sale with no prescription

Hector (not verified) - Fri, 12/15/2017 - 11:02

buy cialis dubai

buy cialis online

cialis cheap prices

Veronique (not verified) - Fri, 12/15/2017 - 16:19

order cialis paypal

generic cialis

cialis pills sale

Gwendolyn (not verified) - Fri, 12/29/2017 - 22:19

where to buy cheap viagra

viagra generique

cheap viagra canada pharmacy

Moises (not verified) - Sat, 12/30/2017 - 07:51

profile buy cheap viagra

viagra generic

viagra online order india

Cierra (not verified) - Tue, 01/02/2018 - 07:40

buy viagra boots

generic viagra india

viagra cheap online no prescription

Clarita (not verified) - Thu, 01/04/2018 - 23:59

viagra online order india

cheap generic viagra

viagra cheap shipping

Tammy (not verified) - Mon, 01/01/2018 - 15:29

viagra pills for sale

viagra generique

cheap viagra pharmacy

Poppy (not verified) - Tue, 01/02/2018 - 18:58

online casino visa electron

casino

best online casino bonuses for us players

Mae (not verified) - Mon, 01/08/2018 - 05:24

viagra cheap pills

viagra generic

viagra online generic cheap

Chi (not verified) - Thu, 01/11/2018 - 18:40

autocad 2011 lt download

autodesc

buy autocad lt 2017

Roseanna (not verified) - Thu, 01/11/2018 - 18:31

autocad software cost in india

auto cad

autocad 2012 for sale

Aurelio (not verified) - Mon, 02/12/2018 - 02:17

cialis 20mg pills sale
generic tadalafil
buy cialis tijuana

Roseanna (not verified) - Thu, 12/14/2017 - 17:40

cheapest price generic cialis

cialis

cheap cialis and levitra

Cameron (not verified) - Fri, 12/15/2017 - 05:03

order cialis online prescription

buy cialis online

lilly cialis pills

Rhoda (not verified) - Wed, 12/27/2017 - 07:28

order viagra in south africa

viagra generique

cheapviagratablets.com

Raymon (not verified) - Mon, 01/01/2018 - 07:28

online casinos usa allowed

casino real money

mobile casinos us players

Lavonne (not verified) - Wed, 01/03/2018 - 20:07

how to order viagra+singapore

viagra generic 100mg

order viagra online legal

Wayne (not verified) - Thu, 01/04/2018 - 10:12

order viagra australia

generic viagra reviews

can you buy viagra over the counter

Jay (not verified) - Mon, 01/01/2018 - 02:13

online gambling the netherlands

casino online

casino game software download

Patsy (not verified) - Mon, 01/01/2018 - 21:03

cheap viagra safe

generic viagra online

cheap generic viagra overnight delivery

Pages