Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
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

2 Answers 2

up vote 13 down vote accepted

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 ';'

or

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

should do what you're trying to do.

share|improve this answer
    
nice. It works for me. Why I have to quote it? –  Rafael T Jul 23 '12 at 9:40
2  
That's because the shell might want to expand {} and interpret ; as a command separator. –  Wojtek Rzepala 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 Rzepala Jul 23 '12 at 15:19

use Pipe like the example below:

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

share|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

Your Answer

 
discard

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.