Filesystem Hierarchy Standard
Sometimes it is difficult to grasp directory structure in Linux/Ubuntu without referring to Filesystem Hierarchy Standard, FHS, which defines directory structure and directory contents in Linux distributions.
In the FHS, all files and directories appear under the root directory /, even if they are physically on different disks or devices.
Binaries and libraries
System scope
-
/binFor binaries usable before the/usrpartition is mounted. This is used for trivial binaries used in the very early boot stage or ones that you need to have available in booting single-user mode.For example: cat, ls, cp. -
/sbinSystem binaries (e.g., fsck, init, route), available forroot -
/libLibraries for the binaries in/binand/sbin.
User scope
-
/usr/binCommand binaries (not needed in single-user mode); for all users. -
/usr/libLibraries for the binaries in/usr/binand/usr/sbin. -
/usr/localIt has subdirectories (e.g., bin, lib, share) for local data specifically for to the host. -
/usr/sbinNon-essential system binaries (e.g., daemons for various network services).
Variable files
-
/varFiles such as logs, spool files, and temporary e-mail files, whose content are continually changed during operation of the system. -
/var/cacheApplication cache data locally generated as during I/O or calculation. -
/var/libState information. Persistent data modified by programs as they run (e.g., databases, packaging system metadata, etc.). -
/var/lockLock files. Files keeping track of resources currently in use. -
/var/logLog files. -
/var/optVariable data from add-on packages that are stored in /opt. -
/var/tmpTemporary files to be preserved between reboots.
Others
-
/Primary hierarchy root and root directory of the entire file system hierarchy. /bootBoot loader files (e.g., kernels, initrd)./devDevice files (e.g., /dev/null, /dev/disk0, /dev/sda1, /dev/tty, /dev/random)./etcHost-specific system-wide configuration files./etc/optConfiguration files for add-on packages that are stored in /opt.-
/homeUsers’ home directories, containing saved files, personal settings, etc. -
/mediaMount points for removable media such as CD-ROMs (appeared in FHS-2.3 in 2004). -
/optAdd-on application software packages. -
/rootHome directory for the root user. /sysContains information about devices, drivers, and some kernel features.-
/tmpDirectory for temporary files (see also /var/tmp), and they are not preserved between system reboots and can be size-restricted. -
/usrSecondary hierarchy for read-only user data; contains the majority of (multi-)user utilities and applications. Should be shareable and read-only. /usr/includeStandard include files.
Where should I put my script ?
The answer is none of the above. I suggest to use /usr/local/bin to make available for system-wide unless I use ~/bin for user scoped script. The script and its data are located under personal home directory.
Under /usr/local there are potentially more subdirectories to accommodate libraries or data, e.g., /usr/local/bin, /usr/local/lib, /usr/local/share.