The single most important distinction you have to understand to figure this out is the difference between root and normal (unprivileged) users. For the most part, unprivileged users are the ones that actually use the computer to get their work done (the computer and its OS serves them). The root user is needed to manage and maintain the computer; they don't use the computer to get their work done, but they work to keep the computer functioning. (There are exceptions to this rule: sometimes one has to be root to use the computer, for example when using low-level hardware.)
Is /usr/ just for the users files
What the
hier(7) page doesn't explain:
/usr is not actually for normal user's files. On the contrary, the files in there are not modified by normal users. Normal user files go into their home directories, which are typically in
/usr/home or in
/home (both traditions exist, as do a few others).
and /bin is for executables?
Yes,
/bin does contain executables. But there are many other directories that also do, including:
/sbin,
/usr/bin and
/usr/sbin,
/libexec and
/usr/libexec, and so on.
Is there a directory for all the hardware like the modem and usb devices?
At one level, a modem and a USB device is a device, and therefore will have a device entry in the
/dev file system. Those device entries are files in a directory (as you said above, nearly everything in Unix is a file), but they are not regular files whose content is stored in the file system itself. Instead, they are special files (a category that also includes a few other things like named pipes), which simply tell the kernel that when a user accesses this file, to instead use the underlying hardware device. In modern Unixes (including FreeBSD), the entries in
/dev don't have to be manually created and deleted by the system administrator (like we used to do 15 or 25 years ago), but automatically come into existence as the kernel discovers devices.
At another level, a USB storage device (the typical memory stick) is not just a device with a device entry (typically called
/dev/da0s1), but also contains a file system. That file system can be mounted, either manually or by an auto-mounter, typically on the
/media mount point. So another concept one has to understand is the distinction between a device, and the file system contained on the device.
And then finally there is one more concept, probably the fuzziest distinction of them all: The difference between software that is installed as part of the basic operating system distribution, which goes into a whole bunch of directories, with the bulk in
/usr, but never in
/usr/local, and other stuff:
- Optional software packages that are installed after the base operating system, for example using the port and package system in FreeBSD for freely available software, and similar distribution mechanisms (such as pip for Python), which goes into /usr/local, to be clearly distinguished from the main operating system installation.
- Locally developed software, which typically also goes into /usr/local
- And in the System 5 tradition (from which Linux feeds), some commercial software gets put into /opt, which was initially intended for optional software. There are other common places for installing commercial software, such as /usr/lpp.
These categories are fuzzy and may sometimes seem not very logical: Why are
vi
and
sh
in
/usr/bin, but
emacs
and
bash
in
/usr/local/bin? There are logical answers to that question, but you need to understand history to know them. Let's not get bogged down in these details.
Where it can get really confusing is: If a Unix system is used by a single user to develop software, and the OS installation itself is considered disposable, the distinction between the user's
/home directory,
/usr/local and the OS itself may become fuzzy, as is the distinction between running as root and as an unprivileged user. But it is a very good idea to be really neat there, do as much work as possible as an unprivileged user with the data in
/home, only perform actions as root is absolutely necessary (like to install software, or to test with real-world devices), and clearly distinguish between a development sandbox in
/home and deployed software in
/usr/local.