Search code examples
shellubuntucommand-line

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

Solution

    • 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