1

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?

2 Answers 2

5

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 *~ .*~
0
1

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
.somefile~
$ 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.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .