How to remove a folder that starts with “$”?
$
, space, '
and [
are special characters in most shells. To remove their special meaning, you have to use the quoting mechanisms of the shell.
The quoting syntax varies very much with the shell.
In all shells that I know, you can use single quotes to quote all characters but single quote, backslash and newline (in Bourne-like shells, it does quote the last two as well, except in backticks for \
in some).
rm -r '$pattern'
Should work in most common shells.
rm -r \$pattern
Would work (except inside backticks for Bourne-like ones) in all shells but those of the rc
family.
Same for:
rm "\$option[value='2016']"
In rc
-like shells, you'd use:
rm '$option[value=''2016'']'
If directory is empty:
rmdir \$pattern
Otherwise:
rm -r \$pattern
(It will delete recursevely any file that the folder contains)
When you need to operate on a file which contains special characters, an option is to use the bash autocomplete feature: start typing your command (in this case rmdir
) and then hit Tab several times. This will cycle around all the files/directory in the current directory, automatically escaping all special characters.
This also works well if you're operating on very long filenames.