1

I accidentally created a directory who's name begins with the "$" character, and now I can't figure out how to ls its contents or rm -r it altogether.

I've tried quoting the name like this ls "$[dir-name]" as well as escaping the special character like ls \$[dir-name], neither of which worked.

Any tips? Thanks!

2 Answers2

4

Using double quotes fails since the shell will still try to expand the variable, but escaping it should work unless there are other characters that may cause an issue as well. Try single quotes.

ls '$foo'
0

Supposing your file is named $file, you can also rm *file. In zsh, you could also rm ?file.

raylu
  • 505
  • think twice before executing rm *file because that will delete all files with filenames ending in "file" – Lesmana Apr 24 '11 at 08:52