While both are designed to contain files not belonging to the operating system, /opt
and /usr/local
are not intended to contain the same set of files.
/usr/local
is a place to install files built by the administrator, typically by using the make
command (e.g., ./configure; make; make install
). The idea is to avoid clashes with files that are part of the operating system, which would either be overwritten or overwrite the local ones otherwise (e.g., /usr/bin/foo
is part of the OS while /usr/local/bin/foo
is a local alternative).
All files under /usr
are shareable between OS instances, although this is rarely done with Linux. This is a part where the FHS is slightly self-contradictory, as /usr
is defined to be read-only, but /usr/local/bin
needs to be read-write for local installation of software to succeed. The SVR4 file system standard, which was the FHS' main source of inspiration, is recommending to avoid /usr/local
and use /opt/local
instead to overcome this issue.
/usr/local
is a legacy from the original BSD. At that time, the source code of /usr/bin
OS commands were in /usr/src/bin
and /usr/src/usr.bin
, while the source of locally developed commands was in /usr/local/src
, and their binaries in /usr/local/bin
. There was no notion of packaging (outside tarballs).
On the other hand, /opt
is a directory for installing unbundled packages (i.e. packages not part of the Operating System distribution, but provided by an independent source), each one in its own subdirectory. They are already built whole packages provided by an independent third party software distributor. Unlike /usr/local
stuff, these packages follow the directory conventions (or at least they should). For example, someapp
would be installed in /opt/someapp
, with one of its command being /opt/someapp/bin/foo
, its configuration file would be in /etc/opt/someapp/foo.conf
, and its log files in /var/opt/someapp/logs/foo.access
.
Linux distributions use the FHS: http://www.pathname.com/fhs/pub/fhs-2.3.html
You can also try man hier
.
I'll try to sum up answers your questions off the top of my head, but I strongly suggest that you read through the FHS:
- /bin is for non-superuser system binaries
- /sbin is for superuser (root) system binaries
- /usr/bin & /usr/sbin are for non-critical shared non-superuser or superuser binaries, respectively
- /mnt is for temporarily mounting a partition
- /media is for mounting many removable media at once
- /dev contains your system device files; it's a long story :)
- The /usr folder, and its subfolders, can be shared with other systems, so that they will have access to the same programs/files installed in one place. Since /usr is typically on a separate filesystem, it doesn't contain binaries that are necessary to bring the system online.
- /root is separate because it may be necessary to bring the system online without mounting other directories which may be on separate partitions/hard drives/servers
- Yes, /etc stands for "et cetera". Configuration files for the local system are stored there.
- /opt is a place where you can install programs that you download/compile. That way you can keep them separate from the rest of the system, with all of the files in one place.
- /proc contains information about the kernel and running processes
- /var contains variable size files like logs, mail, webpages, etc.
To access a system, you generally don't need /var, /opt, /usr, /home; some of potentially largest directories on a system.
One of my favorites, which some people don't use, is /srv. It's for data that is being hosted via services like http/ftp/samba. I've see /var used for this a lot, which isn't really its purpose.
Best Answer
Per FHS,
/opt/bin
,/opt/lib
,/opt/info
,/opt/include
,/opt/doc
, and/opt/man
are there for the administrator's convenience. For instance, you might have/opt/jdk
and/opt/LibreOffice
holding your jdk and office suite, but rather than add a new element to$PATH
,ld.so.conf
, etc. every time you add another package, you can just symlink the binaries to/opt/bin
, the libs to/opt/lib
, etc.Basically, you should put the binary in
/opt/foo/bin
and, at your discretion, symlink the binary into/opt/bin
FHS does not specify any particular organization within
/opt/package
, but the widely accepted practice is to make abin
andlib
directory, and possiblydoc
,man
, etc. as needed.As a side note: if you are writing to
/opt/foo
FHS also clears you to write to/etc/opt/foo
and/var/opt/foo
.