Using Linux:System Maintenance
-->
Previous
Table of Contents
Next
This command creates (-c) an archive file (f tarfile.tar) containing all the listed files. The file(s) argument can be a directory in a directory tree; tar archives everything beneath that directory (inclusive), maintaining all the directory relationships, including links, permissions, ownership information, and date stamps. To tell tar exactly what type of archiving job to perform, specify one function as the first argument on the command line (see Table 31.1 for a list of tars major function identifiers).
TABLE 31.2 tars major function identifiers
Function Identifier
Mnenomic
Action
c
create
Instructs tar to make a new archive, putting the listed files and directories in the tar file you designate
x
extract
Instructs tar to recreate a set of original files (and directories) using the specified tar archive file
t
list
Generates a list of the listed files that are stored in the tar file (if no files are listed on the command line, lists all files in tar)
u
update
Updates an existing tar file with the files listed if they are not currently contained in the tar file, or have more recent modification times (m times) than the file(s) already contained in the tar file
r
append
Adds listed files to the end of an existing tar archive file
In addition to using functions to designate the major action it will perform, tar accepts dozens of additional options. Listed here are some of the ones most often used:
f filename
Designates tar filename
k
Keeps old files (doesnt overwrite with files being extracted)
v
Verbose (provides information while running)
z
Archives/extracts by using gzip compression/decompression
M
Multivolume (indicates an archive that can use several floppy disks or tapes)
V
Volume name (stored in tar file for reference)
Using tar to Archive Directories
tar can archive an entire directory if you use a directory name on the command line:
#pwd
/public/sharedfiles/me
#ls -l
total 27
rwxrwxrx 1 me users 22843 Apr 1 20:40
README.txt
rwxrwxrx 1 me me 1519 Mar 15 21:29
iousage
drwxrwxrx 2 me users 1024 Jun 8 1996
fileshare
lrwxrwxrx 2 me users 8 Dec 12 20:39
thtfil -> thisfile
# tar cf share.tar /public/sharedfiles/me
tar: removing leading / from absolute pathnames in the archive
#ls -l
total 28
rwxrwxrx 1 me users 22843 Apr 1 20:40
README.txt
rwxrwxrx 1 me me 1519 Mar 15 21:29
iousage
drwxrwxrx 2 me users 1024 Jun 8 1996
fileshare
rwxrwxrx 1 me users 46058 Apr 1 20:40
share.tar
lrwxrwxrx 2 me users 8 Dec 12 20:39
thtfil -> thisfile
tar uses relative pathnames; it creates an archive of the me directory in the preceding code without referring to the root pathname (the first slash). (Thats what the tar: ... system message means.) You can place archived directories in other directories without worrying about the archives original pathnames and parent directories.
You can think of tar as a way to graft a directory branch to another directory tree; you can use one tar file to move an entire set of directories and subdirectories from place to place on your system, or from system to system (many ftp files are tar files).
Moving and Extracting tar Files
After you create a tar file, anyone with read and write permissions for the directory containing the file (such as the user notme) needs to add the me directory that was archived earlier to his or her home directory:
#pwd
/home/notme
#ls -l
total 53
rwrwr 1 notme users 8432 Apr 1 20:40
zipcode.c
rwrwr 1 notme users 21519 Mar 14 21:29
stadd.o
drwxrwxrx 2 notme users 1024 Dec 4 20:39
docfiles
drwxr-xr 1 notme users 1024 Jan 11 1996
perlscripts
drwr---r 2 notme users 1024 Mar 14 21:29
progfiles
#cp /public/sharedfiles/me/share.tar .
#tar xvf share.tar
public/sharedfiles/me/README.txt
public/sharedfiles/me/iousage
...
#ls -l
total 80
rwrwr---- 1 notme users 8432 Apr 1 20:40
zipcode.c
rwrwr---- 1 notme users 21519 Mar 14 21:29
stadd.o
drwxrwxrx 2 notme users 1024 Dec 4 20:39
docfiles
drwxr-xr---- 1 notme users 1024 Jan 11 1996
perlscripts
drwr---r---- 2 notme users 1024 Mar 14 21:29
progfiles
drwxrwxrwx 2 notme users 1024 Apr 1 1996 public
#ls -l public
drwxrwxr-x 2 notme users 1024 Aug 17 08:42 me
Because the user notme ran the tar extraction command, the extracted directory public (and its subdirectories) are now owned by notme rather than me. The v (verbose) option in the last example provides a listing of relative pathnames for each file tar processes (abbreviated for space). Increasing the number of v options listed increases the amount of information tar provides (vv lists date stamps and sizes as well as pathnames, like the ls -l command).
Previous
Table of Contents
Next
Wyszukiwarka
Podobne podstrony:
548 550548 03 2012 NORD 10002 (548)548,8,artykul544 (2)548 (2)539 544542 544544,24,artykul541 54403 (548)BC549,548,550,547,546README (544)więcej podobnych podstron