Snott

Tag: filesystem

  • Understanding the Linux Directory Structure

    Understanding the Linux Directory Structure

    Folder Icon

    I am pretty sure sometime you have asked yourself “where do that program I just installed went to?” you can access the program no problems, but you have no clue of the directory where it got installed, well, maybe with a little more understanding of how Linux handles directories you should be able to find it.

    I will post here some explanations of the directories and what they store, and then you will get a nice image resuming this, the image it’s very useful and self-explanatory and could help you learn the structure faster.

    /

    The root directory. The starting point of your directory structure. This is where the Linux system begins. Every other file and directory on your system is under the root directory. Usually the root directory contains only subdirectories, so it’s a bad idea to store single files directly under root.

    Don’t confuse the root directory with the root user account, root password (which obviously is the root user’s password) or root user’s home directory. You need root permissions to write to this folder, in fact, you need root permissions to access any folder on the system different from your home directory.

    /boot

    Pretty self-explanatory,  this is the place where Linux keeps information that it needs when booting up, that is, the Kernel used for booting and your bootloader, be it GRUB or LILO. If you list the contents of /boot, you’ll see one or more files starting with vmlinuz – those are kernels.

    You should be very carefull when you do anything to this folder, if you don’t know what you are doing you might render your system unbootable, as a rule of thumb, it is highly recommended to have this folder on a separate partition from the rest of the system.

    /etc

    The configuration files for the Linux system. Most of these files are text files and can be edited by hand. Lots of user installed applications store the configuration files here. There are a lot of files here, some of the most useful are:

    /etc/inittab
    A text file that describes what processes are started at system bootup and during normal operation. For example, here you can determine if you want the X Window System to start automatically at bootup, and configure what happens when a user presses Ctrl+Alt+Del.

    /etc/fstab
    This file contains descriptive information about the various file systems and their mount points, like floppies, cdroms, even network shares that you want to mount at boot.

    /etc/passwd
    A file that contains various pieces of information for each user account. This is where the users are defined.

    /bin, /usr/bin

    These two directories contain a lot of programs (binaries, hence the directory’s name) for the system. The /bin directory contains the most important programs that the system needs to operate, such as the shells, lsgrep, and other essential things. /usr/bin in turn contains applications for the system’s users. However, in some cases it really doesn’t make much difference if you put the program in /bin or /usr/bin.

    /sbin, /usr/sbin

    Most system administration programs are stored in these directories. In many cases you must run these programs as the root user.

    /usr

    This directory contains user applications and a variety of other things for them, like their source codes, and pictures, docs, or config files they use. /usr is the largest directory on a Linux system, and some people like to have it on a separate partition. Some interesting stuff in /usr:

    /usr/doc
    Documentation for the user apps, in many file formats.

    /usr/share
    Config files and graphics for many user apps.

    /usr/src
    Source code files for the system’s software, including the Linux kernel.

    /usr/include
    Header files for the C compiler. The header files define structures and constants that are needed for building most standard programs. A subdirectory under /usr/include contains headers for the C++ compiler.

    /usr/local

    This is where you install apps and other files for use on the local machine.

    As a recommendation, If you find interesting apps that aren’t officially a part of your distro (i.e installed by your package manager), you should install them in /usr/local. For example, if the app would normally go to /usr/bin but it isn’t a part of your distro, you should install it in /usr/local/bin instead. This way you would always KNOW what did you install manually and avoid confusion, keeping things organized to avoid headaches later.

    /lib

    The shared libraries for programs that are dynamically linked. The shared libraries are similar to DLL’s on Winblows.

    /home

    This is where users keep their personal files. Every user has their own directory under /home, and usually it’s the only place where normal users are allowed to write files. You can configure a Linux system so that normal users can’t even list the contents of other users’ home directories (Linux is a really good multiuser system, unlike windows that you can list all contents of all users). This means that if your family members have their own user accounts on your Linux system, they won’t see all the important files (you know you only got porn there, but lets call that “important files”) you keep in your home directory.

    /root

    The superuser’s (root’s) home directory. Don’t confuse this with the root directory (/) of a Linux system.

    /var

    This directory contains variable data that changes constantly when the system is running, this folder is really useful for system administrators because it contains all the logs about system usage, load, access times, etc. Some interesting subdirectories to know about:

    /var/log
    A directory that contains system log files. They’re updated when the system runs, and checking them out can give you valuable info about the health of your system. If something in your system suddenly goes wrong, the log files may contain some info about the situation.

    /var/mail
    Incoming and outgoing mail is stored in this directory.

    /var/spool
    This directory holds files that are queued for some process, like printing.

    /tmp

    Programs can write their temporary files here.

    /dev

    The devices that are available to a Linux system. Remember that in Linux, devices are treated like files and you can read and write devices like they were files. For example, /dev/fd0 is your first floppy drive, /dev/cdrom is your CD drive, /dev/hda is the first IDE hard drive, and so on. All the devices that a Linux kernel can understand are located under /dev, and that’s why it contains hundreds of entries.

    /mnt

    This directory is used for mount points. The different physical storage devices (like the hard disk drives, floppies, CD-ROM’s) must be attached to some directory in the file system tree before they can be accessed. This attaching is called mounting, and the directory where the device is attached is called the mount point.

    The /mnt directory contains mount points for different devices, like /mnt/floppy for the floppy drive, /mnt/cdrom for the CD-ROM, and so on. However, you’re not forced to use the /mnt directory for this purpose, you can use whatever directory you wish. Actually in some distros, like Debian and SuSE, the default is to use /floppy and /cdrom as mount points instead of directories under /mnt.

    /proc

    This is a special directory. Well, actually /proc is just a virtual directory, because it doesn’t exist at all! It contains some info about the kernel itself. There’s a bunch of numbered entries that correspond to all processes running on the system, and there are also named entries that permit access to the current configuration of the system. Many of these entries can be viewed.

    /lost+found

    Here Linux keeps the files that it restores after a system crash or when a partition hasn’t been unmounted before a system shutdown. This way you can recover files that would otherwise have been lost. This folder should NOT be confused with the trash folder, trash folder if for files that you intentionally deleted, while lost+found is for filesystem recovery purposes.

    Now, as promised, here is the image about the Linux Directory Structure:

    Directory Tree