-1

Inside the Ubuntu docker container, cd /home and cd ~ are pointing to different locations.

cd ~ is going to /root folder while cd /home is going to /home. But in general ~ is synonymous with the home directory in Ubuntu. But why is it different in the Ubuntu docker container?

2 Answers2

1

You are root and root's home is in /root. You can check it in /etc/passwd. You would get the same behavior on native installation.

1

cd ~ changes to the home-directory of the actual user. Where the home-directory is, is configured in the passwd-map (or -file (/etc/passwd)).

If you're working as root, cd ~ brings you to the home-directory of the user root. Which is /root in most cases.

If you're working as user1 and that users home-directory is defined as /home/user1 in /etc/passwd/, cd ~ brings you to /home/user1.

~[user] is just some shell-shortcut (in bash and some other shells, not all of them). If you leave out the user, internally the actual user is substituted.

So, as root you could do cd ~user1 and that would change the directory to /home/user1.

rathier
  • 386