|
CSC128 : Introduction to UNIX
Using tar
The tar Utility
tar
Manages archives of files.
tar -cvf filename.tar files...
This will create a tar file named filename.tar
that contains all the files listed (files...
).
tar -xvf filename.tar
This will extract the files in filename.tar
gzip
Compresses and decompresses single files.
gzip filename
This will compress the file called filename
into a file called
filename.gz
gzip -d filename.gz
gunzip filename.gz
Each of these commands will decompress the file called
filename.gz
into a file called filename
tar and gzip together
tar and
gzip
are often used in combination. First, a series of files (often
a whole directory tree) is tar
'ed, and then that tar
file is
gzipped, to take up
less space.
user@machine:~ $ tar -cvf archive.tar ~user/mydir/
user@machine:~ $ gzip archive.tar
user@machine:~ $ ls
archive.tar.gz mydir
user@machine:~ $
|
These can be combined with pipes to perform the archiving and compression
in one step:
tar -cvf - files | gzip > archive.tar.gz
Some newer versions of tar
have a -z
option, that will perform the gzip compression for you:
tar -czvf archive.tar.gz files
And to decompress:
gzip -dc archive.tar.gz | tar -xvf -
Or, with the newer versions of tar
:
tar -xzvf archive.tar.gz
dump
Selectively backs up the filesystem (usually to a dumpfile).
restore
Restores a filesystem from a backup (usually a dumpfile).
uniq
Removes duplicate lines:
user@machine:~ $ cat names.txt
David
Angie
John
David
Catherine
Suzanne
user@machine:~ $ sort names.txt
Angie
Catherine
David
David
John
Suzanne
user@machine:~ $ sort names.txt | uniq
Angie
Catherine
David
John
Suzanne
user@machine:~ $
|
wc
Displays on stdout the number of lines, words, and characters in files
.
user@machine:~ $ wc poem
537 5832 31416 poem
user@machine:~ $
|
|