Command Line – Search

In this item I will go through a couple of the commands you can use to locate files on your system.

find

Surprisingly enough, to find some files you can run find, examples of usage are below

find -x / -name filename

this will search your boot volume for files entitled filename

find / -name filename

this will search all mounted volumes (including network shares) for the file named filename, this can take rather a long time so probably best to specify the volume you wish to search

find . -name ‘*filename*’

this searches the current directory and subdirectories for any files with filename anywhere in their name

grep

Search the contents of text files and print lines containing the word searched for

grep searchterm ~/Documents/filename

searches the file called filename stored in my Documents folder, for the text ‘searchterm’

grep -R searchterm ~/Documents

searches through all the files and folders in my Documents folder for ‘searchterm’

grep -Rl searchterm ~/Documents

searches through all the files and folders in my Documents folder for ‘searchterm’, but this time it will only list the file path, not the contents of the file matching the ‘searchterm’

grep daemon /var/log/system.log

searches the system log for entries that mention ‘daemon’

For more info on additional options, check out their manuals

man find

man grep