finding files on lunix using the find command and grep

find /home/www -name ‘index*’
find /home/www -iname ‘index*’
The 1st command will find files with filename starts with ‘index’ in the directory /home/www and all the sub-directories below it.
The 2nd command does the same, except it will be a case insensitive, for example, filenames start with “Index”, “INDEX”, “index”, “inDEx” will all be returned.

find /home/music -name ‘*.mp3’ -size -5000k
find /home/music -size +5000k
The 1st command will find mp3 files with file size less than 5000 Kilobytes wihin the directory /home/music and all the sub-directories below it.
The 2nd command will find any file with file size larger than 5000 Kilobytes within the directory /home/music and all the sub-directories below it.

find /home/app -amin -5 -name ‘*.cpp’
find /home/app -cmin -5 -name ‘*.cpp’
find /home/app -mmin -5 -name ‘*.cpp’
find /home/app -mtime -5 -name ‘*.cpp’
The above will all search for files with the .cpp extension in the directory /home/app and all the sub-directoreis below it.
The 1st command will retrun files that have been accessed in the last 5 minutes.
The 2nd command will return files with their status changed in the last 5 minutes.
The 3rd command will return files that have been modified within the last 5 minutes.
The 4th command will return files that have been modified within the last 5 days.
Note, if we change the -5 to +5 in the above commands, it would be mean more than 5 mintues or 5 days.

find /home/www -name ‘index*’ -and -amin -5
find /home/www -name ‘index*’ -or -amin -5
find /home/www -name ‘index*’ ! -amin -5
The 1st command will find files with file name starts with index AND was accessed within the last 5 minutes.
The 2nd command file find files with file name starts with index OR was accessed within the last 5 minutes.
The 3rd command file find files with file name starts with index but wasn’t accessed within the last 5 minutes.

find /home/app -executable -name ‘*’
find -executable -name ‘*’ -exec ls -l ‘{}’ ;
The 1st command find all executable files in the directory /home/app and all the sub-directories below it.
The 2nd command does the same but it will return the files with file details such as ownership, last modified, etc.

grep -Hrn ‘error’ .
This command will find files that contains the term ‘error’ in the currently directory and all the sub-directories below it. It will print the file name and the line numbere where the file has the term “error”.

man find
This command will let you know all the functionalites and how to use the find tool in your linux or unix system.

Search within Codexpedia

Custom Search

Search the entire web

Custom Search