1

A script I wrote named a file "() - ." according to Filezilla. Filezilla was unable to delete it from the server so I tried to "rm "() - ." from inside the containing folder and received "rm: cannot remove `() - .': No such file or directory". I then used "ls" which shows...

 () -  .                                               03_The_Kill_30_Seconds_to_Mars.mp3                 Crooked X (Crooked X) - 08 Nightmare.mp3
01 Attack - 30 Seconds to Mars.mp3                     03 Wave of Mutilation - Pixies.mp3                 Danzig (Danzig) - 01 Twist Of Cain.mp3

It lists the file in question though here it looks like it might contain a leading space and mabey two spaces between the "-" and the ".". So I tried to "rm" many combinations of spaces mixed between the other characters with no success.

I also tried renaming it but with the same error.

My fallback is to replace it with a 0KB file of the same name but, I'd rather delete it, (read- I'm OCD and it's irritating me that it shows up in "ls")

Thanks for any help.

Running: Ubuntu 12.04 LTS Server Edition

1
  • 1
    if you can type rm and then the first symbol of the name then hit tab bash and zsh will fill it in. rm \ \(\)\ -\ \ . this was my test
    – zeitue
    Dec 3, 2012 at 18:30

4 Answers 4

1

From the terminal... First, let's test before trying. Create a similar file with this command:

touch \(\)

Then to remove that file:

rm \(\)

The \ symbol is used for special characters.

In your case, as long as the file is the only file that starts with (), you should use this command

rm -i \(\)*

The -i makes it interactive (asks your permission).

3
  • 1
    I made \(\) and "rm"ed it then tried rm -i \(\)* with no luck then changed it to rm -i \ \(\)* suspecting the beginning space and it "rm"ed it. Thanks!
    – Seminecis
    Dec 3, 2012 at 17:50
  • you're lucky it ended up being a space. Next time, in case it is some unprintable char, you could still use wildcards rm *\(* Dec 3, 2012 at 19:02
  • 1
    As an update to my issue, I have also found that some ftp clients do remove files named like () - . even though filezilla couldn't delete it, Notepad++ nppftp plugin was able to. I found that interesting. Thanks again for all the help.
    – Seminecis
    Dec 3, 2012 at 22:51
1

Since the filename contains spaces, you need to include the filename in quotation marks.

One problem why you cannot delete the file is because you might not have permissions to do it.

So try sudo rm " () - .".

This should do the trick. Also look out for a trailing space after '.'

1
  • Thanks for the reply, still had the same error though.
    – Seminecis
    Dec 3, 2012 at 17:47
1

What I usually do in cases like that is to use tab-completion to make sure everything gets escaped properly. The steps would be:

  • open a terminal and navigate to the folder with the bad filename in it
  • type "rm \ " (a backslash followed by one space)
  • hit tab
  • that should expand the filename with the necessary escapes

This is assuming that's the only filename you have that starts with a space - if there's more than one, you might need to manually type and escape the first couple of characters so it can distinguish which one you mean.

0

An alternate solution (even though properly using rm may be preferable) is to use midnight commander, e.g.

$ sudo apt-get install mc
$ mc

Then,

  • move to the directory containing the file (use up/down arrows to select directories and enter to cd to them),
  • select the file you want to delete (CTRL-T)
  • delete the file (F8)

You must log in to answer this question.

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