1

I'm trying to delete a folder my music collection folder. With the command

ls -al /mnt/media/Music/

I can see the folder - only it has a ? at the end of the name, so it looks like this:

drwxrwxr-x 1 reuben reuben    0 Mar  3 15:24 Twin Shadow - Eclipse (2015) [FLAC]?

but when I try to delete it with this command:

rmdir /mnt/media/Music/Twin\ Shadow\ -\ Eclipse\ \(2015\)\ [FLAC]\?/

Then I get this:

rm: cannot remove '/mnt/media/Music/Twin Shadow - Eclipse (2015) [FLAC]?/': No such file or directory

I'm confused; what am I missing? I hope it's not something really obvious!

2
  • If you want to use escaping, you will also need to backslash-escape the parentheses and brackets, I think i.e. /mnt/media/Music/Twin\ Shadow\ -\ Eclipse\ \(2015\)\ \[FLAC\]?/ (or - simpler - enclose the whole thing in quotes) - if in doubt, type rmdir /mnt/media/Music/Twin and then hit the TAB key to autocomplete Mar 4, 2017 at 0:49
  • If you submit your solution as an answer i'll check it off for you as the solution! Mar 4, 2017 at 1:22

1 Answer 1

3

By far the easiest way to handle filenames like this in the terminal is to make use of the shell's tab completion feature: type enough of the name to be unambiguous e.g.

rmdir /mnt/media/Music/Twin\ Shad

and then hit TAB

The second easiest way - at least if the name doesn't itself contain quotes - is to quote the whole thing e.g.

rmdir '/mnt/media/Twin Shadow - Eclipse (2015) [FLAC]?'

(double quotes should also work in this context).

If you really need to use backslash escapes, then both parentheses and square brackets are shell metacharacters and must also be escaped i.e.

rmdir /mnt/media/Music/Twin\ Shadow\ -\ Eclipse\ \(2015\)\ \[FLAC\]\?/

(the - doesn't need to be escaped - although it doesn't hurt to do so).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .