Skip to main content

How do I Compress a Whole Linux or UNIX Directory?

highlighted text

Originaly posted by Vivek Gite on www.cyberciti.biz

February 11, 2006 last updated September 11, 2015

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.
Hung (not verified) - Thu, 03/29/2018 - 03:07

play casino games online

casino games

casino games slots

slot online

online casino games

Tam (not verified) - Thu, 03/29/2018 - 06:56

casino games real money

casinos online

kasino

kasino

online casino slots

Margart (not verified) - Fri, 02/09/2018 - 13:32

slot online

vegas casino games

new usa online casinos 2017

kasino

online gambling casino

Lidia (not verified) - Thu, 03/29/2018 - 04:05

slot game

kasino

play casino games online

casino slots

casino games real money

Pages

Aliaksandr Yakauleu,
2010-2019

How do I Compress a Whole Linux or UNIX Directory? | Mynet.su

Error

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /home/mynet/web/mynet.su/mynet.su/webroot/includes/common.inc:2755) in drupal_send_headers() (line 1232 of /home/mynet/web/mynet.su/mynet.su/webroot/includes/bootstrap.inc).
  • PDOException: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away: INSERT INTO {watchdog} (uid, type, message, variables, severity, link, location, referer, hostname, timestamp) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9); Array ( [:db_insert_placeholder_0] => 0 [:db_insert_placeholder_1] => cron [:db_insert_placeholder_2] => %type: !message in %function (line %line of %file). [:db_insert_placeholder_3] => a:6:{s:5:"%type";s:12:"PDOException";s:8:"!message";s:238:"SQLSTATE[HY000]: General error: 2006 MySQL server has gone away: SELECT 1 AS expression FROM {variable} variable WHERE ( (name = :db_condition_placeholder_0) ); Array ( [:db_condition_placeholder_0] =&gt; drupal_http_request_fails ) ";s:9:"%function";s:14:"variable_set()";s:5:"%file";s:64:"/home/mynet/web/mynet.su/mynet.su/webroot/includes/bootstrap.inc";s:5:"%line";i:991;s:14:"severity_level";i:3;} [:db_insert_placeholder_4] => 3 [:db_insert_placeholder_5] => [:db_insert_placeholder_6] => http://mynet.su/blog/how-do-i-compress-whole-linux-or-unix-directory?page=2 [:db_insert_placeholder_7] => [:db_insert_placeholder_8] => 104.236.211.176 [:db_insert_placeholder_9] => 1575636993 ) in dblog_watchdog() (line 163 of /home/mynet/web/mynet.su/mynet.su/webroot/modules/dblog/dblog.module).
The website encountered an unexpected error. Please try again later.