5

I'm trying to delete a file using the console with this command

rm ./google-chrome-stable_current_amd64(1).deb

but I get a syntax error. What is wrong with this command?

Abhay Patil
  • 2,545
  • 3
  • 18
  • 36
af1223345
  • 51
  • 2
  • You need to quote or escape the special characters - see related [How to delete all files that contains “ (2)” wildcards dont work](https://askubuntu.com/questions/694262/how-to-delete-all-files-that-contains-2-wildcards-dont-work) – steeldriver Jul 19 '20 at 17:58
  • ... also [How do I enter a file or directory with special characters in its name?](https://askubuntu.com/questions/101587/how-do-i-enter-a-file-or-directory-with-special-characters-in-its-name) – steeldriver Jul 19 '20 at 17:59
  • You can after the first few characters of a filename and the terminal will fill in as required. So `rm google-c` will probably fill in the name as the terminal expects it. – Stephen Boston Jul 19 '20 at 18:32
  • What syntax error are you getting? Show us the error – Abhay Patil Jul 19 '20 at 20:39

1 Answers1

5

Parentheses are treated specially by the shell. Quote them to remove their special meaning so the shell treats them literally.

There are three major forms of quoting, and for this purpose any of them will do:

  • Since ( and ) are not the ' character, they're treated literally inside single quotes (so long as the single quotes are not themselves quoted).
  • Since they are not $, `, \, or !, they're treated literally inside double quotes (so long as the double quotes are not themselves quoted).
  • Like any character, they're treated literally after a \ (so long as the backslash is not itself quoted).

Thus any of the following will work:

rm ./google-chrome-stable_current_amd64\(1\).deb  # backslashes
rm './google-chrome-stable_current_amd64(1).deb'  # single quotes
rm "./google-chrome-stable_current_amd64(1).deb"  # double quotes

Though less commonly done, you can also use single quotes or double quotes to quote less than the full argument. For example, these also work:

rm ./google-chrome-stable_current_amd64'(1)'.deb
rm ./google-chrome-stable_current_amd64"(1)".deb

As a separate matter, note that you don't need the leading ./ in the path here, though it's fine to include it. With rm, you'd only need it if the path started with a - character, which rm would attempt to treat as one or more options rather than a path. (Though you could alternatively pass a separate -- argument before the path to indicate that all separate arguments are paths and not options.)

Eliah Kagan
  • 116,445
  • 54
  • 318
  • 493