Edit: This is a duplicate of https://stackoverflow.com/questions/998626/meaning-of-tilde-in-linux-bash-not-home-directory/. I don't have the reputation to close this question as duplicate.
I'm not referring to ~
as in the home directory but rather this:
$ ls ~foo/bar
/some/mount/point/foo/bar
However if I attempt it with a different mount point, e.g.:
$ mount | ag "/dev "
devfs on /dev (devfs, local, nobrowse)
$ ls /dev/stdin
/dev/stdin
$ ls ~stdin
zsh: no such user or named directory: stdin .
# bash has a similar error message:
ls: ~stdin: No such file or directory
What is the ~
called in this context? How does it work?
Edit: More information based on some of the comments below:
- I can attest that
foo
is not a username on my system. - When attempting to autocomplete
ls -lah ~
not all options are shown. i.e. I'm able tocd ~qux
, whenqux
doesn't show up in the autocomplete. Againqux
is not a user in my system. - If it matters
/some/mount/point
is a network share. - All of the details suggest some named path muckery, a Z shell feature of pathname expansion, but this works in bash as well, which apparently doesn't support things like the Z shell's named paths.
~foo
is the home directory of the userfoo
. If the user is not specified, the current user is the default. – DopeGhoti Feb 13 '18 at 20:30/some/mount/point
definitely isn't my home directory.cd ~
takes me to/Users/$username/
--which matches$HOME
– R.D. Feb 13 '18 at 20:32zsh
appears to also use the tilde to indicate named directories. – DopeGhoti Feb 13 '18 at 20:36bash -c "ls ~foo/bar"
)--which doesn't have named directories. Furthermore even within zsh, if I inspect theenv
, I don't see any named directories set up. I'm on Mac OS and I feel this is some feature specific to OS X. – R.D. Feb 13 '18 at 20:42~foo
. Take the actual string (not the examplefoo
) and dogrep "actual username" /etc/passwd
.~text
should work for only possible login usernames according to bash manual (doesn't necessarily mean it is actually able to log in; in case of system users such as~lp
, for example). In all my tests, the~string
corresponds withstring
being username. – Sergiy Kolodyazhnyy Feb 13 '18 at 21:15foo
is not a user in/etc/passwd
. More details here: https://unix.stackexchange.com/questions/423962/what-is-a-tilde-when-used-as-a-prefix-to-a-path#comment763801_423983. FWIW, I'm being intentionally vague with paths as I see with my work computer and sharing the real path would likely reveal personal info. – R.D. Feb 13 '18 at 22:14/etc/master.passwd
? – Sergiy Kolodyazhnyy Feb 13 '18 at 22:29/etc
for instances offoo
(or similar paths I'm able to access)--no dice – R.D. Feb 13 '18 at 22:57getent
– Sergiy Kolodyazhnyy Feb 14 '18 at 06:10grep -Fr some/mount/point /etc
? [without any foo part, just the mount point itself; it may be listed somewhere as a default location for creating user directories] – Will Crawford Feb 14 '18 at 11:33