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 $
?
CodePudding user response:
*$*
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.
CodePudding user response:
here's link for rm this explained everything you need to use rm command in future (https://www.computerhope.com/unix/urm.htm) . it deleted all your files because used * in it. * stands for everything contains in your current folder including sub directories !!!! be careful next time. happy coding :)