13

I'm in directory "home" and I run this command

find . -iname *.mov

and it produces

./root/movies/Corey/holtorf/Intro.mov

Now, I "cd .." and run the same command

find . -iname *.mov

This time "Intro.mov" is not in the result. What are the reasoning behind this? And what is the command to search recursively for every file ending with ".mov" in the current directory? Thanks.

Sean Xiao
  • 606
  • 1
  • 12
  • 20

4 Answers4

24

When using a wildcard in an argument it is expanded by the shell. To prevent this, you need to write "*.mov".

In your case, the shell expands to whatever files it finds before passing the argument to find, which then gets a list of files and will not search based on the original pattern.

ypnos
  • 50,202
  • 14
  • 95
  • 141
22

You might need to add -follow if your home directory is actually a symlink. Also quote the pattern otherwise the shell will try to expand it before passing it to find.

find . -iname "*.mov" -follow
dogbane
  • 266,786
  • 75
  • 396
  • 414
4

I cannot comment yet so I will post this as an answer (my apologies in advance).

Please check out this post "find: paths must precede expression:" How do I specify a recursive search that also finds files in the current directory?

And additional information that may benefit you: To recursively find a file with a certain name in your current directory, you can use either grep or find

grep -r "*.mov" .

or for case-insensitive search

grep -ri "*.mov" .

and for find

find . -type f -exec grep -l "*.mov" {} +

Also a useful link http://www.cyberciti.biz/faq/howto-recursively-search-all-files-for-words/

Community
  • 1
  • 1
Kenneth P. Hough
  • 577
  • 2
  • 8
  • 25
1

I would use:

 grep -rn 'mov' .

recursive numeric search

Head
  • 548
  • 7
  • 26
  • For some reason, this is a lot slower than `find` with my shell `GNU bash, version 5.0.11(1)-release (x86_64-apple-darwin18.6.0)`. There must be a significant difference between the algorithms. – kakyo Oct 29 '20 at 12:00