Find, Grep, Locate, Whereis


Example 1

Type this from the home directory. It will display all modified files in the last 3 minutes, in home directory and in /tmp:

find . -mmin -3 -print
  • “.” specifies to start looking in the current directory
  • “-mmin -3” means to look for those files that have been changed in the last 3 minutes.
  • “-print” specifies to show the output on screen. This is not usually necessary on most modern Linux systems.

Example 2

The use of “sudo” allows us to find files we normally wouldn’t have access to:

sudo find / -type f -mmin -10
  • “/” specifies to start in the root directory
  • “-type f” specifies normal files; we do not want links or directories listed.
  • “-mmin -10” means files that have been changed in the last 10 minutes.

Example 3

find ~ -iname "*pic*" -exec mv -v {} /home/user/pics \;
  • “~” looks in home directory
  • “-iname” case-insensitive search
  • “*pic*” the files we are interested in: anything with “pic” somewhere in the filename
  • “-exec” sends the results to another program
  • “mv” the “move” command
  • “-v” verbose – it shows on-screen what is being done
  • “{}” strips out the original path from the file(s) found
  • “\;” the semi-colon ends the series of commands, and the backslash is an escape character which lets the command interpreter know that the semicolon is to be interpreted literally, and not as some other kind of command parameter.


Grep looks for text within files. In this example we search for the word “span” in all the text files:

grep "span" *.txt

It then spits out every reference to the word “span” in all the txt files. Note: it uses Regular Expressions (regex), so you have to use delimiters for certain characters).


The “whereis” command is used for finding the location of executables (binaries), source code, and manuals for a specific program:

whereis gimp

The results returned for this particular example are:

  • /usr/bin/gimp
  • /etc/gimp
  • /usr/lib/gimp
  • /usr/lib64/gimp
  • /usr/share/gimp
  • /usr/share/man/man1/gimp.1.gz


Not as flexible as the “Find” command, because it takes few parameters. But it is lightning fast because it does not manually search the file-system, but rather a database list of files that is maintained by the system. Example:

locate filename

Can be used with “-i” for case-insensitive searches, ie:

locate -i filename
By practic on August 3, 2011 | | A comment?