Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 6 down vote accepted

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 ~
/home/anthony
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.

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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