The bin Directories in Linux

📢 This article was translated by gemini-3-flash-preview

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:

1
2
[yexca@yexca-PC ~]$ echo $PATH
/home/yexca/.local/bin:/home/yexca/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin

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.

References

Linux /usr/bin与/usr/local/bin区别_学亮编程手记的博客-CSDN博客

/bin,/sbin,/usr/sbin,/usr/bin 目录之简单区别_IT农夫的博客-CSDN博客

This post is licensed under CC BY-NC-SA 4.0 by the author.