“paths must precede expression” error when trying to find all jpg files in the current directory












3














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




















  • 2




    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"
    – Jeremy L
    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
















3














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




















  • 2




    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"
    – Jeremy L
    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














3












3








3


1





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















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 .







find






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 14 '11 at 20:28









Lekensteyn

120k48263355




120k48263355










asked Mar 14 '11 at 15:33









Bunny Rabbit

4192817




4192817








  • 2




    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"
    – Jeremy L
    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














  • 2




    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"
    – Jeremy L
    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








2




2




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"
– Jeremy L
Mar 14 '11 at 15:58




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"
– Jeremy L
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




@Nerdling: Why don't you make your comment an answer (which it is)? :)
– arrange
Mar 14 '11 at 16:22










1 Answer
1






active

oldest

votes


















10














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 named pic1 (1).jpg so that file name replaces *.jpg. The command the system is given by the shell becomes



find . -maxdepth 1 -type f -name 'pic1 (1).jpg'


To see in depth, try tracing the original command using strace. What is actually executed is:



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



















  • 3




    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








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f30330%2fpaths-must-precede-expression-error-when-trying-to-find-all-jpg-files-in-the-c%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









10














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 named pic1 (1).jpg so that file name replaces *.jpg. The command the system is given by the shell becomes



find . -maxdepth 1 -type f -name 'pic1 (1).jpg'


To see in depth, try tracing the original command using strace. What is actually executed is:



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



















  • 3




    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
















10














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 named pic1 (1).jpg so that file name replaces *.jpg. The command the system is given by the shell becomes



find . -maxdepth 1 -type f -name 'pic1 (1).jpg'


To see in depth, try tracing the original command using strace. What is actually executed is:



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



















  • 3




    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














10












10








10






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 named pic1 (1).jpg so that file name replaces *.jpg. The command the system is given by the shell becomes



find . -maxdepth 1 -type f -name 'pic1 (1).jpg'


To see in depth, try tracing the original command using strace. What is actually executed is:



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














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 named pic1 (1).jpg so that file name replaces *.jpg. The command the system is given by the shell becomes



find . -maxdepth 1 -type f -name 'pic1 (1).jpg'


To see in depth, try tracing the original command using strace. What is actually executed is:



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














share|improve this answer



share|improve this answer








edited Jan 2 at 5:22

























answered Mar 14 '11 at 16:36









l0b0

3,93173259




3,93173259








  • 3




    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














  • 3




    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








3




3




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






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




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


















draft saved

draft discarded




















































Thanks for contributing an answer to Ask Ubuntu!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f30330%2fpaths-must-precede-expression-error-when-trying-to-find-all-jpg-files-in-the-c%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How did Captain America manage to do this?

迪纳利

南乌拉尔铁路局