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 have a folder in which I have around 4k files. Some of these files start with a a ? or ! character. I need to delete them but can't find an expression that would do so:

rm -f ./?*

just deletes everything. I can possibly use grep on ls and pipe it through xargs and move files to another folder but I was hoping there was a proper way of doing this. Need help on both the ? and ! files.

share|improve this question

1 Answer 1

up vote 18 down vote accepted

No need for any fancy stuff. Simply escape the ? so that it's not considered part of the glob:

rm -f ./\?*

This works for ! too:

rm -f ./\!*

Or in one fell swoop:

rm -f ./{\?,\!}*

Update

Just noticed that you were suggesting to grep the output of ls. I wanted to bring your attention to the fact that you shouldn't parse the output of ls

share|improve this answer
    
Oh, I feel stupid :$. Thanks a lot :) –  recluze Jul 13 '13 at 6:05
4  
@recluze Not stupid; it's far from obvious how to do it if you don't know about wildcard escaping. –  Michael Kjörling Jul 13 '13 at 11:41
    
@recluze Still feel stupid after 5 votes on your question? :) By the way, see the updated answer. –  Joseph R. Jul 13 '13 at 21:16
    
Thanks and thanks :) ... Was aware of the problems in ls output but my files had a particular pattern that I could count on. Nevertheless, good to know :) –  recluze Jul 14 '13 at 5:51

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.