-2

For some reasons, I have a file in one of my directories that I cannot delete:

$ ls -al
drwxrwxr-x 2 xxx xxx 4096 Oct 10 14:05 ''$'\r'
(more files follow...)

The problem is that I cannot delete it. I tried rm ''$'\r' and ls using wildcards to at least see what it matches, but had no success. Interestingly, ls -al ?, ls -al ??, etc. does not list the file.

Probably I could delete the entire directory and restore the other files afterwards, but I think it should be possible to 1) list the proper file name, and 2) then delete the file using this name.

user52366
  • 1,035
  • 1
  • 10
  • 21
  • Are all those quotes part of the filename, or did `ls` add them in an attempt at being helpful? Try running `printf '%q\n' *` and see what it prints. The syntax it prints for the name should be usable as an argument to `rm` in bash. – Gordon Davisson Oct 14 '19 at 07:44

3 Answers3

2

I finally managed to do it this way:

ls -i # find the inode of the file
find . -inum 4350083 -delete 

Not sure why the name is not listed in a form that can be entered. I tried enclosing it in $'...' but this also did not work.

user52366
  • 1,035
  • 1
  • 10
  • 21
1

Since you are running bash interactively, you can use file name completion. The first character in the file name is special for the shell, so you need to escape it. Bash should do the rest. So type:

rm \'

Then hit tabulator key, and bash should complete the file name for you, with proper escaping etc. Then just hit enter to delete it.

hyde
  • 60,639
  • 21
  • 115
  • 176
0

I think this is ok.

rm "''$'\r'"
Yuji
  • 525
  • 2
  • 8