0

Today I accidentally typed ls ~bin
I wanted to type ~bak - that's my junk backup folder, but ~b<tab> deceived me.

Instead I got this:

$ ls ~bin
core_perl                             fogcoord                     lftp                           pcmanfm                                 snmpvacm
site_perl                             fold                         lftpget                        

... many miles of output ...

Could anyone kindly explain what the hell happened here? Works also with cd, for example.

There is no such folder (or symlink) in pwd - it's the real /bin. I also tried ls ~etc, but that didn't work.

Here's my ls:

$ alias ls
alias ls='ls --color=auto --group-directories-first -h'
1
  • This is called tilde expansion; so ~bin is a tilde-prefix. If none of the characters in the tilde-prefix are quoted, the characters in the tilde-prefix following the ~ are treated as a possible login name from the user database. See also Does ~ always equal $HOME Dec 12 '14 at 0:45
3

There is a bin user with home /bin:

$ getent passwd bin
bin:x:1:1:bin:/bin:/bin/false

Now ~bin refers to the home directory of the bin user which is /bin and contains all the many miles of commands.

The same way ~etc does not work, because there is no etc user.

2

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.