Standard directories in linux

Standard and/or common directories on Unix/Linux OSes

et cetera. Even if I had no idea what these folders did, I could guess with good accuracy from their names.

Now I’m taking a good look at Linux, and getting quite confused about how to find my way around the file system.

  • /bin contains binaries. But so do /sbin , /usr/bin , /usr/sbin , and probably more that I don’t know about. Which is which?? What is the difference between them? If I want to make a binary and put it somewhere system-wide, where do I put it?
  • /media contains external media file systems. But so does /mnt . And neither of them contain anything on my system at the moment; everything seems to be in /dev . What’s the difference? Where are the other partitions on my hard disk, like the C: and D: that were in Windows?
  • /home contains the user files and settings. That much is intuitive, but then, what is supposed to go into /usr ? And how come /root is still separate, even though it’s a user with files and settings?
  • /lib contains shared libraries, like DLLs. But so does /usr/lib . What’s the difference?
  • What is /etc ? Does it really stand for «et cetera», or something else? What kinds of files should go in there — global or local? Is it a catch-all for things no one knew where to put, or is there a particular use case for it?
  • What are /opt , /proc , and /var ? What do they stand for and what are they used for? I haven’t seen anything like them in Windows*, and I just can’t figure out what they might be for.

If anyone can think of other standard places that might be good to know about, feel free to add it to the question; hopefully this can be a good reference for people like me, who are starting to get familiar with *nix systems.

*OK, that’s a lie. I’ve seen similar things in WinObj, but obviously not on a regular basis. I still don’t know what these do on Linux, though.

Thanks for keeping a good spirit of learning. This topic is often contentious. See my answer to this question for some extra explanations about the fundamental differences between file system structures in Windows vs Linux.

Don’t think of «usr» as the abbreviation of «user» but «Unix System Resources» (even if it’s probably a backronym since it did contain users’ directories years ago) (linux-training.be/files/books/html/fun/ch09s08.html).

There’s no use trying to justify Unix/Linux/etc’s cryptic directory naming against Windows (Or Mac OS X). It’s just how it is.

As of 2017, the Windows folder structure is a complete mess. C:\Program Files , C:\ProgramData , %HOME%\AppData\Local , %HOME%\AppData\LocalLow , C:\Windows\SystemApps . All examples where one can find executables in Windows. And I will not even talk about configuration files & the registry, I don’t want to get even more depressed. PS: I work primarily in Windows.

3 Answers 3

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.
Читайте также:  Установка kes 11 astra linux

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.

Good overview addressing the specific questions. Note that some distros use /home/users/username for users and /home/services/servicename for what you mention /src being for. I think this works out better in that it’s more versatile to partition. You can have it on it’s own partition or use the same partition and your user data, which is often what I want to do.

/usr should contain files specific to the applications being on the operating system and/or third-party files. It is not intriniscally sharable! Although LSB argues for these being kept in /opt. /usr/share on the other hand can contain files which are sharable across machines of different architectures / OS versions. These are all just conventions though! It’s quite possible (though a lot of hard work) to use a completely different structure. There are other conventions though — like Oracle’s Optimal Flexible Architecture

Another thing to keep in mind about Unix is the concept that «everything is a file» (or at least looks like one). For example, the stuff in /proc looks like files and directories, but the contents are really created dynamically by the kernel when you access them. This means that you can use the same tools (ls, cat, etc.) to access this information.

@symcbean From the FHS: «. /usr is shareable, read-only data. That means that /usr should be shareable between various FHS-compliant hosts . «. Obviously some files are architecture dependent, and some distributions expect wildly different directory hierarchies. The solution is to do your homework, like a good Admin 🙂

I won’t answer about what they all mean (others have), but give a little historical context.

Читайте также:  Справочник команд unix linux

First, remember that UNIX is getting close to 40 years old, back in the days of paper tape and 300 baud hard-coded terminals to mainframes (Windows XP system is close to 10 year old). Typing was slow and the need for efficiency in typing outweighed a lot of other considerations. That is the reason for the very short basic commands (i.e. ‘ls’, ‘cat’, ‘cc’, ‘dd’, etc.). The same was with the directory structures. The thought was that if the command is more than three or four characters then the name was too long.

The /usr directory originally contained user’s home directories since most of the commands were in /bin and all the device files were in /dev. Later it was thought to make the primary drive (the root filesystem, ‘/’) small for faster boot times. So other structures like /usr/bin, /usr/include and /usr/lib came about, where /usr was a separate «drive». Much later, it was thought to have user’s home directories in /home, yet another drive. And much later than that, to have a /var (short for variable/changable). The /etc directory did mean ‘et cetera’ since that was the catch-all location of all the system configuration files. The /mnt was used as a temporary place to access a drive (often a backup drive). Directories like /opt, /proc and /media came much much later.

There is a lot that is left out (like /usr/local and /net), but this gives a brief description of why the names are ‘less intuitive’.

Источник

LinuxFilesystemTreeOverview

Ubuntu (like all UNIX-like systems) organizes files in a hierarchical tree, where relationships are thought of in teams of children and parent. Directories can contain other directories as well as regular files, which are the «leaves» of the tree. Any element of the tree can be referenced by a path name; an absolute path name starts with the character / (identifying the root directory, which contains all other directories and files), then every child directory that must be traversed to reach the element is listed, each separated by a / sign.

A relative path name is one that doesn’t start with /; in that case, the directory tree is traversed starting from a given point, which changes depending on context, called the current directory. In every directory, there are two special directories called . and .., which refer respectively to the directory itself, and to its parent directory.

The fact that all files and directories have a common root means that, even if several different storage devices are present on the system, they are all seen as directories somewhere in the tree, once they are mounted to the desired place.

FilePermissions are another important part of the files organization system: they are superimposed to the directory structure and assign permissions to each element of the tree, ultimately decided by whom it can be accessed and how.

Examples

An absolute path name, pointing to what is normally an executable file on an Ubuntu system:

An absolute path name, but pointing to a directory instead of a regular file:

A relative path name, which will point to /usr/bin/test only if the current directory is /usr/:

Читайте также:  Uefi usb boot linux

A relative path name, which will point to /usr/bin/test if the current directory is any directory in /usr/, for instance /usr/share/:

A path name using the special shortcut ~, which refers to the current user’s home directory:

Path names can contain almost any character, but some characters, such as space, must be escaped in most software, usually by enclosing the name in quotation marks:

"~/Examples/Experience ubuntu.ogg"

or by employing the escape character \:

~/Examples/Experience\ ubuntu.ogg

Main directories

The standard Ubuntu directory structure mostly follows the Filesystem Hierarchy Standard, which can be referred to for more detailed information.

Here, only the most important directories in the system will be presented.

/bin is a place for most commonly used terminal commands, like ls, mount, rm, etc.

/boot contains files needed to start up the system, including the Linux kernel, a RAM disk image and bootloader configuration files.

/dev contains all device files, which are not regular files but instead refer to various hardware devices on the system, including hard drives.

/etc contains system-global configuration files, which affect the system’s behavior for all users.

/home home sweet home, this is the place for users’ home directories.

/lib contains very important dynamic libraries and kernel modules

/media is intended as a mount point for external devices, such as hard drives or removable media (floppies, CDs, DVDs).

/mnt is also a place for mount points, but dedicated specifically to «temporarily mounted» devices, such as network filesystems.

/opt can be used to store additional software for your system, which is not handled by the package manager.

/proc is a virtual filesystem that provides a mechanism for kernel to send information to processes.

/root is the superuser’s home directory, not in /home/ to allow for booting the system even if /home/ is not available.

/run is a tmpfs (temporary file system) available early in the boot process where ephemeral run-time data is stored. Files under this directory are removed or truncated at the beginning of the boot process.
(It deprecates various legacy locations such as /var/run, /var/lock, /lib/init/rw in otherwise non-ephemeral directory trees as well as /dev/.* and /dev/shm which are not device files.)

/sbin contains important administrative commands that should generally only be employed by the superuser.

/srv can contain data directories of services such as HTTP (/srv/www/) or FTP.

/sys is a virtual filesystem that can be accessed to set or obtain information about the kernel’s view of the system.

/tmp is a place for temporary files used by applications.

/usr contains the majority of user utilities and applications, and partly replicates the root directory structure, containing for instance, among others, /usr/bin/ and /usr/lib.

/var is dedicated to variable data, such as logs, databases, websites, and temporary spool (e-mail etc.) files that persist from one boot to the next. A notable directory it contains is /var/log where system log files are kept.

LinuxFilesystemTreeOverview (последним исправлял пользователь sydneypacific-seven-seventeen 2016-01-04 14:38:17)

The material on this wiki is available under a free license, see Copyright / License for details
You can contribute to this wiki, see Wiki Guide for details

Источник

Оцените статью
Adblock
detector