December 19, 2009

Interactive Find command usage

Sometimes we need to find the file in server which we do not know where exactly it is located:

Search and list all files from current directory and down for the string ABC:

Quote
find ./ -name "*" -exec grep -H ABC {} \;
find ./ -type f -print | xargs grep -H "ABC" /dev/null
egrep -r ABC *

Find all files of a given type from current directory on down:
Quote
find ./ -name "*.conf" –print

Find all user files larger than 5Mb:

Quote
find /home -size +5000000c –print

Find all files owned by a user (defined by user id number) on
the system: (could take a long time)


Quote
find / -user 501 –print

Find all files created or updated in the last five minutes: (Great for finding effects of make install)

Quote
find / -cmin -5

Find all world writable directories:
Quote
find / -perm -0002 -type d –print

Find all world writable files:

Quote
find / -perm -0002 -type f -print
find / -perm -2 ! -type l -ls

Find files with no user:

Quote
find / -nouser -o -nogroup –print

Find files modified in the last two days:

Quote
find / -mtime 2 -o -ctime 2

finding files in a directory that are older than 3 days and deleting them:
Quote
find /directoryname -type f -mtime +3 -exec rm {} \;

No comments:

Post a Comment