Find, Grep, Locate, Whereis

Find

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

Example 2

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

sudo find / -type f -mmin -10

Example 3

find ~ -iname "*pic*" -exec mv -v {} /home/user/pics \;

Grep

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).

Whereis

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:

Locate

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

Leave a Reply

Time limit is exhausted. Please reload CAPTCHA.