How can I delete a file whose name starts with "#"?

104 Views Asked by At

There is a file #A.py# that appears to be a copy of the original A.py in the same directory - when I try rm, I get the following:

rm: missing operand

What does the ## notation mean? How did this file appear?

3

There are 3 best solutions below

3
On

Add quotes around:

rm "#A.py#"

Without quotes it's interpreted as a beginning of the comment

0
On

Like mention in other answers by using quotes should work:

rm "#A.py#"

Also this:

rm \#A.py\# 

To remove all:

rm \#*

And just in case check the option --

The rm command supports the -- (two consecutive dashes) parameter as a delimiter that indicates the end of the options. This is useful when the name of a file or directory begins with a dash or hyphen. For example, the following removes a directory named -dir1

rm -- -filename
0
On

You could also escape the #:

$ touch \#rmme
$ ls|grep \#
#rmme
$ rm \#rmme