Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 24 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 ./{\?,\!}*


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

In my case, the characters were not really question marks, but unicode characters that apparently could not be displayed in my console.

Using rm -i * worked for me. If you don't want to do this, you can also delete by inode, as described at http://www.cyberciti.biz/tips/delete-remove-files-with-inode-number.html.

To find the inode, use:

ls -il

Then do:

find . -inum [inode-number] -exec rm -i {} \;
share|improve this answer

Your Answer


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.