Thursday, February 23, 2006

Finging Files with Find

# find path operators

where path is the directory in which find will begin to search and operators tell find which files you are interested in.

Example:

To find a file with specific name,

# find . –name “*ab*” –print

Where the starting point is current directory. (This will find all files under the current directory that has “ab” somewhere in the name.)

find can be used to find files using a lot of other attributes:

# find . -mtime +2 -print
finds files that have been modified for more than 2 days.

# find . -atime -5 -print
finds files that have been accessed for less than 5 days.

# find . –type f –print
Find the file by type
f- Plain file
l- symbolic link
d- directory

# find . –size 1234c –print
finds the file with exactly 1234 bytes

# find . –size +10000c –size -32000c –print
finds the all files in current directory that are grater than 10000bytes, but less than 32000bytes.

# find . –perm -100 -print
find the files with permission 100 (--x------)
---------------------------------------------------------------------------------------------------------------------------
Another useful command to use with this is -exec

find . -name *.jar -exec ls -l {} \;

Find all the jars under the current directory and execute ls -l on each

1 comment:

Lahiru Sandakith Gallege said...

Azeez ayya gave a nice hint on this that it can be also be done with xargs

find . -name .svn | xargs rm -rf

cool ahh....

no exec any more ...