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 .
Best Answer
tl;dr Always quote globs in find:
find . -maxdepth 1 -type f -name "*.jpg"
(notice the"
characters surrounding*
).In your case, the shell is interpreting
*.jpg
(note the*
character) and trying to match file names within the current directory that end in.jpg
. There is a file namedpic1 (1).jpg
so that file name replaces*.jpg
. The command the system is given by the shell becomesTo see in depth, try tracing the original command using
strace
. What is actually executed is: