Find a File by Name in UNIX, Solaris, or Linux
Posted by Quinn McHenry in UNIX
Using the find command, one can locate a file by name.
To find a file such as filename.txt anywhere on the system:
find / -name filename.txt -print
Recent operating system versions do not require the print option because this is the default. To limit the search to a specific directory such as /usr:
find /usr -name filename.txt -print
About Quinn McHenry
Quinn was one of the original co-founders of Tech-Recipes. He is currently crafting iOS applications as a senior developer at Small Planet Digital in Brooklyn, New York.
View more articles by Quinn McHenry
View more articles by Quinn McHenry
The Conversation
Follow the reactions below and share your own thoughts.



October 22, 2008 at 7:22 pm, snarfel said:
so, i get a bunch of “Permission Denied” notices for directories that my current user account can’t access. is there a way to suppress these?
October 22, 2008 at 7:30 pm, Quinn McHenry said:
Yeah, totally. Normal output goes to “standard output” which can be redirected with normal measures. It’s actually a nice thing that those messages are sent to “standard error” so you can redirect those but keep the more interesting responses.
find / -name something 2> /dev/null
November 17, 2008 at 2:17 pm, venkata sudheer said:
try this # find -name -print
January 08, 2009 at 5:09 am, Jesse F. said:
His problem is is that he doesn’t have permissions to view a lot of the files ‘find’ uses. Here’s a few options:
If you don’t have root permission, then you can supress error messages like so: ‘find -ignore_readdir_race /parent/path/here -name file_name.txt’
Or if you can get permission, then: ‘sudo find /parent/path/here -name file_name.txt’
yay!
June 29, 2010 at 3:31 pm, Goldcd said:
Try
find / -name filename.txt -print 2>/dev/null
June 22, 2010 at 9:03 am, Srikantakumar said:
when I am excuting the below command, getting the file name with ./ prefix before file name which i don’t want (like test2 only not ./test2). any suggestion….
$ find -name “test*” -type f -print
./test2
./test3
./test1
November 12, 2010 at 9:27 am, Rani Sahoo said:
I can use locate filename to get the file with path.
April 06, 2012 at 6:49 am, bill doherty said:
how would I structure the command to only return the names of directories that do NOT contain a specific file…i.e. find directories that do not contain a file called “running.txt”? I currently use find . -name “running.txt” but can’t figure out how to say “opposite” of that? thank you
April 07, 2012 at 7:11 am, qmchenry said:
Bill, you can do logical operations in find that can make some incredibly elaborate and precise scalpel cuts. To do what you’re asking, just add \! in front of your -name argument, so
find . \! -name running.txt