/bin
everyday commands→ usr/bin/bin is where the everyday commands are found. The name is short for binaries — programs ready to run. ls, cp, cat and the shell itself are all here, and on a current system /bin is simply a link that points at /usr/bin.
Type a command, and the shell finds it here.
Why it exists
Every directory at the top of the tree is there for a reason. This is the problem /bin solves.
On early Unix machines /usr was a separate disk, mounted late. /bin held the few commands needed to boot and to repair the system before that disk was available.
Modern systems mount everything early, so the split no longer helps. /bin was merged into /usr/bin and left behind as a link, so that scripts beginning #!/bin/sh still work.
The shell searches the directories listed in the PATH variable. /usr/bin is on that list, which is why ls runs without typing its full path.
What you find inside
Not everything, but the entries worth recognising. Each is marked as a directory, a file, a link or a device.
- bashfileThe shell that reads what you type.
- lsfileLists the contents of a directory.
- cpfileCopies files and directories.
- catfilePrints the contents of a file.
- grepfileFinds the lines in a file that match a pattern.
- shlinkA link to the system’s default script shell.
At the terminal
Four commands that show what this directory is doing on a real machine.
ls -ld /binShow that /bin is a link, and where it points.
echo $PATHList the directories the shell searches for a command, in order.
which bashShow the full path of the program a command name runs.
file /bin/lsShow what kind of file a command is — a compiled program or a script.
Handle with care
What goes wrong here, and what someone securing or attacking the machine looks at.
Personal scripts belong in ~/bin or ~/.local/bin, and system-wide ones in /usr/local/bin. Files placed in /bin get mixed up with the system’s own.
An attacker who replaces ls or ps can hide files and processes. Package tools such as dpkg --verify or rpm -V compare the installed files against what the package shipped.