The /etc/shells says it has zsh installed in /bin/zsh, but also in /usr/bin/zsh.
<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5c3e2e3b2e1c39322a256d6b">[email protected]</a>:~$ cat /etc/shells # /etc/shells: valid login shells /bin/sh /bin/dash /bin/bash /bin/rbash /usr/bin/tmux /usr/bin/screen /bin/zsh <-- /usr/bin/zsh <--
Now, the internet suggests me to use the one from /usr/bin/.
My question is: why? What is the difference between these two and why is bash for example only intalled at one path (/bin/bash)?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
The contents of /etc/shells are more or less static and have nothing to do with the the presence of specific shells installed on a system.
The fact that there are two entries in your /etc/shells means only that if a user has either /bin/zsh or /usr/bin/zsh specified as their shell in /etc/passwd, both of them would be considered ‘valid’ by daemons that consult /etc/shells (eg. most FTP daemons).
To see the first available zsh in your path ($PATH) you can use the which command like this:
which zsh
Or whereis, which displays more information (the binary, source, and manual page files for a command):
whereis zsh
Method 2
One is probably a symlink (or hard link) to the other…..but they are the SAME file.
Method 3
When /bin/zsh exists, the redundant existence of /usr/bin/zsh has mostly the purpose of portability in the sense that you don’t need to edit each and any scripts’ shebang line, which, when using zsh, will likely address /usr/bin/zsh.
zsh is not considered a standard software, but many and ever more people are using it, even hardcore system administrators. And that’s why more distributions tend to place it in /bin/zsh as well.
To come to the point: it is not a zsh issue, but a feature that ought to guarantee to boot a Linux (or historically, Unix) system into a defined state.
/bin is defined to reside in the root file system, while /usr/bin is not.
For the latter (among others), options include to have it on another disk (partition) or even on another machine, and mounted via NFS or other networking means.
So when booting a system without network support, or in case the network goes down accidentally, or when a disk crashes or a file system is corrupted, or just booting into single user mode without mounting anything, the files in /bin are still accessible.
The same applies to /lib and /usr/lib: in fact, anything beyond /usr is considered to not be vital for the basic system (also X11 is usually found somewhere in the /usr branch. And that’s also the reason why root’s $HOME is not /home/root, since /home is also considered to not reside in the root file system.
And if the system disk crashed? Or the root file system is corrupted? Well, then chances are that you can’t even load the kernel…
Much of the above is not too critical for today’s systems. NFS mounted /usr/* file systems are unnecessary, since disk space is cheap and available in vast amounts.
Even OS images are installed to a separate /boot file system in many installations, so that loading the kernel doesn’t guarantee to be able to mount the root file system, but for that we have initrd these days, which holds a working initial root file system for kernel startup (in which, in fact, zsh will be missing in most cases).
It’s also common practice to have a big root file system that includes the /usr branch, which has some advantages when cloning installations.
So, the traditional considerations that led to the distinction of /bin and /usr/bin (and the like) are a bit out of date, but are still implemented in recent systems.
(this was more an aside, but these are the facts)
Method 4
$ ls -li /bin/zsh /usr/bin/zsh 19401918 -rwxr-xr-x 1 root root 861568 Feb 4 2019 /bin/zsh 19401918 -rwxr-xr-x 1 root root 861568 Feb 4 2019 /usr/bin/zsh
Matching i-nodes means they are hard-linked.
Method 5
For compatibility reasons. Some scripts use /usr/bin others use /bin. Several distros wish to move everything to /usr/bin since there’s not much point in having /sbin and /bin anymore. One of the exceptions is bash, since #!/bin/bash has been used in countless scripts over the last decades, so providing /bin/bash for compatibility, with a symlink, is a good solution for now.
Method 6
they may be the same (check file sizes with ls -l) or /bin/zsh may be an static linked version
in my debian jessie booth are the same but i could play with update-alternatives to make /bin/sh a link to /bin/zsh-static
in case my system is missing any zsh link dependency i would be able to login if my shell is /bin/zsh (if it is linked to /bin/zsh-static)
this practice is the norm on solaris systems, where /bin/ksh is a lightweight version of korn shell, where the heavy all-the-features version lives on /usr/bin/ksh
/usr/bin precedes /bin/ in the path so if you don’t specify which one you want you get the better shell by default
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0