It happened again. I’m not sure how I keep doing this all of a sudden, but a few times in the last month or so I’ve managed to create a file or folder called
~ in one project or another. Now the problem is that
~ is the shortcut for your home folder. In my case that’s
/home/keith on Linux, or
/Users/keith on MacOS. At that point things get really weird. You can’t see what’s in the folder or file because any command you use to try to look at it looks at your home folder instead. You can’t just
rm -rf ~. No… please don’t even try that. I couldn’t even change the name with
mv ~ foo because that would try to move my home folder into a new folder called
foo which is probably somewhere in my home folder.
The trick is pretty simple, but since I already had to look it up a couple of times, I’ll post it here.
mv \~ foo
\~, the system knows that you’re talking about this file/folder in the current directory, not the shortcut to home. Now you have a
foo folder there instead, which you can look inside of and see whats there, and delete it or whatever.
You could also delete it directly this way:
rm -rf \~
But that feel like playing with fire. Rename it first and make sure you’ve done the right thing.