0

I have a directory that has a name like 10.2 (14C92) i want to remove using rmdir -rf (to include their content). I do know how to pass a space with \ but I got the result:

-bash: syntax error near unexpected token ('

So it seems to me that I somehow have to escape the parenthesis from the command. How am I doing this properly?

2

You can use \ to escape any single character, ( and ) included as you already do with spaces. While it works, it can be cumbersome if you have lots of characters/spaces to escape.

A faster alternative is to use single quotes (') to escape the whole string, i.e. something like:

rm -rf '10.2 (14C92)'

Please keep in mind that ' escape everything, so use it with care if you need, for example, variable expansion inside the quotes. That said, using double quotes works for escaping spaces and parentheses, also:

rm -rf "10.2 (14C92)"

Also, based on your question, you try to use rmdir. rmdir works only for empty directories and it doesn't have -r and/or -f flags:

NAME rmdir - remove empty directories

SYNOPSIS rmdir [OPTION]... DIRECTORY...

DESCRIPTION Remove the DIRECTORY(ies), if they are empty.

You'll want to use rm -rf.
If 10.2 (14C92) is indeed empty, a simple

rmdir '10.2 (14C92)'

would do.

Escaping is done by bash itself, so it works for every command. In other words, it's bash which decides what to pass to the command, based on its own parsing rules, the command then acts on the arguments after bash has parsed them.

1

You are already on the right path. You can use the escape character \ for parenthesis aswell.

rm -r 10.2\ \(14C92\)

You can also use quoting:

rm -r '10.2 (14C92)'
  • does this also work with rmdir? – procra Jan 15 at 9:33
  • Yes. This is not specific to the program being run, but to your shell! – Panki Jan 15 at 9:35
  • thanks that worked for me, now i am finally able to clean up my drive from old system stuff i don't need anymore. I didn't even had enough space for an OS update before – procra Jan 15 at 9:36
0

rm -rf 10.2\ \(14C92\)/ - recursively remove this folder 10.2\ \(14C92\)/ and all of its content.

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.