Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

while running find command to find all the jpg files in the current directory as

find . -maxdepth 1 -type f -name *.jpg

i am getting the error as :

 find: paths must precede expression: pic1 (1).jpg
 Usage: find [-H] [-L] [-P] [-Olevel] [-Dhelp|tree|search|stat|rates|opt|exec] [path...] [expression]

i am not able to figure out what is wrong with that .

share|improve this question
If you have a .jpg file in the current directory then your shell will expand your wildcard to be a list of the jpg files. Put your pattern in quotes to prevent this: "*.jpg" – Nerdling Mar 14 '11 at 15:58
@Nerdling: Why don't you make your comment an answer (which it is)? :) – arrange Mar 14 '11 at 16:22
up vote 8 down vote accepted

Always quote globs in find: find . -maxdepth 1 -type f -name "*.jpg"

To see why, try tracing the original command and looking at what is actually executed:

touch foo.jpg bar.jpg
strace find . -maxdepth 1 -type f -name *.jpg 2>&1 | grep jpg
execve("/usr/bin/find", ["find", ".", "-maxdepth", "1", "-type", "f", "-name", "bar.jpg", "foo.jpg"], [/* 62 vars */]) = 0
share|improve this answer
strace is a great tool, but definitely an overkill for somebody who doesn't understand shell expansion. It's much simpler to step back in the shell history and just prepend the command with "echo". – Adam Byrtek Mar 14 '11 at 23:42
Always is, as always :) , too often. find proj* -type f -name foobar` will search in every directory which matches ./proj* for example; perfectly valid and reasonable. – user unknown Mar 26 '11 at 16:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.