Take the 2-minute tour ×

I was trying to remove files ending with a tilde using the command rm *.*~,but that does not remove files that start with a . and end with ~, e.g. .somefile~. I've also tried rm *~, but that also does not work for files starting with a .. Can someone explain why that is?

I want to remove all files ending with ~, regardless of whether they start with a . or not (I was trying to do that without find/exec). Is that possible?

share|improve this question

2 Answers 2

up vote 5 down vote accepted

Files starting with a . are hidden by default, and don't show up in a normal ls. Because you may not have seen them, shells generally won't match these files unless you manually include them. You can do this as follows:

rm *~ .*~
share|improve this answer
thanks, that did the trick –  Jeff Storey Jan 3 '13 at 2:22

Though the above answer is probably safer (because of fewer side effects), for completeness....

The bash shell (which is what most people run on Linux) has a flag to say whether or not to include dotfiles in globs. You set it with shopt -s dotglob. The sequence below is before setting the flag, then after setting. Notice the rm will remove it once dotglob is set.

$ touch .somefile~
$ rm *~
rm: cannot remove `*~': No such file or directory
$ ls -A
$ shopt -s dotglob
$ rm *~
$ ls -A

A little bit less safe; in theory you may forget whether or not this is set. But if you want to set this everywhere, and you're consistent about it, it may be what you want.

share|improve this answer
+1 - I wasn't aware of this. thanks. –  Jeff Storey Mar 23 '13 at 0:08

Your Answer


