I had bug in my bash script that created folder called
~
Anyway that lead me to another problem which is exscuting the following command:
rm -fr ~
ooopsss removed my home folder...
so my question is:
why rm works on the alias and not on the actual folder that is listed where I am?
You can reproduce it, by the following:
cd /tmp/
mkdir "~"
which rm ~
now you will see that the output of which rm ~ is pointing to the actual home folder and not the the ~ which was created in tmp
The ~ is expanded by the shell to the home directory name before rm is called, the rm program is unaware of it.
Expansion of magic characters like this can be suppressed by enclosing them in quotes:
$ echo ~
/Users/fredbloggs
$ echo '~'
~
rm -R ./~
That will make it look for ~ in the current directory. If you run
rm -rf ~
You are removing the original ~ so you need to indirect with ./~
This happens because of the expansion of the special character
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With