ls, rm, or perform other operations on a directory who's name begins with '$'

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!

johnny_bgoode

Posted 2011-04-24T04:48:15.863

Reputation: 178

Answers

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'

Ignacio Vazquez-Abrams

Posted 2011-04-24T04:48:15.863

Reputation: 100 516

0

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

raylu

Posted 2011-04-24T04:48:15.863

Reputation: 485

think twice before executing rm *file because that will delete all files with filenames ending in "file" – lesmana – 2011-04-24T08:52:24.640