How to find files using a shell prompt

linux-penguinGetting to grips with the command line in Linux will mean that you'll always be able to manage practically any Linux distribution (and there are literally hundreds) without having to learn a new interface.

Command line instructions are often quicker to implement as well.


Example

Here are some example uses of find.

$ find ~ -name myfile.txt -print 

This will use find to search in your home directory (~) for a file with the name myfile.txt and print the search results.

$ find /home -name *.jpg

Find all jpgs in the /home directory and sub-directories.

 

$ find /home -user steven -mtime 7 -iname ".db"

Find all .db files (ignoring text case) modified in the last 7 days by steven

 

Options

Here are some further options that you might find useful.

-O1

(Default) filter based on file name first.

-O2

File name first, then file-type.

-O3

Allow find to automatically re-order the search based on efficient use of resources and likelihood. of success

-maxdepth X

Search current directory as well as all sub-directories X levels deep.

-iname

Search without regard for text case.

-not

Return only results that do not match the test case.

-type f

Search for files.

-type d

Search for directories.

 

Thanks for visiting.