Linux Directory Structure (File System Structure)
Structure could vary from distro to distro. Most distributions have same general structure of the linux base dir system.
“/ “ The root directory
This is where the Linux system begins. Only root user has write privilege under this directory. Every single file and directory starts from the root directory. Need root permissions to write to this folder, in fact, u need root permissions to access any folder on the system different from your home directory.
/ root
The super user’s (root’s) home directory. Don’t confuse this with the root dir (/) of a Linux system. This is distinct from /, which is the system root directory. /boot
Contains boot loader related files they are the kernel, grub , system.map config files etc. This is the place where Linux keeps information that it needs when booting up.
/home
where users keep their personal files. Every user has their own directory under /home, and usually each user only has write access to their own home folder. home folder contains the user’s data files and user-specific configuration files. This file system differs from host to host. Once the user is logged in ; user is placed in his home directory. LINUX creates directories for all users directory. e:g : /home/rose.
/dev
Contains all device files these include terminal devices, usb, or any device attached to the system. Dev directory contains the essential system files and drivers. All the devices that a Linux kernel can understand are located under
/dev
/dev/fd0 is your floppy drive,
/dev/cdrom is your CD drive, / tmp
Programs can write their temporary files here. A temporary file system which hold temporary files which are cleared a t system reboot. There is also a
/var/tmp directory which holds temporary files too. The only difference between the two is that /var/tmp directory holds files that are protected at system reboot. In other words, /var/tmp files are not flushed upon a reboot. /proc
This file system does not exist on the hard disk. It is created by the kernel in its memory to provide information about the system. This special directory Well, actually /proc is just a virtual directory does not contain files. In fact, this directory does not really exist at all. It is entirely virtual. It contains information about system process.
There ’s a bunch of numbered entries that correspond to all processes running on the system also named entries that permit access to the current system configuration.
Many of these entries can be viewed. cd /proc/cpuinfo. This entry tells what the kernel thinks of the CPU. Proc is a pseudo filesystem contains information about running process. eg: /proc/{pid} It contains info about the process with that particular pid.
eg: /proc/pid , /proc/uptime
/cpuinfo (information about cpu),
/devices (information about devices installed),
/filesystem (file systems configured),
/net (information about network protocols),
/mem (memory usage)
Few of the Directories include /1 (directory with information about Proc process num 1, where 1 is the identification number).
/mnt
Mount point for temporary file systems . 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 before they can be accessed. This attaching is called mounting, and the directory where the device is attached is called the mount point.
/usr filesystem
This file system is generally large as it contains the executable files to be shared amongst different machines. Files are usually the ones installed while installing Linux. This makes it possible to update the system from a new version of the distribution, or even a completely new distribution, without having to install all programs again. Sub directories include /bin, /include, /lib, /local (for local executables)
/bin , /usr/bin ( User Binaries )
The /usr directory contains applications and files used by users. while /usr/bin contains applications for the system's users .
Contains binary executables. These two directories contain most of the programs for the system. The /bin directory contains the most important programs that the system needs to operate, such as the shells, ls, grep, and other essential things.
usr/bin is one of the major sub directories of the /usr directory. It contains most of the executable files (i.e. ready-to-run programs) that are not needed for booting (i.e., starting). There are more than 1900 executable files in /usr/bin on a typical system. Check following commands . The are
/sbin, /usr/sbin
/sbin System binaries (Utilities used for system administration). sbin directories contain programs for system administration, mostly for use by the superuser. Stored in /sbin, /usr/sbin, and /usr/local/sbin. /sbin contains binaries essential for booting, restoring, recovering the system.
eg: reboot, iptables, fdisk, ifconfig, swapon /lib
/usr/lib contains libraries for /usr/bin and /usr/sbin. Shared libraries for programs that are dynamically linked. Library files i.e program libraries. Libraries are collections of frequently used program routines. that supports the binaries located under /bin and /sbin.
Library filenames are either ld* or lib*.so.* ( ld-2.11.1.so, libncurses.so.5.7) /usr
/usr is the largest directory on a Linux system. It contains user installed applications (applications) ie. contains Sub- directories , for many programs like their source codes, and pictures, docs etc ..
/usr/src /usr/local /usr/share/dic) /usr/share/doc /usr/share/X11
(/src) linux' sub-directory holds the Linux kernel sources, header-files and
documentation. Source code files. If we install the kernel source code package, will find the entire Linux kernel source code here.
(/local) where we install apps and other files for use on the local machine.
When programs to install on linux system, should be installed in one of the /usr/local directories. /usr/local and its subdirectories are used for the installation of software and other files for use on the local machine.
(/X11) - Support files for the X Windows system. (/dic)- Dictionaries for the
spelling checker - (look and ispell ). (/doc) - Various documentation files /var
Var stands for variable files . It contains various system files i.e. files that change as the system is running. Variable content like logs, spool files for printers, crontab,at jobs, mail, running process, lock files etc . This file system is specific to local systems , because the data keeps changing. Content of the files that are expected to grow can be found under this dir This includes — system log files (/var/log);
packages and database files (/var/lib); emails (/var/mail);
print queues (/var/spool); lock files (/var/lock);
temp files needed across reboots (/var/tmp);
(var/log) Directory that contains log files for different applications. . These are
updated as the system runs. Should view the files in this directory from time to time, to monitor the health of your system.
/var/run/ /var/lib /var/mail:
/var/tmp /var/cache/ /var/spool
(/run) contains data describing since it was booted. (/lib) -Contains info relating
to the current state of applications. (/cache) contanins tmp files preserved between system reboots. Storage area for cached data for applications.
(/mail) -Incoming and outgoing mail.
(tmp )- contanins tmp files preserved between system reboots.
(/spool) - contains data i.e waiting for some kind of peocessing . This directory
is used to hold files that are queued for some process, such as mail messages and print jobs. When a user's mail first arrives on the local system (assuming you have local mail), the messages are first stored in /var/spool/mail.
/etc
etc stands for "etcetera" !
This directory contains the configuration files for the system. All of the files in /etc should be text files. Most of these files are text files and can be edited by hand. Lots of user installed applications store the configuration files here i.e. A lot of files here (passwd , fstab , hosts , etc) ..
/etc/fstab /etc/hosts /etc/passwd /etc/inittab.d
(/hosts) -lists the network host names and IP addresses that known to the
system. (/passwd) -The passwd file contains the essential info for each user. here that users are defined.
(/fstab) - This file defines your disk drives like floppies, cdroms, even network shares and also descriptive information about the various file systems and their mount points.
(inittab.d) A text file that describes what processes are started at system bootup andduring normal operation. This also contains startup and shutdown shell scripts used to start/stop individual programs.
Linux Performance Commands :
Managing performance on Linux systems is a lot easier with a few commands. Listed below are some of commands including top, vmstat, iostat, free, and sar. They may help in resolving performance issues quickly and easily.
TOP
The ‘top’ command shows not only the current tasks being serviced by the kernel but also some broad statistical data about the state of a host. By default, it automatically updates this data every five seconds (this update period is configurable).
The top command tells several things, for example: the current uptime, system load, number of processes and memory usage. In addition, the command shows those processes using the most CPU (including a variety of pieces of information about each process such as the running user and the command being executed).
VMSTAT
The ‘vmstat’ command gives a snapshot of current CPU, IO, processes and memory usage. Similar to the top command, it dynamically updates and can be executed with this command: $ vmstat 10
IOSTAT
The ‘iostat’ command (provided via the sysstat package on Ubuntu and Red Hat/Fedora) offers three reports. These are CPU utilization, device utilization, and network file system utilization.
In case of running the command without options,it will display all three reports. The individual reports can be specified with the -c, -d and -h switches respectively.
FREE
The ‘free’ command shows memory statistics for both main memory and swap. A total memory amount can be displayed by specifying the -t switch. The amounts in bytes can also be displayed by specifying the -b switch and megabytes using the -m switch (it displays in kilobytes by default). Free can also be run continuously using the -s switch with a delay specified in seconds: $ free -s 5
SAR
Use the ‘sar’ command line tool to collect, view and record performance data. This command is considerably more sophisticated than all the commands discussed above. It can collect and display data over longer periods.
Error Codes in Linux
To understand the nature of the error these codes need to be interpreted. They are recorded in /usr/include/asm/errno.h
Command to find status of last command Execution
$ echo $? # echo $?
Number C define Message
0 Action Success
1 EPERM Operation not permitted
2 ENOENT No such file or directory
3 ESRCH No such process
4 EINTR Interrupted system call
5 EIO Input/output error
6 ENXIO Device not configured
7 E2BIG Argument list too long
8 ENOEXEC Exec format error
9 EBADF Bad file descriptor
10 ECHILD No child processes
11 EAGAIN Resource temporarily unavailable
11 EWOULDBLOCK Resource temporarily unavailable
12 ENOMEM Cannot allocate memory
13 EACCES Permission denied
14 EFAULT Bad address
15 ENOTBLK Block device required
16 EBUSY Device or resource busy
17 EEXIST File exists
18 EXDEV Invalid cross-device link
19 ENODEV No such device
20 ENOTDIR Not a directory
21 EISDIR Is a directory
22 EINVAL Invalid argument
23 ENFILE Too many open files in system
24 EMFILE Too many open files
25 ENOTTY Inappropriate ioctl for device
26 ETXTBSY Text file busy
27 EFBIG File too large
28 ENOSPC No space left on device
30 EROFS Read-only file system
31 EMLINK Too many links
32 EPIPE Broken pipe
33 EDOM Numerical argument out of domain
34 ERANGE Numerical result out of range
35 EDEADLK Resource deadlock avoided
35 EDEADLOCK Resource deadlock avoided
36 ENAMETOOLONG File name too long
37 ENOLCK No locks available
38 ENOSYS Function not implemented
39 ENOTEMPTY Directory not empty
40 ELOOP Too many levels of symbolic links
EWOULDBLOCK (same as EAGAIN)
42 ENOMSG No message of desired type
43 EIDRM Identifier removed
44 ECHRNG Channel number out of range
45 EL2NSYNC Level 2 not synchronized
46 EL3HLT Level 3 halted
47 EL3RST Level 3 reset
48 ELNRNG Link number out of range
49 EUNATCH Protocol driver not attached
50 ENOCSI No CSI structure available
51 EL2HLT Level 2 halted
52 EBADE Invalid exchange
53 EBADR Invalid request descriptor
54 EXFULL Exchange full
55 ENOANO No anode
56 EBADRQC Invalid request code
57 EBADSLT Invalid slot
EDEADLOCK (same as EDEADLK)
59 EBFONT Bad font file format
61 ENODATA No data available
62 ETIME Timer expired
63 ENOSR Out of streams resources
64 ENONET Machine is not on the network
65 ENOPKG Package not installed
66 EREMOTE Object is remote
67 ENOLINK Link has been severed
68 EADV Advertise error
69 ESRMNT Srmount error
70 ECOMM Communication error on send
71 EPROTO Protocol error
72 EMULTIHOP Multihop attempted
73 EDOTDOT RFS specific error
74 EBADMSG Bad message
75 EOVERFLOW Value too large for defined data type
76 ENOTUNIQ Name not unique on network
77 EBADFD File descriptor in bad state
78 EREMCHG Remote address changed
79 ELIBACC Can not access a needed shared library
80 ELIBBAD Accessing a corrupted shared library
81 ELIBSCN .lib section in a.out corrupted
82 ELIBMAX Attempting to link in too many shared libraries
83 ELIBEXEC Cannot exec a shared library directly
84 EILSEQ Invalid or incomplete or multibyte or wide char
85 ERESTART Interrupted system call should be restarted
86 ESTRPIPE Streams pipe error
87 EUSERS Too many users
88 ENOTSOCK Socket operation on non-socket
89 EDESTADDRREQ Destination address required
90 EMSGSIZE Message too long
91 EPROTOTYPE Protocol wrong type for socket
93 EPROTONOSUPPORT Protocol not supported
94 ESOCKTNOSUPPORT Socket type not supported
95 EOPNOTSUPP Operation not supported
96 EPFNOSUPPORT Protocol family not supported
97 EAFNOSUPPORT Address family not supported by protocol
98 EADDRINUSE Address already in use
99 EADDRNOTAVAIL Cannot assign requested address
100 ENETDOWN Network is down
101 ENETUNREACH Network is unreachable
102 ENETRESET Network dropped connection on reset
103 ECONNABORTED Software caused connection abort
104 ECONNRESET Connection reset by peer
105 ENOBUFS No buffer space available
106 EISCONN Transport endpoint is already connected
107 ENOTCONN Transport endpoint is not connected
108 ESHUTDOWN Can’t send after transport endpoint shutdown
109 ETOOMANYREFS Too many references: cannot splice
110 ETIMEDOUT Connection timed out
111 ECONNREFUSED Connection refused
112 EHOSTDOWN Host is down
113 EHOSTUNREACH No route to host
114 EALREADY Operation already in progress
115 EINPROGRESS Operation now in progress
116 ESTALE Stale NFS file handle
117 EUCLEAN Structure needs cleaning
118 ENOTNAM Not a XENIX named type file
119 ENAVAIL No XENIX semaphores available
120 EISNAM Is a named type file
121 EREMOTEIO Remote I/O error
122 EDQUOT Disk quota exceeded
123 ENOMEDIUM No medium found
LINUX File System:
Linux operating system everything is a file. To manage all these files Linux have a tree like directory structure. File system may little vary from distro to disro.
/ : Root directory, which contains all other directories.
/dev : Contains device files.
/etc : Contains configuration files.
/root : Root user’s home directory.
/sbin : Contains system binaries.
/tmp : Contains temporary files.
/var : Contains variable data files.
/opt : Contains add-on/optional packages.
/home : Contains users’ home directories.
/media : Mount point for removable media.
/lib : Essential shared libraries and kernel modules.
/proc : Contains kernel and process information
/bin : Contains commands that may be used by both system administrator and by users, but which are require when no other file-systems are mounted.
/boot: This directory contains everything which required for the boot process, like kernel, GRUB, Initrd, etc.
In Linux operating system there is a pre-defined location to store different files. So above mentioned file system is common for Red hat distributions.