6

I've accidentally created a file named °. Now I'm having trouble deleting it with bash.

[/opt/etc/sudoers.d] # ls -l
-r--r-----    1 admin    administ       21 Feb  3 23:54 010-root
-rw-r--r--    1 admin    administ       20 Feb  3 23:50 °

Typing rm ° seems to only move the caret to the beginning of the line, i.e. no character is entered.

(For what it's worth I'm running bash 3.2.0 on a remote machine conntected with SSH using Mac OSX Terminal)

Any ideas?

12

How about?

rm -i ?

I think this should work...

  • 2
    For further explanation, -i means "interactive". It will prompt you for each matching file before deleting it. – bahamat Feb 5 '11 at 21:01
  • Great idea, but I had to replace ? with * to make it work. rm: cannot remove '?': No such file or directory. What am I missing? – Oskar Feb 6 '11 at 12:42
  • 2
    Perhaps your locale is wrong and so your shell sees the degree/ring symbol as two characters rather than one. Again, what does locale -a print? – Mikel Feb 6 '11 at 20:15
  • 1
    Actually, the output of locale without -a would be better. – Mikel Feb 6 '11 at 22:25
10

If there are a lot of matches to using a wildcard with rm like rm -i ?, you can always remove it by inode number instead:

ls -i
find . -inum <inode> -ok rm '{}' \;

Where <inode> is the inode number from ls -i, which lists all the inode numbers of the files in the current directory.

  • 1
    oh, this is cool. – gabe. Feb 7 '11 at 22:28
  • This is the best answer since it gives a handle to the file itself. Also, I never knew about the -ok flag! – anthonybell Aug 22 '16 at 16:59
2

The rm -i ? answer is fine.

This would also work:

rm [^a-z]

as would

rm [[:punct:]]

And as to why it's going back to the start of the line, how are you typing the ˚? Perhaps the input is being interpreted as Ctrl+A or some other shortcut that is used by the shell to go to the start of the line.

Is there a setting to set the encoding or character set to utf-8 in the terminal app? What does it print if you run locale inside the terminal session?


And how did you create the file? Maybe you can use a similar method to delete it?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.