Take the 2-minute tour ×

List all files/dirs in or below the current directory that match 'filename'.

share|improve this question
add comment

3 Answers

up vote 20 down vote accepted

The direct equivalent is

find . -iname <filename>

which will list all files and directories called <filename> in the current directory and any subdirectories, ignoring case.

If your version of find doesn't support -iname, you can use -name instead. Note that unlike -iname, -name is case sensitive.

If you only want to list files called <filename>, and not directories, add -type f

find . -iname <filename> -type f

If you want to use wildcards, you need to put quotes around it, e.g.

find . -iname "*.txt" -type f

otherwise the shell will expand it.

As others have pointed out, you can also do:

find . | grep "\.txt$"

grep will print lines based on regular expressions, which are more powerful than wildcards, but have a different syntax.

See man find and man grep for more details.

share|improve this answer
If <filename> contains wildcards, use quotes around it, e.g. find . -name '*.txt'. –  Gilles Feb 9 '11 at 23:03
@Gilles, updated my answer to say that, thanks. –  Mikel Feb 10 '11 at 4:32
Using <filename> as marker for userinput is a bad habit in command-line environment, where < and > most of the time have specific meaning. I suggest just using filename, maybe FILENAME to emphasize it. Most people will understand, and those, who won't, might cause harm when not understanding that they aren't supposed to hit less-than or greater-than sign. –  user unknown Feb 10 '11 at 8:25
<filename> is a convention in a lot of UNIX documentation, so I think it's useful for people to be aware of it, but I agree FILENAME might be easier to understand. –  Mikel Feb 10 '11 at 10:48
find -iname <filename> is better since it is case-insensitive like DOS –  Agnel Kurian Feb 16 at 17:18
show 2 more comments

Some shells allow ls **/filename, which is quite convenient.

share|improve this answer
Good point. In recent versions of bash, running shopt -s globstar; echo **/filename is equivalent to find . -name "filename". It also works in zsh. –  Mikel Feb 10 '11 at 4:41
That one is really nice. Thanks! –  rozcietrzewiacz Aug 4 '11 at 8:02
add comment

You can do this with

find . | egrep filename
share|improve this answer
You could also do it in one with find . -regextype posix-egrep -regex '.*filename.*' (I don't know if the egrep part is important, but you used egrep in your answer so I included it) –  Michael Mrozek Feb 9 '11 at 20:29
You can, but grep is different than the equivalent DOS command. grep uses regular expressions, while the DOS command uses shell wildcards. –  Mikel Feb 9 '11 at 20:36
Come to think of it, shell globs are also different than DOS wildcards. For instance, find . -name "*.*" won't do what you'd expect from a DOS background. Globs are close enough to be recognizable, though, while regexes are an entirely new beast. –  Jander Feb 10 '11 at 8:14
add comment

Your Answer


