I cannot delete such a type of #file.ext#

sedsil

New Member
Joined
Sep 23, 2022
Messages
3
Reaction score
2
Credits
22
Dear All,

I cannot delete such a type of #file.ext# by using the command "rm". What can I do?
sedsil.
 


kc1di

Well-Known Member
Joined
May 14, 2021
Messages
1,146
Reaction score
960
Credits
8,203
Hello @sedsil,
Welcome to the Linux.org forums.

What error message do you get when you try to rm the file?
Where is the file located on the system and what are it's permissions?

It might be helpful to those trying to help you if you included the Distro your using also.
 
OP
S

sedsil

New Member
Joined
Sep 23, 2022
Messages
3
Reaction score
2
Credits
22
hi kc1di,
here is the message I got:

-bash-4.2$ rm #md_6b.log.1#
rm: missing operand
Try 'rm --help' for more information.
-bash-4.2$
 

Old Tom Bombadil

Active Member
Joined
Jul 29, 2020
Messages
109
Reaction score
141
Credits
1,013
It's a bad idea to use special characters, like #, as the first character in a file name. The easiest method to delete this file is to preface the file name with ./ (dot slash), like this:
Code:
rm ./#md_6b.log.1#

If that gives you a Permission Denied error, then use sudo:
Code:
sudo rm ./#md_6b.log.1#

Of course you need to be inside the directory with the file you want to delete when you give the appropriate rm command above. This article gives more information about special characters in file names.
 

kc1di

Well-Known Member
Joined
May 14, 2021
Messages
1,146
Reaction score
960
Credits
8,203
Old Tom beat me to it. Do as he says change the name of the file if It indeed has # as the first character. That symbol usually mean ignore what follows.
 

JasKinasis

Well-Known Member
Joined
Apr 25, 2017
Messages
1,522
Reaction score
2,162
Credits
10,996
It's a bad idea to use special characters, like #, as the first character in a file name. The easiest method to delete this file is to preface the file name with ./ (dot slash), like this:
Code:
rm ./#md_6b.log.1#

If that gives you a Permission Denied error, then use sudo:
Code:
sudo rm ./#md_6b.log.1#

Of course you need to be inside the directory with the file you want to delete when you give the appropriate rm command above. This article gives more information about special characters in file names.
Actually #filename.ext# is typical of a backup file automatically created by emacs. So if you open a file in emacs, edit it and then quit without saving, it often creates a backup file that has # characters at the start/end of the original filename. And it is possible that other software might create similarly named backup files.

RE: filenames containing special characters
You should either escape any special characters with backspaces, or enclose them in double quotes.

So in order to remove the temporary files in the terminal, you could use backspaces to "escape" special characters in the file-name like this:
Bash:
rm /path/to/\#md_6b.log.1\#
OR using double quotes:
Bash:
rm "/path/to/#md_6b.log.1#"

And as pointed out by @Old Tom Bombadil , if you require root permissions in order to remove the files, you should use sudo.
e.g.
Bash:
sudo rm "/path/to/#md_6b.log.1#"

Also note:
In all of the above examples, substitute /path/to/ with the actual path to the file you want to delete.
 
OP
S

sedsil

New Member
Joined
Sep 23, 2022
Messages
3
Reaction score
2
Credits
22
Actually #filename.ext# is typical of a backup file automatically created by emacs. So if you open a file in emacs, edit it and then quit without saving, it often creates a backup file that has # characters at the start/end of the original filename. And it is possible that other software might create similarly named backup files.

RE: filenames containing special characters
You should either escape any special characters with backspaces, or enclose them in double quotes.

So in order to remove the temporary files in the terminal, you could use backspaces to "escape" special characters in the file-name like this:
Bash:
rm /path/to/\#md_6b.log.1\#
OR using double quotes:
Bash:
rm "/path/to/#md_6b.log.1#"

And as pointed out by @Old Tom Bombadil , if you require root permissions in order to remove the files, you should use sudo.
e.g.
Bash:
sudo rm "/path/to/#md_6b.log.1#"

Also note:
In all of the above examples, substitute /path/to/ with the actual path to the file you want to delete.
thanks for the solution
 
$100 Digital Ocean Credit
Get a free VM to test out Linux!

Linux.org Hosting Donations
Consider making a donation

Members online


Top