Introduction
Technically, you can put executable files anywhere you want. These directories are just conventions, but following them is a good idea—nobody wants a messy system, especially on Linux.
Priority
These bin directories in Linux all store commands. If there are executables with the same name in different directories, the execution order is determined by priority. You can check your $PATH environment variable to see this priority:
| |
Paths are separated by :. The earlier a path appears in the list, the higher its priority.
/bin
Essential system commands. bin is short for binary. This directory contains fundamental executables required for the system to run, such as: cat, cp, chmod, df, dmesg, gzip, kill, ls, mkdir, more, mount, rm, su, tar, etc.
/usr/bin
Executables pre-installed by the system that may change during system updates.
It also contains execution scripts for software installed later. It mainly houses essential executables for applications and tools like: c++, g++, gcc, chdrv, diff, dig, du, eject, elm, free, gnome*, gzip, htpasswd, kfm, ktop, last, less, locale, m4, make, man, mcopy, ncftp, newaliases, nslookup, passwd, quota, smb*, wget, etc.
/usr/local/bin
The place for users to put their own executables. It’s recommended to use this directory because system updates won’t overwrite files here that share names with system defaults.
/sbin
Short for “Superuser bin.” It contains essential programs for system administration, such as: cfdisk, dhcpcd, dump, e2fsck, fdisk, halt, ifconfig, ifup, ifdown, init, insmod, lilo, lsmod, mke2fs, modprobe, quotacheck, reboot, rmmod, runlevel, shutdown, etc.
/usr/sbin
Contains system administration programs installed by the user or the distribution, such as: dhcpd, httpd, imap, in.*d, inetd, lpd, named, netconfig, nmbd, samba, sendmail, squid, swap, tcpd, tcpdump, etc.