Ian Fung
Ian Fung

Reputation: 23

How to remove files with special characters

How to remove a file(s) with strange name in ubuntu?

I used ssh-keygen, I think I copied the command line with the linebreak at the end and created two files with a very strange file name.

https://ibb.co/0mC5fMj

Try to delete

rm \'\'$\'r\'

But result:

rm: cannot remove ''\'''\''$'\''r'\''': No such file or directory

Upvotes: 2

Views: 3052

Answers (2)

odaiwai
odaiwai

Reputation: 31

You can try to do an interactive rm on any file starting with a non-alpha character:

$ ls  [^A-z0-9]*
''$'\033''qq'$'\033'

$ rm -iv [^A-z0-9]*
rm: remove regular file ''$'\033''qq'$'\033'? y
removed ''$'\033''qq'$'\033' 

Upvotes: 0

Guillaume D
Guillaume D

Reputation: 2326

  • Try to add -- at the beginning of the file name.
$ rm -v -- #file
$ rm -v -- "#file"
  • Try to add ./ at the beginning of the file name.
$ rm -v ./#file
  • If the previous tips do not work, you can still remove it using the inode number with:
ls -li

output:

5133242 -rw-r--r-- 1 user #*%/file

then using find

$ find . -inum 5133242 -delete

Upvotes: 5

Related Questions