I want to remove certain files using find and -exec. But unlikely bash tells me, that I'm "missing" some argument.

find . -name *.png -exec rm {} /;

what do I miss?

same "missing argument" return for my attempt to rename some files:

find . -name ic_launcher.png -exec mv {} other_name.png /;

Can somebody tell me, what bash does miss, and why this command isn't successful?

  • 10
    Are you really putting /; at the end? If so, try \; instead. – D_Bye Jul 23 '12 at 9:32
  • 7
    By the way find has -delete option. There is no need in -exec rm {} \;. – rush Jul 23 '12 at 9:39
  • 3
    Backslash and slash are not the same thing at all. Backslashes lean backwards: \\ , Forward slashes, or just slashes, lean forwards: /. In Unix, slashes are generally path separators, while backslashes are generally used for quoting / escaping. – jw013 Jul 23 '12 at 12:19
  • 1
    @jw013 sorry about that! I was actually misreading it, most likely because I found so many examples that use the slash instead of the backslash. In fact the manpage is right! – Rafael T Jul 23 '12 at 12:39
  • 4
    Wherever you found those examples that used the wrong slash must not be a very good resource. I would recommend not going there for examples anymore. – jw013 Jul 23 '12 at 12:44

The semicolon at the end needs to be quoted or escaped so that it is passed to find instead of being interpreted by the shell.

find . -name ic_launcher.png -exec mv '{}' other_name.png ';'


find . -name ic_launcher.png -exec mv '{}' other_name.png \;

should do what you're trying to do.

| improve this answer | |
  • 2
    That's because the shell might want to expand {} and interpret ; as a command separator. – Wojtek Jul 23 '12 at 9:48
  • 1
    It's almost never necessary to quote {}. There was actually an entire question about that, but I can't find it because the site can't search for {}. The issue is the /; typo in the original question. – jw013 Jul 23 '12 at 12:17
  • 4
    Found it: modern shells don't require quoting {}. – jw013 Jul 23 '12 at 12:28
  • @jw013 That is a very fair point. I guess I usually tend to go for something that will definitely work. And after having experienced issues with no quoting, I usually quote the braces. Possibly a bit too much for my own good. – Wojtek Jul 23 '12 at 15:19
  • Yup, no harm in over-quoting. It's definitely better to err that way than the other way, but leaving out redundant quotes does save some keystrokes :). Normally I don't point out redundant quotes but in this case I just wanted to make sure the questioner understood where the real issue was, i.e. the misquoted ; character. – jw013 Jul 23 '12 at 17:41

use Pipe like the example below:

find . -name 'spam-*' | xargs rm

| improve this answer | |
  • that is a workaround to do what I which, but no answer on what I miss. I will use your solution for now, but I'd still like to know what I miss on the find command – Rafael T Jul 23 '12 at 9:38
  • Are you quoting the * wildcard? find . -name "*.png" will find all png files in or below the current dir, without those double quotes the shell will expand the * so you'll find all png files with the same name as one in the current dir - probably not what you meant. – Bristol Jul 23 '12 at 13:29
  • 3
    If you use xargs in combination with find, use -print0 etc. to sanitize against blanks etc. in filenames, so in general it is much more easy to use -exec instead, or, for rm, just -delete. – user unknown Jul 23 '12 at 14:49
  • 2
    While this may help to do what the OP is trying to do, it does not at all answer the question that was asked. – killermist Jul 23 '12 at 19:48

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