To collect a bunch of files and directories together, use tar.
For example, to tar up your entire home directory and put the tarball into /tmp, do this
$ cd ~srees
$ cd .. # go one dir above dir you want to tar
$ tar cvf /tmp/srees.backup.tar srees
By convention, use .tar as the extension. To untar this file use
$ cd /tmp
$ tar xvf srees.backup.tar
tar untars things in the current directory!
After running the untar, you will find a new directory, /tmp/srees, that is a copy of your home directory.
Note that the way you tar things up dictates the directory structure when untarred.
The fact that I mentioned srees in the tar creation means that I'll have that dir when untarred.
In contrast, the following will also make a copy of my home directory, but without having a srees root dir:
$ cd ~srees
$ tar cvf /tmp/srees.backup.tar *
It is a good idea to tar things up with a root directory so that
when you untar you don't generate a million files in the current directly.
To see what's in a tarball, use
$ tar tvf /tmp/srees.backup.tar
Most of the time you can save space by using the z argument.
The tarball will then be gzip'd and you should use file extension .tar.gz:
$ cd ~srees
$ cd .. # go one dir above dir you want to tar
$ tar cvfz /tmp/srees.backup.tar.gz srees
Unzipping requires the z argument also:
$ cd /tmp
$ tar xvfz srees.backup.tar.gz
If you have a big file to compress, use gzip:
$ gzip bigfile
After execution, your file will have been renamed bigfile.gz.
To uncompress, use
$ gzip -d bigfile.gz
To display a text file that is currently gzip'd, use zcat:
$ zcat bigfile.gz
Look in:
Friday, January 16, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment