Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

There's a lot of stuff about this on the Internet, but most of the examples there are contrived. How does one delete files that are really stubborn? e.g.,

$ find ./ -inum 167794
./àKÈÿÿÿÿ@
$ find ./ -inum 167794 -exec rm \"{}\" \;
rm: cannot lstat `"./\037\340\025K\021\004\310\377\377\377\377@\020\002"': Invalid or incomplete multibyte or wide character

share|improve this question
add comment

2 Answers

up vote 7 down vote accepted

Try removing the escaped double quotes. I believe rm thinks those are part of the filename.

find ./ -inum 167794 -exec rm {} \;
share|improve this answer
    
d'oh. Good spot. I never use unquoted variables in rm commands. I never noticed that find seems to be able to handle them fine. This actually works... weird... is it safe? touch important; touch "myfile -f important"; touch myfile; find "myfile -f important" -exec rm {} \; –  mgjk Apr 13 '11 at 14:40
2  
It's safe. You quote arguments to protect them from being touched by the shell. In this case, find is passing arguments directly to rm and they won't be interpreted/expanded by the shell. –  MikeyB Apr 13 '11 at 15:19
    
man find advises to escape or quote {}, too. –  Sam Hocevar Apr 13 '11 at 22:21
add comment

If you want safe quoting for every shell I know, use this:

find ./ -inum 167794 -exec rm '{}' ';'
share|improve this answer
    
For every known shell, no masking of the braces is needed. Or earn some points on unix & linux. –  user unknown Apr 13 '11 at 18:13
    
@user unknown: Or you could just read man find: Both of [{} and ;] might need to be escaped or quoted to protect them from expansion by the shell. –  Sam Hocevar Apr 13 '11 at 22:19
    
If you had visited my link, you would have seen an emphasized citation citation of that. The text from the man page raised my interest, and I'm waiting since one month for somebody, who can name a current shell, where the argument is valid. might need is the keyword. Might or might not. Maybe I spend a bounty? –  user unknown Apr 13 '11 at 22:36
    
@user unknown: I'm really sorry, I mistook the tone of your message and actually thought it meant I should earn points in order to be listened to. My apologies. That said, I tend to quote anything using { } because I don't want to have of think whether it is likely to get expanded. I agree {} is kinda special and I haven't met a shell that messed with it either. –  Sam Hocevar Apr 13 '11 at 22:50
    
Ah no, I'm sorry for the ambiguous tone. I don't know how old the entry of find is, and don't know any shell, beside bash a bit, nor much OS' beside Linux. So I'm searching for the reason of that entry, because first I thought, it should be masked (from the manpage, and examples) and told everybody to mask it, got later curious, when seeing diverging examples which worked. –  user unknown Apr 13 '11 at 23:58
add comment

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.