I was working on a project to control my digital camera using Ubuntu and gphoto2. At one point I noticed a new "~" directory in my project folder, /home/greg/project/~. When I enter this new "~" directory, it takes me backwards to my home directory /home/greg/ (as you might expect).

I don't know exactly how this happened, but my suspicion is that when I ran gphoto2 on the command line and specified an output file, I typed "~/filename.jpg" expecting the file would show up in my home directory, but instead bash put a new "~" directory in the working directory. I'm wasn't aware something like that could be done (if that's what happened).

More important than how it got there is how I should get rid of it. I can't remove the directory, because as far as I can tell it is my home directory. It doesn't appear to be a sym-link, (at least not according to ls -l), but I'm not sure what that would even really mean.


You need to quote it to protect it from shell expansion.

ls ~    # list your home directory
ls "~"  # list the directory named ~
ls \~   # list the directory named ~

Same thing with rm, rmdir, etc. The shell changes ~ to /home/greg before passing it to the commands, unless you quote or escape it. You can see this with echo:

anthony@Zia:~$ echo ~
anthony@Zia:~$ echo \~

You'll want to be careful, because rm -Rf ~ would be a disaster. I suggest if at all in doubt, first rename it (mv -i \~ newname) then you can examine newname to make sure you want to delete it, and then delete it.

| improve this answer | |
  • Also: ls ./~ # list the directory named ~ – glenn jackman Mar 25 '14 at 19:02
  • Ah yes, this seems to explain it, thanks! – Greg L Mar 25 '14 at 20:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.