Tuesday, November 23, 2010

find command

To find all files modified in the last x days in the given directory(dirName) and its sub-directories:

find dirName -mtime -x -print


To find all files modified more than x days in the given directory(dirName) and its sub-directories:

find dirName -mtime +x -print


For finding only regular files(not the directories) use

find dirName -type f -mtime -x -print


For finding files by name we can use -type f

find dirName -type f -name 'filename'

filename can be regular expression like *.mp3
Case insensitive searches can be achieved by using the -iname flag instead of name

Further we can narrow down the searches by adding more filter like size and modified times
To find .avi files bigger than 700M and modified in the last 15 days:

find dirName -name '*.avi' -a -size +700M -mtime -15


References
http://www.debuntu.org/how-to-find-files-on-your-computer-with-find

No comments:

Post a Comment