Code: Select all
$ find /home/rovan -name 'index*'
$ find /home/rovan -iname 'index*'
The 2nd command would search for the same, but the case of the file name wouldn't be considered. So all files starting with any combination of letters in upper and lower case such as INDEX or indEX or index would be returned.
Code: Select all
$ find -name met*
Code: Select all
$ find /mp3collection -name '*.mp3' -size -5000k
$ find / -size +10000k
The 2nd command would search from the / directory for any file that is larger than 10000k (> 10MB)
Code: Select all
$ find /home/rovan -amin -10 -name '*.c'
$ find /home/rovan -atime -2 -name '*.c'
$ find /home/rovan -mmin -10 -name '*.c'
$ find /home/rovan -mtime -2 -name '*.c'
The 2nd command does the same but searches for those files that have been accessed in the last 10 hours.
The 3rd and the 4th commands do the same as the 1st and 2nd commands but they search for modified files rather than accessed files. Only if the contents of the files have been modified, would their names be returned in the search results.
Code: Select all
$ find / -mount -name 'win*'
Code: Select all
$ find /mp3-collection -name 'MLTR*' -and -size +10000k
$ find /mp3-collection -size +10000k ! -name "MLTR*"
$ find /mp3-collection -name 'MLTR*' -or -size +10000k
The 1st command searches within the directory /mp3-collection for files that have their names beginning with 'MLTR' and whose size is greater than 10000 kilobytes (> 10 MB).
The 2nd command searches in the same directory as above case but only for files that are greater than 10MB, but they should not have 'MLTR' as the starting of their file names.
The 3rd command searches in the same directory for files that begin with 'MLTR' in their names or all the files that are greater than 10 MB in size.
The exec option is probably the most important feature of the find tool. The exec command allows you to execute a particular command on the results of the find command. A simple demonstration of this feature is shown below. Its up to your imagination to make maximum use of this feature. Suppose you wanted to see the details of the files (read, write, execute permission, file size, owner etc..) that have been returned as a search result you could do the following
Code: Select all
$ find / - name 'MLTR*' -exec ls -l {\}\ \;
The words following the -exec option is the command that you want to execute i.e. ls -l in this case.
{\}\ is basically an indicator that the file names returned by the search should be substituted here.
\; is the terminating string, and is required at the end of the command