Some Other Tools in UNIX:Tar and Other Utilities.
Module 16: Some Other Tools in UNIX
We have emphasized throughout that the philosophy of Unix is to provide - (a) a large number of simple tools and (b) methods to combine these tools in flexible ways. This applies to file compression, archiving, and transfer tools as well. One can combine these tools in innovative ways to get efficient customized services and achieve enhanced productivity. Usually, the use of these tools is required when user or system files need to be moved enblock between different hosts.
In this module we shall discuss some tools that help in archiving and storing information efficiently. Efficient utilization of space requires that the information is stored in a compressed form. We discuss some of the facilities available in Unix for compression. Also, compressed files utilize available network bandwidth better for file transfers on the internet. Without compression, communicating postscript, graphics and images or other multimedia files would be very time consuming.
One of the interesting tools we have included here is a profiler. A profiler helps in profiling programs for their performance. In program development it is very important to determine which segments of program are using what resources. We discuss a few program performance optimization strategies as well.
We begin the module with a description of archiving tools available in the Unix environment.
16.1 Tar and Other Utilities
In the past, archives were maintained on magnetic tapes. The command tar appropriately stands for the tape archiving command for historical reasons. These tapes used to be stacked away in large archival rooms. The tar command carries over to archiving files from a file system onto a hard disk. The command has a provision for a default virtual tape drive as well.
As a user, we distribute our files within a directory structure. Now suppose we need to archive or copy an entire set of files within a directory subtree to another machine. In this situation the tar command comes in handy. It would also be very handy when one has to copy a large set of system files to another machine. Many of the newer applications are also installed using a copy from a set of archived files. The tar command has the following structure:
tar options target source
As an example suppose we wish to archive all the .c files under directory. /M/RAND and place these under directory. /T, we may give a command as follows:
bhatt@SE-0 [~/UPE] >>tar cvf ./T/cfiles.tar ./M/RAND/*.c a ./M/RAND/dum.c 1K
a ./M/RAND/main.c 1K
a ./M/RAND/old_unif.c 1K a ./M/RAND/templet.c 4K a ./M/RAND/unif.c 1K
We may now change to the directory T and give a ls command to see what we have there.
bhatt@SE-0 [T] >>ls ReadMe cfiles.tar
The options used in tar command have the following interpretations:
The option c suggests to create, v suggests to give a verbose description on what goes on, and f indicates that we wish a file to be created in a file system. An absence of f means it will be created in /etc/remt0 = or a tape. To see the table of contents within a tarred file use the t option as shown below:
bhatt@SE-0 [T] >>tar tvf cfiles.tar tar: blocksize = 18
-rw-r--r-- 10400/14210 414 Nov 30 15:53 1999 ./M/RAND/dum.c
-rw-r--r-- 10400/14210 364 Nov 30 16:38 1999 ./M/RAND/main.c
-rw-r--r-- 10400/14210 396 Nov 30 16:29 1999 ./M/RAND/old_unif.c
-rw-r--r-- 10400/14210 3583 Nov 29 11:22 1999 ./M/RAND/templet.c
-rw-r--r-- 10400/14210 389 Oct 16 09:53 2000 ./M/RAND/unif.c
To extract the files from the tarred set cfiles, we may use the x option as follows:
tar xvf cfiles.tar
This creates a directory M under T (M was the parent directory of RAND) under which RAND and files stood in the first place.
In particular, tar has the following options:
c: create an archive.
r: append files at the rear end of an existing archive.
t: list table of contents.
x : extract individual contents
f : file to be created within a file system
f : write/read from standard output/input o : change file ownership
v : verbose mode, give details of archive information
Note that it is dangerous to tar the destination directory (i.e. take the archive of the destination directory) where we propose to locate the .tar file as this results in a recursive call. It begins to fill the file system disk which is clearly an error.
The tar command is very useful in taking back-ups. It is also useful when people move - they can tar their files for porting between hosts.
Comments
Post a Comment