Linux’s directory structure (folder structure)

WEll i have noticed,Many new comer Faces Problem in understanding what exactly Linux and It’s File structure. Linux organizes its files differently from Windows. First the directory structure may seem unlogical and strange and you have no idea where all the programs, icons, config files, and others are. This Article will take you to a guided tour through the Linux file system. This is by no means a complete list of all the directories on Linux, but it shows you the most interesting places in your file system.

In Windows, you use this format to access a Directory:

C:\Folder\subfolder\file.txt

In Linux, this is the basic format:

# /Folder1/subfolder/file.txt

You’ll notice that the slashes are forward slashes in Linux versus backslashes in Windows. Also, there is no drive name (C:, D:, etc.) in Linux. At boot, the ‘root partition’ is mounted at “/”. All files, folders, devices and drives are mounted under /. files and folders in Linux are case sensitive. /Folder1/subfolder/file.txt is not the same as /folder1/subfolder/file.txt.

The Main Directories

1. / – Root
2. /bin – User Binaries
3. /sbin – System Binaries
4. /etc – Configuration Files
5. /dev – Device Files
6. /proc – Process Information
7. /var – Variable Files
8. /tmp – Temporary Files
9. /usr – User Programs
10. /home – Home Directories
11. /boot – Boot Loader Files
12. /lib – System Libraries
13. /opt – Optional add-on Applications
14. /mnt – Mount Directory
15. /media – Removable Media Devices
16. /srv – Service Data

This is How Linux File Structure Looks like. Let’s explain Each of one.

1. / – Root

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.Only root user has write privilege under this directory.Please note that /root is root user’s home directory, which is not same as /.

# cd /

# ls

Image and video hosting by TinyPic
This is How it Looks like in fedora

Image and video hosting by TinyPic
This is How it looks like in Backtrack5

You will notice it has Diffrent File name , as we know it depends upon Linux distribution Generally you will find these basic File Directory in every Linux Operating system.

2. /bin – User Binaries, /usr/bin

These two directories contain a lot of programs (binaries, hence the directory’s name) for the system. Common linux commands you need to use in single-user modes are located under this directory.The /bin directory contains the most important programs that the system needs to operate, such as the shells, ls, grep, and other essential things For example: ps, ls, ping, grep, cp. /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.

# cd /usr/bin

# ls 

Image and video hosting by TinyPic
YOu can see a Very large number of binary executables.

3. /sbin – System Binaries

Most system administration programs are stored in these directories. In many cases you must run these programs as the root user.For example: iptables, reboot, fdisk, ifconfig, swapon. It also contains binary executables you can check by

# cd /sbin

  # ls 

Image and video hosting by TinyPic

4. /etc – Configuration Files

# cd /etc/

# ls 

The configuration files for the Linux system.It contains configuration files required by all programs Most of these files are text files and can be edited by hand. Some interesting
stuff in this directory:

Image and video hosting by TinyPic
This is How it looks in Fedora above

Image and video hosting by TinyPic
This is How it looks in backtrack 5
————————————————————————
This file contains descriptive information about the various file systems and their mount points, like floppies, cdroms, and so on.

# cat /etc/fstab

Image and video hosting by TinyPic
This is How it looks in Fedora a permanent mount point

Image and video hosting by TinyPic
This is How it looks in Backtrack5 a permanent mount point

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

# cat /etc/passwd

Image and video hosting by TinyPic
This is How it looks in Fedora


This is How it looks in Backtrack5

5. /dev – Device Files

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.These include terminal devices, usb, or any device attached to the system.Example /dev/tty1, /dev/usbmon0

# cd /dev

# ls

Image and video hosting by TinyPic
This is How it Looks in Fedora

Image and video hosting by TinyPic
This is How it Looks in Backtrack5

6. /proc – Process Information

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.by #cd /proc and then type #lsThis is a pseudo filesystem contains information about running process. For example: /proc/{pid} directory contains information about the process with that particular pid.Last but not least it Contains information about system process.

# cd /proc/

# ls

Image and video hosting by TinyPic
This is How it Looks in Fedora

Image and video hosting by TinyPic
This is How it Looks in Backtrack5

7. /var – Variable Files

This directory contains variable data that changes constantly when the system is running.

# cd /var/

Image and video hosting by TinyPic
THis is How it looks in Fedora

Image and video hosting by TinyPic
This is How it looks in Backtrack 5

Some interesting subdirectories:

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.

# cd/var/log

Incoming and outgoing mail is stored in this directory.

# cd /var/mail

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

# cd /var/spool

8. /tmp – Temporary Files

Programs can write their temporary files here.

# cd /tmp

9. /usr – User Programs

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:

#cd /usr

# ls

Image and video hosting by TinyPic
THis is How it looks in Fedora

Image and video hosting by TinyPic
This is How it looks in Backtrack 5

# cd/usr/doc

Documentation for the user apps, in many file formats.

# cd/usr/share

Config files and graphics for many user apps.

# cd/usr/src

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

# cd/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/X11R6 Not here, but it Present. it is basically for,The X Window System and things for it. The subdirectories under /usr/X11R6 may contain some X binaries themselves, as well as documentation, header files, config files, icons, sounds, and other things related to the graphical programs.

10. /home – Home Directories

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. This means that if your family members have their own user accounts on your Linux system, they won’t see all the w4r3z you keep in your home directory. ;-)Or you Porn stuff hheeh :D

# cd /home/

# ls

# cat /etc/passwd | grep "/home"

Image and video hosting by TinyPic
This is HOw in fedora looks

Image and video hosting by TinyPic
This is how in backtrack5 looks like

11. /boot – Boot Loader Files

As the name suggests, this is the place where Linux keeps information that it needs when booting up. For example, this is where the Linux kernel is kept. If you list the contents of /boot, you’ll see a file called vmlinuz – that’s the kernel.Kernel initrd, vmlinux, grub files are located under /boot For example: initrd.img-2.6.32-24-generic, vmlinuz-2.6.32-24-generic

# cd /boot/

# ls

Image and video hosting by TinyPic
This is how looks in Fedora

12. /lib – System Libraries

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

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.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

# cd/mnt/1

# ls

Image and video hosting by TinyPic
This is How Backtrack looks like

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

# cd /media/

# ls 

You will then see list of temporary media connected like cdrom and floppy Try you self

16./srv – Service Data

srv stands for service.Contains server specific services related data.For example, /srv/cvs contains CVS related data.

# cd /srv/

# ls

Try you self

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.

#######################$$$$$$$$$$$$$####################

What next?

If you're completely new to Linux, you might want to learn some commands for moving around in the file system, viewing text files, or manipulating the files. In that case I suggest you take a look at my, new articles coming at my Linux command line section :);) sTAY TuNe

About these ads

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s