548 550




Using Linux:System Maintenance






-->















Previous
Table of Contents
Next




Compressing Archive Files with tar

tar can also serve double duty as an archive compression/expansion utility. When used with the z option, tar gzips (or gunzips) the tar archive file it creates (or extracts) by using gzip compression. To compress our sharedfiles tree, use the following:


#tar czf meshare.tar.gz me


tar compresses and archives in one step. If you use the filename.tar.gz naming convention for gzipped tar files, it helps you keep track of when to use the z option to extract a tar file.

SEE ALSO

•  For more information about file attributes, see page 43 and page 418.
•  For more information about command-line syntax, see page 16.





tar command line options do not require leading dashes
Unlike most Linux commands, the initial arguments on the command line of a tar command do not require leading dashes to set them apart. This is partly because the first argument after the tar command must be one of the major tar functions (c, x, t, u, and so on), so the shell doesn't need an additional cue to determine how to parse the command line.

Using find to Locate Files for tar Backups

Often you must back up certain kinds of files based on their type, owner, creation date, or other file attributes. The find command helps you look for those files by using a large number of options.


#find pathname(s) to search search rule expression


For instance, you can use find to look for HTML files like so:


#find . -name '*.html’ -print


Used this way, find locates all files in the current directory and any of its subdirectories with filenames ending in .html, and then prints a list of those filenames. (Actually, you would not have to list the . before html to indicate the current directory; find automatically searches the current directory if no pathname(s) are listed.)
find works like an inspection line in a factory. It passes each filename it finds in the specified path(s) to the first rule in the search rule expression. Each rule in the search processes the file in some way, and then either passes the file to the next rule, or excludes the file from the search.
Using find to Help with System Maintenance

You can use find to search using a number of different rules. When using find for system maintenance purposes, often you will need to locate files based on one of three criteria: file ownership, file size, or other file attributes (such as file access time, file type, or file permissions). find is equipped to handle most jobs simply. For instance, you can print a list of all files of type d (the directories) in /usr:


#find /usr -type d -print

#find $HOME -size +5k -print




find uses three general kinds of search rules
Find recognizes three basic kinds of rules: tests, actions, and options. Tests, such as name, run tests on each file they process, and forward only those files that pass the test to the next rule in the search. Actions, like print, perform some action on all the files that reach them; they also can pass the file to the next rule in the search. find options determine how the command runs generally; they don’t process individual filenames.

In the preceding example, find prints a list of files with sizes larger than 5KB in your home directory. (In find test expressions, +number represents all values greater than the number, -number represents all values less than the number, and a number with no plus or minus attached stands for the value of the number itself.)
Using the atime and fprint options, you can print a list of man page files that have not been accessed within the last five days in the log file unhit_man_files.log.


#find /usr/man -atime +5 -fprint unhit_man_files.log


find can use a version of the ls command as an option. The following command prints a list of files on the current device (-xdev) belonging to the user tb in the ls -dils format to the file all_tb_files.lst.


#find / -xdev -user tb -ls > all_tb_files.lst


This last example illustrates a way to use find with tar. If the user tb were taking a sabbatical, you could round up all the files owned by that user and back them up by using the tar command.


#cd /

#find / -user tb -print
/usr/local/proj1/stadd.o
/usr/local/proj1/stadd.c
/home/tb/docfiles/mk2efs_notes
/home/tb/scripts/perlscripts/hform1
...

#find / -xdev -user tb -fprint all_tb_files.lst

#tar -cvz -T all_tb_files.lst -f all_tb_files.tar.gz


The -T option instructs tar to look for the list of files to archive inside a file, instead of on the command line.(When using the -T option with tar, you must separate command-line options with leading dashes.) If you were to delete all the tb files, and needed to reinstall them when tb returned, you would have to extract the all_tb_files.tar.gz archive from the same spot you created it (to ensure that the tar extraction replaced the files in the original spots recorded by the find command).



Previous
Table of Contents
Next














Wyszukiwarka

Podobne podstrony:
BC549,548,550,547,546
544 548
2 modulid 550
548 03 2012 NORD 100
02 (548)
GE 550 L&S [GV] L293 82 3
548,8,artykul
550 554
547 550
548 (2)
GE 550 DeVlieg 4K M908 89
GE 550 LeBlonde [KSW] L219 82 8

więcej podobnych podstron