Messiah
Messiah

Reputation: 35

I accidentally deleted files in a repository using rm *$*

I was trying to remove a file within a repository which contained a "$" symbol, so I used:

rm *$*

But this deleted all my files in the directory and attempted to delete all subdirectories as well.

Can someone explain why this command did not just remove files containing a $?

Upvotes: 2

Views: 732

Answers (1)

chepner
chepner

Reputation: 531345

*$* first undergoes parameter expansion, with $* expanding to a string consisting of all the current positional parameters. If there are none, the result is *, which then undergoes pathname expansion.

The correct command would have been something like rm *"$"* or rm *\$*, with the $ escaped to prevent any parameter expansion from taking place before pathname expansion.

Upvotes: 3

Related Questions