How are directories structured in GNU / Linux?

Linux folders

Many of us learned to use our computer thanks to some version of Windows. One of the first skills they teach us (or at least that's how it happened to me) is to manage our information contained in our equipment, whether on the hard drive or removable media (I still remember my teachers taking exams about how to move, copy, create, organize and locate files and folders within the system, those guys really got tiresome with the Win 3.1 XD file manager).

This time we will see how the directory hierarchy in GNU / Linux. It is true that it is not extremely necessary to know it 100%, but believe me that it will make your life much easier to have an idea of ​​it;).

I intend this article to serve the dual purpose of being a quick access guide, as well as being a reference guide for future reference. For this, the information that, I believe, is more "Specialized" it is in a more subdued color to try and facilitate quick reading.

General structure of the directories

In the UNIX file system (and the like, such as GNU / Linux), there are several sub-hierarchies of directories that have multiple and different storage and organization functions throughout the system. These directories can be classified into:

<° Static: It contains files that do not change without the intervention of the administrator (root), however, they can be read by any other user. (/ bin, / sbin, / Opt, / Boot, / usr / bin

<° Dynamic: It contains files that are changeable, and can be read and written (some only by their respective user and root). They contain settings, documents, etc. (/ var / mail, / var / spool, / var / run, / var / lock, / Home

<° Shared: It contains files that can be found on one computer and used on another, or even shared between users.

<° Restricted: It contains files that cannot be shared, they are only modifiable by the administrator. (/ Etc, / Boot, / var / run, / var / lock

root: is the conventional name of the user account that has all rights in all modes (single or multi user). Root is also called superuser. Usually this is the administrator account. The root user can do many things that a common user cannot, such as changing file owners or permissions and bind to small number ports. It is not recommended to use the root user for a simple session of regular use, since it puts the system at risk by guaranteeing privileged access to each running program. It is preferable to use a normal user account and use the su command to access root privileges if necessary.

This structure is represented in the form of a tree, as shown in the following image:

directory tree

where the root of the tree/) is the base of the entire directory structure and branches (directories and files) arise or hang from said base.

 Directory tree structure in GNU / Linux

Some Linux distributions make modifications to the directory tree structure, to suit their own needs. Anyway the standard is the following:

hierarchy files

This is how it looks on my computer (even in the desktop screenshots I reflect my XD metal spirit):

File System

Enough of the detours and let's dive into the subject ...

Description of the edirectory tree structure

root

 

<° / (root): Similar to the root directory "C: \”Of the DOS and Windows operating systems. It is the highest level within the directory hierarchy, it is the container for the entire system (access to the file system, including removable disks [CD's, DVD's, pen drives, etc.]).

bin

<° / bin (binary): Binaries are Linux executables (similar to files .exe Windows). Here we will have the executables of the operating system's own programs.

boat

<° / boot (boot): Here we find the files needed to start Linux, from the bootloader configuration files (Grub - Lilo), even his own kernel of the System.

Boot loader: it is a simple program (which does not have all the functionalities of an operating system) exclusively designed to prepare everything that the operating system needs to function.

Core or kernel: it is software that is the most important part of the operating system. It is the main person responsible for providing the different programs with secure access to the computer hardware or in a basic way, it is in charge of managing resources, through system call services.

giant

<° / dev (devices): This folder contains system devices, even those that have not been assigned (mounted) a directory, for example microphones, printers, pen drives (USB sticks) and special devices (for example, / Dev / null). Linux treats devices as if they were one more file to facilitate the flow of information.

/ dev / null or null device (null peripheral): it is a special file that discards all the information that is written or redirected in it. In turn, it does not provide any data to any process that tries to read from it, simply returning an EOF or end of file. The most commonly used way is by redirection, since / dev / null is a special file and not a directory; therefore, you cannot move (mv) or copy (cp) files inside.

etc

<° / etc (etc.): The configuration files of the installed programs are stored here, as well as certain scripts that are executed at system startup. The values ​​of these configuration files can be complemented or replaced by the user configuration files that each one has in their respective "home" (personal folder).

  • / etc / opt / Configuration files for programs hosted within the directory / Opt.
  • / etc / X11 / Configuration files for the X Window System, version 11.

X: It is in charge of displaying the graphic information completely independent of the operating system.

  • / etc / sgml / Configuration files for SGML.

The SGML language: It consists of a system for the organization and labeling of documents. It is used to specify the rules for tagging documents and does not impose any special tag set itself.

  • / etc / xml / Configuration files for XML.

XML: It is an extensible tag metalanguage developed by the World Wide Web Consortium (W3C). It is a simplification and adaptation of the SGML. It is easier to implement as it avoids some advanced SGML features.

home

<° / home (home): Here are the user configuration files as well as the user's personal files (documents, music, videos, etc.), except for the superuser (administrator, root) which has a separate directory. Similar to "My Documents" in Windows.

lib

<° / lib (libraries): It contains the essential shared libraries (poorly known as libraries) of the hosted programs, that is, for the binaries in / bin / y / sbin /, the libraries for the kernel, as well as modules and drivers.

medium

<° / mean (mean / means): It contains the mounting points of the removable storage media, such as CD-ROM readers, Pendrives (USB memory), and even serves to mount other partitions of the same hard disk, such as a partition that is used by another system operational.

mnt

<° / mnt (mounts): This directory is typically used for temporary drive mounts. It is a directory similar to / media, but it is used mostly by users. It is used to temporarily mount hard drives and partitions on the system; you don't need a password, unlike the / media directory.

opt

<° / opt (optional): It contains optional program packages for static applications, that is, they can be shared between users. These applications do not save their settings in this directory; In this way, each user can have a different configuration of the same application, so that the application is shared but not the user configurations, which are saved in their respective directory in / Home.

proc

<° / proc (processes): It mainly contains text files, virtual file systems that document the kernel and the status of the processes in text files (eg uptime, network).

root

<° / root (administrator): It is the / home of the administrator (only for him). It's the only one / Home which is not included -by default- in the aforementioned directory.

sbin

<° / sbin (system binaries): Special binary system, commands and programs unique to the superuser (root), for example, init, route, ifup, such as mount, umount, shutdown). A user can run any of these command applications, if they have sufficient permissions, or if they have the superuser password.

srv

<° / srv (services): System information about certain services it offers (FTP, HTTP ...).

tmp

<° / tmp (temporary): It is a directory where temporary files are stored (for example: by the internet browser). Every time the system is started this directory is cleaned.

usr

<° / usr (users): Secondary hierarchy of user data; It contains most of the utilities and multi-user applications, that is, accessible to all users. In other words, it contains the files that are shared, but are nonetheless read-only. This directory can even be shared with other computers on the local network.

  • / usr / bin: Set of executables (non-administrative for all users) of most desktop applications among others (for example firefox). They are read-only, but can have their own settings for each user in / home. Some executables share the same libraries as other applications, so generally there are no two identical libraries on the same system, which saves memory and provides more order.
  • / usr / include: The header files for C and C ++.
  • / Usr / lib: Libraries for C and C ++.
  • / usr / local: It is another level within that offers a hierarchy similar to the directory itself / Usr.
  • / usr / sbin: Non-essential binary system; for example, daemons for various network services. That is, it contains programs that do not provide a user interface and generally run at system startup or under certain circumstances. They are not directly managed by the user while they are running, although they can be configured before they are run.
  • /usr/share: Shared files such as configuration files, images, icons, themes, etc.
  • / usr / src: Source codes of some applications and the Linux kernel. Like / mnt, this folder is managed by users directly so that they can save in it the source code of programs and libraries and thus can access it easily, without problems with permissions. It allows the source code to have its own space, accessible but away from all users.
  • / usr / X11R6 / X Window System, Version 11, Release 6. This directory is related to the graphical environment.

var

 

<° / var (variables): Variable files, such as logs, spool files, databases, temporary e-mail files, and some temporary files in general. It generally acts as a system registry. Help to find the origins of a problem.

  • / var / cache: Applications cache, although the / tmp directory is also used for the same.
  • / var / crash / Data and information are deposited, referring to the crashes or errors of the operating system. It is more specific than / var in general.
  • / var / games / Variable data from system games. This directory is not essential and is often omitted by game applications themselves, since they use the user folder in / Home to save variable data as configurations, for example. Anyway, gnome games use this directory.
  • / var / lib: Information on the current state of the applications, modifiable by the applications themselves.
  • / var / lock: Files that ensure that a resource is only used by a specific application that has requested its exclusivity, until it is released.
  • / var / log: It is one of the most important subdirectories since all kinds of system logs are stored here.
  • / var / mail: Mailbox or messages from users. If you do not use encryption, then the personal folder is generally used for the same work by programs that handle e-mails.
  • / var / opt: Data used by packages stored in / Opt.
  • / var / run: Recent information. It deals with the operation of the system since the last boot. For example, the currently registered or logged users, who have entered; and the demons that are running.
  • / var / spool: Tasks waiting to be processed (for example, print queues and unread mail).
  • / var / tmp: Temporary files that, unlike / Tmp, they are not deleted between sessions or system restarts, but they are nevertheless dispensable.

<° / sys (system): Contains configuration parameters of the running system. Data referring to the kernel, bus, devices, firmware, fs (filesystem) and others.

<° / lost + found: On Unix systems, each of the partitions / filesystems has a directory called / lost + found in which files and directories (or remnants of them) recovered after a review of the file system through the fsck tool are stored, all of this usually caused by system crashes, forced shutdowns of the computer, power outages, etc.

All those files and directories recovered after a fsck are stored with the following structure in the directory / lost + found, the name of each file is the inode number:

drwxr-xr-x 3 root root 4096 2010-03-12 09:38 # 123805
drwxr-xr-x 3 root root 4096 2010-03-12 09:38 # 125488
drwxr-xr-x 3 root root 4096 2010-03-12 09:38 # 135836
-rw-r – r– 2 root root 2473 2010-03-02 16:03 # 137864
-rw-r – r– 2 root root 18505 2010-03-02 16:03 # 137865
-rw-r – r– 2 root root 56140 2010-03-02 16:03 # 137866
-rw-r – r– 2 root root 25978 2010-03-02 16:03 # 137867
-rw-r – r– 2 root root 16247 2010-03-02 16:03 # 137868
-rw-r – r– 2 root root 138001 2010-03-02 16:03 # 137869
-rw-r – r– 2 root root 63623 2010-03-02 16:03 # 137870
-rw-r – r– 2 root root 34032 2010-03-02 16:03 # 137871
-rw-r – r– 2 root root 2536 2010-03-02 16:03 # 137872

These files may be corrupt or incomplete, but we may be lucky and find what we thought was lost after fsck. We will have to review the files and directories one by one because the file name has been lost. It can be a difficult task to go through all the files and directories and try to put them back in their place, in some cases it can be practically impossible.

fsck (file system check or file system consistency check): is a utility whose function is to solve inconsistencies in the file system, since it corrects possible errors in the system. fsck runs automatically at system startup on failure, but can also be used manually by the system administrator to force a check.

So you know, study it well, that for tomorrow there is an XD exam ...

Sources:

Wikipedia

http://tuxpepino.wordpress.com/2008/01/09/jerarquia-directorios-gnulinux/


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   David Segura M. said

    Very useful for me to find out in a little more detail what the Linux organization is like, thanks!

    1.    jose said

      Can you help me in which folders the user passwords are stored in Ubuntu

      1.    Joaquin JH said

        / Etc / shadow
        but the displayed passwords will appear encrypted

  2.   proper said

    wooooow !!
    Excellent work @Perseo

  3.   nerjamartin said

    Congratulations Perseus, great job !! 🙂

  4.   Oscar said

    Excellent tuto, it would be very good, within your possibilities, to put it in PDF within the forum in Tutorials. +1.

    1.    David Segura M. said

      You can always use http://www.printerfriendly.com for it

  5.   Marco said

    +10 !!!! fabulous, i just bookmarked the item. clear explanation of Linux structure. I did not know many of these things !!!!

    1.    elav <° Linux said

      Perseus is true. Excellent article 😀

    2.    KZKG ^ Gaara said

      Honestly, I also learned a lot from this article ... amazing how well explained it is, perseus he really has a gift for this O_O

      1.    Courage said

        Already clear

  6.   electron22 said

    Excellent, thank you very much 😀

  7.   perseus said

    Thank you all for your comments 😀

    1.    electron22 said

      You cannot make a PDF this information must be shared 😀

      1.    perseus said

        Of course we will, just give me a little space (I have received some work lately: D) and I will gladly do it 😉

        1.    electron22 said

          I will be pending 😀

  8.   Chango said

    The explanation is excellent. Very good article.

  9.   Yoyo said

    Unbeatable 😉

  10.   Carlos-Xfce said

    Thank you very much for this article, Perseus. This type of information greatly enriches the blog, since it is not only about news or showing how to configure something, but about learning more about our operating system. Without a doubt now I know a little more about things that I always wanted to know when I was faced with those "rogue" files that would not let me make changes because I was not "root", ha ha ha.

    1.    perseus said

      Thank you very much for commenting friend, we will try to continue improving: D.

      PS: Sorry for the delay, but I'm testing other distros 😉 for my computer.

  11.   jelpassenger said

    Do you know of any command that forces an application outside the system to install itself in opt instead of the file system?

  12.   arthur molina said

    It is very well explained, I finally understood why when I used Slax's live cd, based on Slackware, I mounted things in mnt and not in media. Regards.

  13.   wibort said

    Excellent article, very complete, thanks for the contribution.

    PS. Sonata Rules! 😛

  14.   Roy said

    Very good. Thanks for the investment.

  15.   jeodriht said

    Very good article, thank you very much for the information!

  16.   jeronimosteel said

    Hello, it is possible to download this guide in pdf or doc to print so I can read it calmly anywhere, if possible, give me the link, bye thank you very much

    1.    KZKG ^ Gaara said

      Hey.
      You can print directly through the same browser, or you can save this page (File-Save) and then print it at home.

      I hope I have helped you 😉
      Greetings and welcome to the blog.

  17.   benybarba said

    the truth is the best documented and summarized that I have seen congratulations to the creator of this article

  18.   oscar said

    Thank you for the contribution!!! It comes in handy to find out what's going on!

  19.   can said

    The / dev / directory is full of files, which point to devices "not drives" (serial port, parallel, physical or virtual disk drives ... blah, blah, blah) for the rest, very good!

  20.   Belen said

    Hello, very good, all of you, on the recommendation of a friend I came to this beautiful website and learn more about Linux, I still have many doubts is that I think I have been used to using windows, but when I saw my friend's computer I was surprised and by I would like to know more.

    Guys know in windows there are logical partitions (disk C, disk D) in Linux how can I do that because look in windows if something happened I deleted the C and through a backup that I had saved in the D I could recover it instead in Linux I don't know how it is I am totally lost.

    Well I hope you help me please, I like Linux and I would like you to help me.

    bye

    1.    elav said

      Hello Belen:

      Well, the first and fundamental thing is to want to learn, and apparently you have that to spare. My advice is that you start reading this article and the links that you can find in it.

      However, to do the same as in Windows the thing is relatively easy, you just have to separate the partition for the / Home. But as I was saying, if you have no idea of ​​the File System in GNU / Linux, I think you should start with that article 😉

      1.    Belen said

        Thank you very much, good you know as far as I could read, I just found out that they are distributions, I am really liking kubuntu, I saw others but the name seems nice to me> .. <I will start to take my first steps 🙂 thanks repeatedly, I will comment on how I am doing with Linux.

        bye 🙂

        1.    elav said

          Very good choice ^ _ ^

  21.   konzentrix said

    Very good tutorial, yes sir. It shows that you have worked it out. For those who do not understand much it will be of great help and for those of us who are more placed it serves as a good pleasant reminder to read.

  22.   Goku said

    Good morning, I really liked your article. I have a doubt:
    How can I save files to the root directory? Is that / home is already full and I want to know if the / directory can be used to have more space, there is more than 20 Gb that I want to take advantage of. I would not like to have to resize partitions. Thanks for your help.

  23.   Rodolfo said

    Very good article, congratulations and keep it up, I follow you and do not forget that I always invite you to know BSD (operating system)

  24.   Samuel said

    Excellent work, very well explained. Thank you…!

  25.   porter said

    Very good of the most complete that I have been able to read until today.

    Greetings.

  26.   Jose said

    Hello, I ask you what the Linuxuser number consists of and I have seen it in different internet sites. Thank you in advance for your answer.

  27.   Alexandra Diel said

    Great!! I have Huayra installed on my school net and they are better than Windows. The information was very useful to me. Thanks for sharing!!

  28.   Simon Valdes said

    Thanks, excellent work, this did clear up a lot of doubts and helped me to make the instruction to the Linux world easier.

  29.   Nicholas said

    Hello, I have an ultra with a hybrid disk and I would like to install everything referred to at the beginning in the ssd part, I was looking and I did not find something specific but this note http://www.linux-es.org/node/112 that from what I might guess at first, they would have to be the / bin /, / boot / and / dev / directories.
    What do you think? Cheers!

  30.   VMS said

    Very good, the truth is sad that most of us did not know this type of thing, even more so, having been using linux for so long. The saddest thing of all is that in five minutes I will have forgotten everything. But reading this has been very good for me. I was thinking of using two discs for the same distribution and that's why I was looking for this type of information. This guide is cool.

  31.   MIGUEL SANCHEZ TRONCOSO said

    Excellent article, very complete.

    From now on I follow your blog

  32.   L3x said

    Hello everyone. I need to know how to make the help information of a QT (C ++) application recognized by the man command. Does anyone know where are the files associated with the linux commands ???? Thanks in advance.

  33.   Rollers said

    Very useful, thanks

  34.   Rollers said

    My question is, in DOS, to copy or move I use c: as root and well the destination, the route from c: \ and I don't know where to start from ???? '

  35.   Matias said

    Very good contribution, I never comment much on blog and stuff, but your work has just been great, I've been reading everywhere and studying a lot ... but this just put everything in its place and I think that test will be a tremendous emotion .

  36.   Enrique said

    Excellent contribution. Thank you very much for the information!.