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'
MightyPork
  • 1,222
  • 11
  • 21
  • This is called [`tilde expansion`](http://www.gnu.org/software/bash/manual/html_node/Tilde-Expansion.html); 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](http://unix.stackexchange.com/q/146671) – don_crissti Dec 12 '14 at 00:45

1 Answers1

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.

michas
  • 21,190
  • 4
  • 63
  • 93
  • 1
    Oh, that's odd. Any clue *why* there is such user? – MightyPork Dec 11 '14 at 21:45
  • @MightyPork Read [The Advanced Bash Scripting Guide - Non Interactive Shells](http://www.tldp.org/LDP/abs/html/intandnonint.html). IIRC bin happens to be a non-interactive user. – eyoung100 Dec 11 '14 at 22:22