Find command – examples

March 20, 2008 at 10:45 am Leave a comment

Find command can do more than many of us could expect. Simple searches are obviously the most popular but as following examples show humble find can do a lot more:

1. search for a file
find . -name “filename”
2. don’t descend to other filesystems
find . -name “filename” -mount
3.list all directories
find . -type d
4. list all files
find . -type f
5. list all symbolic links
find . -type l
6. list all files more recent than filename
find . -newer filename
7. list all files that the userid doesn’t correspond to valid userid
find . -nouser
8. list all files that the groupid doesn’t correspond to valid groupid
find . – nogroup
9. search all core files and ask before deleting them
find / -name “core*” -ok rm rm{} ;
10. search all files and include the filenames in caution.txt
find / -perm 777 -fprint /tmp/caution.txt

11. search all .dat files bigger than 1M and older than 1 year
find /home -type f -name “*.dat” –size 1M -atime +365 -print
12. search all .c files and sort them
find /home -name “.c” -exec wc -l {} ; | sort -nr

For convienience I have created PDF version here.

Advertisements

Entry filed under: Linux. Tags: , .

Lost in translation Happy Easter

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


Recent Posts

Categories


%d bloggers like this: