Usage of Find command in Unix
Example:1
find . -name "rc.conf" -print
This command searches in the current directory and all the sub directory for a file name rc.conf
Exampe:2
find . -name "rc.conf" -exec chmod 0+r '{}' \;
This command searches the current directory and all the sub direcories .All files named rc.conf will be procesed by the chmod o+r command.The argument '{}' inserts each found file into the chmod command line.The '\' argument indicates the exec command line has ended.
The end result of this command is all rc.conf files have the other permissions set to read access(if the operator is the owner of the file).
Example:3(Apply a complex selection of files -o and -a)
find /usr/src -not \(-name "*,v" -o -name ".*,v" \) '{}' \; -print
This command searches the /usr/src directory and all sub direcories .All files that are of the form '*,v' and '.,V' are excluded.
Important arugments to note :
*] -not means the negation of the expression that follow
*]\( indicates the start of a complex expression
*] \) indicates the end of a complex expression
*] -o means a logical or a complex expression
In this case the complex expression is all files like '*,v' or '.*,v'
The above example shows how to select all files that are not part of the RCS system.This is important when you want to go thro a source tree and modify all the source files.But you dont want to affect the RCS version control files.
Example:4 [How to search for a string in a selection of files (-exec grep)]
find . -exec grep www.athabasca" '{}' \; -print
This command searches the current directory and all sub directories.All files that contains the string will have their path printed to Standard output.
If you want to just find each file then pass it on for processing use the -q grep option.This find the first occurances of the search string.It then signals sucess to find and find continues searching for more files.
find . -exec grep -q www.athabasca '{}' \; -print
This command is very important for process a series of files that contain a specific string.You can then process file appropriately.An example is find all html files with the string "www.athabascau.ca".You can then process the files with a sed script to change the occurances of www.athabascau.ca with intra.athabascau.ca"
Example:5
find / -name chapter1 -type f -print
Searches through the root file system for the file named chapter1.
Example:6
find /usr -name "chapter*" -type f -print
Searches thro the /usr directory for all files that begin with the word "chapter"
Tuesday, October 03, 2006
Previous Posts
- Unix : Complete List of Vi Commands ......... w ...
- Removing Duplicate rows in oracle....................
- Avoid these communication mistakes............ P...
- STROKE: Remember The 1st Three Letters... ...
- Transcript of J. Jayalalitha's interview on BBC Wo...
- For all you F1 fans... 01. An F1 car is made up o...
- Good ..... Measuring programming progress by lin...
- Madras..... Nalla Madras..... Wanna drive Pulsar o...
- Good Sites to browse : Java/J2EE: For Beginners ...

0 Comments:
Post a Comment
<< Home