5

~ is $HOME. For me, cd ~ is /home/cat. Simple so far, yes?

In Bash, the following happens:

cat @ mint-kitty : ~/Downloads $ cd ~ # from /home/cat/Downloads to /home/cat/, as an example, but behaviour happens with any directory cat @ mint-kitty : ~ $ cd ~<TAB>proxy/ # oh? what's this? cat @ mint-kitty : /bin $ cd ~<TAB><TAB> ~ais ~clamav/ ~debian-tor/ ~gitlog ~list ~mixmaster/ ~ntp ~redis/ ~stunnel4 ~systemd-resolve ~uuidd/ ~avahi/ ~cl-builder/ ~dirmngr/ ~gnats ~lp ~monkeysphere/ ~oident/ ~roard/ ~sync/ ~systemd-timesync/ ~vde2-net ~avahi-autoipd/ ~clickpkg ~dnsmasq/ ~irc ~mail/ ~mpd/ ~pdnsd/ ~root/ ~syncache/ ~timidity/ ~whoopsie ~backup/ ~colord/ ~epmd ~jetty/ ~man/ ~muroard/ ~postgres/ ~rtkit/ ~sys/ ~tomcat8 ~www-data/ ~bin/ ~daemon/ ~festival ~libvirt-dnsmasq/ ~mdm/ ~mysql ~proxy/ ~saned ~syslog ~trafficserver ~bind/ ~Debian-exim/ ~games/ ~libvirt-qemu/ ~memcache ~news ~pulse ~speech-dispatcher ~systemd-bus-proxy/ ~uml-net ~cat/ ~debian-spamd/ ~gitdaemon ~lightdm/ ~messagebus/ ~nobody ~radvd ~sshd/ ~systemd-network ~uucp cat @ mint-kitty : /bin $ cd ~systemd-resolve bash: cd: /run/systemd/resolve: No such file or directory 1 | cat @ mint-kitty : /bin $ cd ~redis cat @ mint-kitty : /var/lib/redis $ cd ~clamav cat @ mint-kitty : /var/lib/clamav $ cd ~irc bash: cd: /var/run/ircd: No such file or directory 1 | cat @ mint-kitty : /var/lib/clamav $ cd ~gnats bash: cd: /var/lib/gnats: No such file or directory 1 | cat @ mint-kitty : /var/lib/clamav $ cd ~sshd cat @ mint-kitty : /var/run/sshd $ cd ~nobody bash: cd: /nonexistent: No such file or directory 

Obviously, <TAB> represents the TAB key sending the byte at ASCII 9, not that actual text.

I've left in my PS1 prompt to show the current path and the return codes. My question is, what's the relevance of these directories being autocompleted from ~?

I've created a table of these and where they point, to better understand them (but I'm just more confused now).

thing points-at? =========================================== ~ais ENOENT /home/ais/ # user ais uid=156(ais) gid=163(ais) groups=163(ais) does not have an entry in /home/ ~avahi /var/run/avahi-daemon/ ~avahi-autoipd /var/lib/avahi-autoipd/ ~backup /var/backups/ ~bin /bin/ ~bind /var/cache/bind/ ~cat /home/cat/ ~clamav /var/lib/clamav/ ~cl-builder /usr/share/common-lisp// # two slashes ~clickpkg ENOENT /nonexsistent/ # yes, really ~colord /var/lib/colord/ ~daemon /usr/sbin/ # ?? ~Debian-exim /var/spool/exim4/ # ?? ~debian-spamd /var/lib/spamassassin/ ~debian-tor /var/lib/tor/ ~dirmngr /var/cache/dirmngr/ ~dnsmasq /var/lib/misc/ # ?? ~epmd /var/run/epmd/ ~festival ENOENT /home/festival # user festival uid=131(festival) gid=29(audio) groups=29(audio) does not have an entry in /home/ ~games /usr/games/ # ??? ~gitdaemon ENOENT /nonexistent/ ~gitlog ENOENT /nonexistent/ ~gnats /var/lib/ircd/ ~jetty /usr/share/jetty8/ ~libvirt-dnsmasq /var/lib/libvirt/ ~libvirt-qemu /var/lib/libvirt/ ~lightdm /var/lib/lightdm/ ~list ENOENT /var/list/ ~lp ENOENT /var/spool/lpd/ ~mail /var/mail/ ~man /var/cache/man/ ~mdm /var/lib/mdm/ ~memcache ENOENT /nonexistent/ ~messagebus /var/run/dbus ~mixmaster /var/lib/mixmaster/ ~monkeysphere /var/lib/monkeysphere/ ~mpd /var/lib/mpd/ ~muroard /var/lib/muroard/ ~mysql ENOENT /nonexistent/ ~nobody ENOENT /nonexistent/ ~ntp ENOENT /home/ntp # user ntp uid=107(ntp) gid=114(ntp) groups=114(ntp) does not have an entry in /home/ ~oident / # ???? ~pdnsd /var/cache/pdnsd/ ~postgres /var/lib/postgresql/ ~proxy /bin/ ~pulse ENOENT /var/run/pulse ~radvd ENOENT /var/run/radvd ~redis /var/lib/redis ~roard /var/lib/roard ~root /root ~rtkit /proc ~saned ENOENT /var/lib/saned ~speech-dispatcher ENOENT /var/run/speech-dispatcher ~sshd /var/run/sshd ~stunnel4 ENOENT /var/run/stunnel4 ~sync /bin/ ~syncache /var/run/syncache-drb/ ~sys /dev/ # ??? ~syslog ENOENT /home/syslog # user syslog uid=104(syslog) gid=109(syslog) groups=109(syslog),4(adm) does not have an entry in /home/ ~systemd-bus-proxy /run/systemd/ ~systemd-network ENOENT /run/systemd/netif/ ~systemd-resolve ENOENT /run/systemd/resolve/ ~systemd-timesync /run/systemd/ ~timidity /etc/timidity/ ~tomcat8 ENOENT /usr/share/tomcat8/ ~trafficserver ENOENT /var/run/trafficserver/ ~uml-net ENOENT /home/uml-net/ # user uml-net uid=146(uml-net) gid=155(uml-net) groups=155(uml-net) does not have an entry in /home/ ~uucp ENOENT /var/spool/uucp/ ~uuidd /run/uuidd/ ~vde2-net ENOENT /var/run/vde2/ ~whoospie ENOENT /nonexistent/ ~www-data /var/www 

The thing column is the entry shown by ~<TAB><TAB>. points-at is either the directory thing points to, or the nonexistent place thing points to.

For instance, ~cat gives bash: /home/cat: Is a directory, so ~cat -> /home/cat but ~clickpkg gives bash: /nonexistent: No such file or directory, so ~clickpkg -> ENOENT /nonexistent/.

I've presented all the data I've got. What's going on here? Is ~ being secretly expanded to something?

1 Answer 1

5

A ~user is the $HOME directory for that user.
That's the list of directories in ~ augmented by all this (second column):

awk -F ":" '{printf( "%15s \t %-20s\n",$1,$6)}' /etc/passwd 

From man bash (search for "Tilde Expansion")

Tilde Expansion
If none of the characters in the tilde-prefix are quoted, the characters in the tilde-prefix following the tilde are treated as a possible login name.
... the tilde-prefix is replaced with the home directory associated with the specified login name.

3
  • How interesting. Commented Apr 1, 2016 at 2:08
  • 1
    Note that most of these are "system users". Their home directories often aren't actually used for anything, and sometimes don't even exist. Usually it's just some directory name to fill that space, vaguely related to whatever the user is used for. Commented Apr 1, 2016 at 5:53
  • @Nate I would have been saved a lot of time if I had realised they were all users in the first place; I only bothered checking for the ones where ~user was a nonexistent place in /home/ D: Commented Apr 1, 2016 at 10:50

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.