According to man find:

find [-H] [-L] [-P] [-D debugpots] [-Olevel] [starting-point...][expression]


The GNU find command is used to search for files in a directory tree when provided with the root path to search for something.Simply when find with no arguements:


It lists all the files or folders in the current directory recursively.

Methods To Find:

find /mnt/hackit/codeds/ -name i3.png

This search was for a specific image with some name inside the codeds folder.
Let's search for all the images with the extension .png inside the codeds folder.

find /mnt/hackit/codeds/ -name "*.png"

Okay,How about searching for all the images with *.png extension in your linux computer.Might take a long time but will finish.

find / -name "*.png"

Don't get afraid with some errors like permission denied etc.Be a root or act like[sudo].

Some More On Find:

find /mnt/hackit/codeds/ -maxdepth 3 -name "*.png"
find /mnt/hackit/codeds/ -maxdepth 2 -name "*.png"

The first line set's max depth of directory traversal to 3(current directory + two level deep).And from second line command, find will not traverse more than 2 direcories level.(current directory + 1 ).

Searching According To Time

find /mnt/hackit/codeds -atime 5 -name "*.png"
find /mnt/hackit/codeds -atime +5 -name "*.png"
find /mnt/hackit/codeds -atime -5 -name "*.png"

Arguements like -mitime, -ctime and -owner can also be used.

Searching files on a time basis is also essential.So,if we have to search for an image that was accessed/modified 5*24 hours earlier the first line helps.The + and - represents within 5 days or before 5 days.

Advanced Search

find /mnt/hackit/codeds -size +2M -name "*.png"

The above command search for image files which has size greater than 2MB. Similarly, I think they make sense now:

find /mnt/hackit/codeds/ -size -2M -name "*.png"
find /mnt/hackit/codeds/ -size 2M -name "*.png"

Search With Operations

I have a folder with hundreds of books of different programming languages.Searching one by one for a book that i want is time consuming and unusual for programmers to do.Let the machine handle that. When i have to search for all the books of python:

find /mnt/hackit/everything/calibre -iname \*python\*.pdf

Here iname flag tells the find command to find all those books of python ignoring the case.That is an case insensitive file search.

Search And Redirection Within Find

Redirection is also another powerful feature of find,in the above example i found all the books of python programming language but what if i want to copy them into a separate folder or to some friend's pendrive or something like that? This can be times in your life when a friend asks u to copy all the books related to Python programming language in his/her pendrive. This One Command might get you out of trouble for going through all the folders and finding the file and copy-paste to the pendrive.

find /mnt/hackit/everything/calibre -iname \*python\*.pdf -exec cp -r { } /mnt/pendrive_is_on_high \;

-exec option allow us to pass command to perform for the output from the original find command.The {} stores output from previous part of the find command and any command on that output is executed using -exec flag to the find command. Also characters like * or ; must be escaped using \(slash).


man find