UNIX Directory structure:
Directiory is a file with special format where the information about other files is stored in
the system. Unix directory structure is very simple.
These files contain audio,video,executable file or help information.
So,Unix uses a hierarchical file system structure, much like an upside-down tree, with
root (/) at the base of the file system and all other directories spreading from there.
This tree structure contain many files which identified by path.
Means a Relative path (from the root point) and absolute path (from the current
location).
So, this unix structure is different from windows and MS DOS system. If youre coming
from Windows, The C:\ drive and drive letters are gone, replaced by a / and other sub
directories, most of which have three letter names.
Ex: a software named WinRAR , which is used for compression and decompression of
data.i sinstalled in our system. Files related to configuration , help and executable of
WinRAR are all stored together in windows, while in unix there are separate directories
for configuration , help and executable of program.
Other difference is that representation of format:
EX: path is represented by (windows use backslash)
Drive:\foldername\sub_folder_name\[Link]
In unix (use forward slash)
/foldername/sub_folder_name/[Link]
1. / Root
Every single file and directory starts from the root directory.
Everything on your Linux system is located under the / directory, known as the root
directory.
2. /bin User Binaries
Contains binary executables.
Common linux commands you need to use in single-user modes are located under this
directory.
For example: ps, ls, ping, grep, cp.
3. /sbin System Binaries
Just like /bin, /sbin also contains binary executables.
But, the linux commands located under this directory are used typically by system
aministrator, for system maintenance purpose.
For example: iptables, reboot, fdisk, ifconfig, swapon
4. /etc Configuration Files
Contains configuration files required by all programs.
This also contains startup and shutdown shell scripts used to start/stop individual
programs.
For example: /etc/[Link], /etc/[Link]
Supervisor directory commands, configuration files, disk configuration files, valid user
lists, groups, ethernet, hosts, where to send critical messages
5. /dev Device Files
Contains device files. These are device driver.
These include terminal devices, usb, or any device attached to the system.
For example: /dev/tty1, /dev/usbmon
Linux exposes devices as files, and the /dev directory contains a number of special files
that represent devices. These are not actual files as we know them, but they appear as file
6. /proc Process Information
Contains information about system process.
This is a pseudo filesystem contains information about running process. For example:
/proc/{pid} directory contains information about the process with that particular pid.
7. /var Variable Files
var stands for variable files.
Content of the files that are expected to grow can be found under this directory.
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);
8. /tmp Temporary Files
Directory that contains temporary files created by system and users.
Files under this directory are deleted when system is rebooted.
9. /usr User Programs
Contains binaries, libraries, documentation, and source-code for second level programs.
/usr/local contains users programs that you install from source. For example, when you
install apache from source, it goes under /usr/local/apache2
10. /home Home Directories
Home directories for all users to store their personal files.
For example: /home/john, /home/nikita
Contains the home directory for users and other accounts
The /home directory contains a home folder for each user. For example, if your user
name is bob, you have a home folder located at /home/bob. This home folder contains the
users data files and user-specific configuration files.
11. /boot Boot Loader Files
Contains files for booting the system
Kernel initrd, vmlinux, grub files are located under /boot
The /boot directory contains the files needed to boot the system for example, the GRUB
boot loaders files and your Linux kernels are stored here.
12. /lib System Libraries
Contains library files that supports the binaries located under /bin and /sbin
Contains shared library files and sometimes other kernel-related files
13. /opt Optional add-on Applications
opt stands for optional.
Contains add-on applications from individual vendors.
add-on applications should be installed under either /opt/ or /opt/ sub-directory.
14. /mnt Mount Directory
Temporary mount directory where sysadmins can mount filesystems.
Used to mount other temporary file systems, such as cdrom and floppy for the CD-
ROM drive and floppy diskette drive, respectively
15. /media Removable Media Devices
Temporary mount directory for removable devices.
For examples, /media/cdrom for CD-ROM; /media/floppy for floppy drives;
/media/cdrecorder for CD writer
The /media directory contains subdirectories where removable media devices inserted
into the computer are mounted. For example, when you insert a CD into your Linux
system, a directory will automatically be created inside the /media directory. You can
access the contents of the CD inside this directory.
16. /srv Service Data
srv stands for service.
Contains server specific services related data.
For example, /srv/cvs contains CVS related data.
The /srv directory contains data for services provided by the system. If you were using
the Apache HTTP server to serve a website, youd likely store your websites files in a
directory inside the /srv directory.
INODE
Names are helpful to humans but, the file system recognizes a file not by its name but by
a number. That number through which the operating system reaches the location and
other attributes of that file is called as an inode number
Inode: its a data structure that keeps track of all the information about a file. Each file
have a small table associated with a file called I-node.(index number)
You store your information in a file, and the operating system stores the information
about a file in an inode(sometimes called as an inode number).
When a file is created inside a directory then the file-name and Inode number are
assigned to file.
These two entries are associated with every file in a directory. The user might think that
the directory contains the complete file and all the extra information related to it but this
might not be the case always. So we see that a directory associates a file name with its
Inode number.
When a user tries to access the file or any information related to the file then he/she uses
the file name to do so but internally the file-name is first mapped with its Inode number
stored in a table.
Then through that Inode number the corresponding Inode is accessed.
There is a table (Inode table) where this mapping of Inode numbers with the respective
Inodes is provided.
Inode number File nme
Inode number also called as index number , it consists following attributes.
File types ( executable, directory,normal file etc ), Permissions ( read, write etc ),
FileSize , Time stamps including last access, last modification and last inode number
change, Number of links ( soft/hard ) , Location of ile on harddisk.
Some other metadata about file.
To check inode number of file use following command, first field in ouput is an inode number.
# ls -il [Link]
1150561 -rw-r--r-- 1 root root 0 Mar 10 01:06 [Link]
Search file on basis of inode number.
# find /root -inum 1150561
/root/[Link]
How do I see file inode number?
You can use ls -i command to see inode number of file
You can also use stat command to find out inode number and its attribute:
$ stat /etc/passwdOutput:
File: `/etc/passwd'
Size: 1988 Blocks: 8 IO Block: 4096 regular file
Device: 341h/833d Inode: 32820 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2005-11-10 [Link].000000000 +0530
Modify: 2005-10-27 [Link].000000000 +0530
Change: 2005-10-27 [Link].000000000 +0530