Pages

Sunday 18 December 2011

Directories and file system of linux

Linux and Unix file systems are organised in a hierarchical, tree-like structure. The highest level of the file system is the / or root directory. In the Unix and Linux design philosophy, everything is considered a file - including hard disks, partitions and removable media. This means that all other files and directories (including other disks and partitions) exist under the root directory.
Underneath the root (/) directory, there is a set of important system directories that are common across most Linux distributions that are used.

The following is a listing of common directories that are directly under the root (/) directory

  •         /bin - important binary applications
  •          /boot - boot configuration files
  •          /dev - the device files
  •          /etc - configuration files, startup scripts, etc...
  •          /home - local users' home directories
  •        /lib - system libraries
  •         /lost+found - provides a lost+found system for files that exist under the root (/) directory
  •          /media - mounted (loaded) removable media such as CDs, digital cameras, etc...
  •          /mnt - mounted filesystems
  •          /opt - provides a location for optional applications to be installed
  •          /proc - special dynamic directory that maintains information about the state of the system, including currently running processes
  •          /root - root user home directory, pronounced 'slash-root'
  •         /sbin - important system binaries
  •         /sys - system files
  •          /tmp - temporary files
  •          /usr - applications and files that are mostly available for all users to access
  •          /var - variable files such as logs and databases
All of the files on a Linux system have permissions that allow or prevent others from viewing, modifying or executing. The super user "root" has the ability to access any file on the system. Each file has access restrictions, user restrictions and have an owner/group association.

/bin:
The first directory we get to is /bin. Its name is derived from the word "binary." Often, the word "binary" is used to refer to executable programs or other files that contains non-readable characters. The /bin directory is where many of the system-related binaries are kept, hence the name. 



Although several of the files in this directory are used for administrative purposes and cannot be run by normal users, everyone has read permission on this directory, so you can at least see what the directory contains.


/boot:
The /boot directory is used to boot the system. There are several files here that the system uses at different times during the boot process.


/dev:
The /dev directory contains the device nodes. Device files are the way both the operating system and users gain access to the hardware. Every device has at least one device file associated with it. If it doesn't, you can't gain access to it. We'll get into more detail on individual device files later.


/etc:
The /etc directory contains files and programs that are used for system configuration. Its name comes from the common abbreviation etc., for et cetera, meaning "and so on." This seems to come from the fact that on many systems, /etc contains files that don't seem to fit elsewhere.
Under /etc are several subdirectories of varying importance to both administrators and users.


/lost+found:
The /lost+found directory is used to store files that are no longer associated with a directory. These are files that have no home and are, therefore, lost. Often, if your system crashes and the filesystem is cleaned when it reboots, the system can save much of the data and the files will end up here. Note that a lost+found directory is created automatically for each filesystem you create. We'll get into more detail about this in the section on filesystems.


/lib:
The /lib directory (for library) contains the libraries needed by the operating system as it is running. You will also find several sub directories.


/proc:
The /proc directory takes a little while to get used to, especially if you come from a non-UNIX world or have used a version of UNIX without this directory. This is a "pseudo-filesystem" that is used to access information in the running system. Rather than having you access kernel memory directly (i.e., through the special device /dev/kmem), you can access the files within this directory. There are directories for every running process as well. We will get into more detail about this when we talk about monitoring your system.


/root:
The /root directory is the home directory for the user root. This is different from many UNIX dialects that have the root's home directory in /. On SuSE, the /root directory is actually a symbolic link to /home/root.


/sbin:
The /sbin directory contains programs that are used (more or less) to administer the system. In other words, the system binaries. Many documentation sources say that this is only for system administrators. However, most of these files are executable by normal users, as well. Whether the support files or device nodes are accessible is another matter. If a normal user cannot access the device nodes or other files, the program won't run.


/usr:
The /usr directory contains many user-related subdirectories. Note the 'e' is missing from "user". In general, one can say that the directories and files under /usr are used by and related to users. There are programs and utilities here that users use on a daily basis. Unless changed on some systems, /usr is where users have their home directory. The figure below shows what the subdirectories of /usr would look like graphically.
Where /bin contains programs that are used by both users and administrators, /usr/bin contains files that are almost exclusively used by users. (However, like everything in UNIX, there are exceptions.) Here again, the bin directory contains binary files. Programs and utilities needs for administrative tasks are stored in /sbin. Note that is common to seperate files like this, but it is not an absolute.
The /usr/adm directory contains mostly administrative data. The name "adm" comes from "administration," which is no wonder considering this contains a lot of the administrative information that relates to users. This may be a symbolic link to the /var directory.
The /usr/src directory contains the source code for both the Linux kernel and for any program that you specifically install.
The directory /usr/X11R6 contains all the X Windows System files. This makes upgrading to newer releases of X much easier as the files are not spread out over the entire system. If you have an older version of Linux, you might still have X11R5 or if a newer release comes out you might have X11R7. To simplify things even further, the directory /usr/X11 is what many things look at instead. This is then linked to the appropriate directory (i.e., /usr/X11R6, /usr/X11R5).
Underneath this directory are the subdirectories bin, lib, and man, which have the same functionality as those under /usr. In most cases, links in other directories point here. For example, you should have a directory /usr/bin/X11. This is a symbolic link to the directory /usr/X11R6/bin. The directory /usr/lib/X11 is a symbolic link to /usr/X11R6/lib. The reason for this is to maintain the directory structure, but still make upgrading easy. When X11R7 comes out, all that you need to do is make the links point to the X11R7 directories and not copy the individual files.


/var:
The /var directory contains files that vary as the system is running, such as log files. This was originally intended to be used when the /usr directory is shared across multiple systems. 

No comments:

Post a Comment