find: missing argument to `-exec' when executing the find command in Linux

0

I get the error find: missing argument to-exec'` when I attempt to run the command

find . -maxdepth 1 \( -iname \*.png -o -iname \*.jpg \) -exec echo {} \; 

The reason I am using echo is because I want to make sure it is returning the results I expect before I replace it with either rm or mv. What am I doing wrong?

PeanutsMonkey

Posted 2012-09-15T07:06:22.640

Reputation: 7 780

Question was closed 2012-09-15T07:32:57.470

try getting rid of the superfluous dot at the end? – Sparr – 2012-09-15T07:20:43.937

@Sparr - Sorry added a period in the post as I ended my sentence. The period does not appear in the command I execute. – PeanutsMonkey – 2012-09-15T07:22:59.227

Running it on find version 4.4.2, I receive no error. It has successfully found the .png file. – bbaja42 – 2012-09-15T07:29:28.700

@bbaja42 - I found the issue. I was using colons as opposed to a semi-colon in the command I was executing. The example I posted was typed out and not pasted so didn't have the actual error in my syntax. – PeanutsMonkey – 2012-09-15T07:34:29.583

Answers

1

The issue apparently was I was using the : in my command as opposed to ;. I noticed that as I repeated the exercise having read the example at Why might -exec affect the output of find in Linux?.

The example I posted although real was typed out as opposed to copied and pasted.

PeanutsMonkey

Posted 2012-09-15T07:06:22.640

Reputation: 7 780

I'm closing this because it's just a typo thing and thus not really reproducible for others – hope that's okay with you. – slhck – 2012-09-15T07:33:19.403

Right. There's no way we could have figured that out. – Michael Hampton – 2012-09-15T07:36:43.463

@slhck - That's okay. I only posted it so that if someone had a similar error, they would know what to look for. – PeanutsMonkey – 2012-09-15T07:38:07.050

@Michael Hampton - Thanks for your help though. – PeanutsMonkey – 2012-09-15T07:38:23.757

1

You don't need -exec... at all. Just run the command without it, and you will see what it found.

If it looks acceptable, add -delete onto the end to delete the files.

Michael Hampton

Posted 2012-09-15T07:06:22.640

Reputation: 11 744

1Great but I want to know how to use it with -exec. For example appending -delete would simply delete files but what if I wanted to move the files or something else. – PeanutsMonkey – 2012-09-15T07:24:00.850