Professional Documents
Culture Documents
1
Archiving with tar tar Practice
Start by moving into your UNIX_class
Creating a tarfile subdirectory.
$ ls –l
Suppose we want to archive a drwxrwxr-x 2 userid userid 512 Jun 28 17:52 Animal
directory. Let’s take dir2 from our drwxrwxr-x
drwxrwxr-x
2
2
userid
userid
userid
userid
512
512
Jun
Jun
18
18
21:31
20:10
Shakespeare
Wildcards
UNIX_class examples. drwxrwxr-x 2 userid userid 512 Jun 24 15:38 dir1
drwxrwxr-x 4 userid userid 512 Jun 24 13:55 dir2
It is always a good idea to verify the drwxrwxr-x 4 userid userid 512 Jun 28 15:19 dir3
2
Archiving with tar Archiving with tar
What we did here is create a tarfile called $ tar –cvf filename.tar directoryname
dir2.tar which is a file archive of all the
files and directories under dir2. The options:
-c tells tar to “create”
Lets look at tar more closely. There
are many options and different ways to
use the command, but we will focus on
the ones you will use most often.
3
Archiving with tar Archiving with tar
tar –cvf /home/jsmith/tarfiles/dir2.tar dir2 tar –cvf /home/jsmith/tarfiles/dir2.tar dir2
pathname tarfile |
tar –cvf ~/tarfiles/dir2.tar dir2
original
Remember that the “tarfiles” directory has to already exist directory
4
Extracting with tar Extracting with tar
Make sure you are in your home Type:
directory (not in UNIX_class).
$ tar –xvf UNIX_class/dir2.tar
$ pwd (always a good habit to get into)
-x option means to extract.
5
Compressing and Uncompressing
Compressing reduces the file size
Compressing and using a special encoding.
Uncompressing Tarring files and compressing often go
hand in hand.
You can compress a whole tarfile
without having to compress each
individual file.
6
Compressing and Uncompressing Compressing Practice
Let’s find our previous tarfile
(dir2.tar) that should reside at the
Using gzip to compress a file. top of your UNIX_class directory and
try this handy utility.
$ cd UNIX_class
$ ls -l
7
Compressing and Uncompressing Compressing and Uncompressing
Notice the file size difference between
the unzipped file and the zipped one.
Using gunzip to uncompress a file.
before:
-rw-rw-r-- 1 userid userid 49664 Ju1 8 16:28 dir2.tar
after:
-rw-rw-r-- 1 userid userid 29601 Ju1 8 16:28 dir2.tar.gz