Linux Filesystem Hierarchy

It is basic list of directories and some files in the Linux and explains which directory and some files use for which need.

Linux Basic Filesystem Hierarchy
Directory Description
/ The root directory where the file system begins. In most cases the root directory only contains subdirectories.
/boot This is where the Linux kernel and boot loader files are kept. The kernel is a file called vmlinuz.
/etc The /etc directory contains the configuration files for the system. All of the files in /etc should be text files. Points of interest:
The passwd file contains the essential information for each user. It is here that users are defined.
The fstab file contains a table of devices that get mounted when your system boots. This file defines your disk drives.
This file lists the network host names and IP addresses that are intrinsically known to the system.
This directory contains the scripts that start various system services typically at boot time.
/bin, /usr/bin These two directories contain most of the programs for the system. The /bin directory has the essential programs that the system requires to operate, while /usr/bin contains applications for the system's users.
/sbin, /usr/sbin The sbin directories contain programs for system administration, mostly for use by the superuser.
/usr The /usr directory contains a variety of things that support user applications. Some highlights:
Support files for the X Windows system
Dictionaries for the spelling checker. Bet you didn't know that Linux had a spelling checker. See look and ispell.
Various documentation files in a variety of formats.
The man pages are kept here.
Source code files. If you installed the kernel source code package, you will find the entire Linux kernel source code here.
/usr/local /usr/local and its subdirectories are used for the installation of software and other files for use on the local machine. What this really means is that software that is not part of the official distribution (which usually goes in /usr/bin) goes here.

When you find interesting programs to install on your system, they should be installed in one of the /usr/local directories. Most often, the directory of choice is /usr/local/bin.
/var The /var directory contains files that change as the system is running. This includes:
Directory that contains log files. These are updated as the system runs. You should view the files in this directory from time to time, to monitor the health of your system.
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
/lib The shared libraries (similar to DLLs in that other operating system) are kept here.
/home /home is where users keep their personal work. In general, this is the only place users are allowed to write files. This keeps things nice and clean :-)
/root This is the superuser's home directory.
/tmp /tmp is a directory in which programs can write their temporary files.
/dev The /dev directory is a special directory, since it does not really contain files in the usual sense. Rather, it contains devices that are available to the system. In Linux (like Unix), devices are treated like files. You can read and write devices as though they were files. For example /dev/fd0 is the first floppy disk drive, /dev/sda (/dev/hda on older systems) is the first IDE hard drive. All the devices that the kernel understands are represented here.
/proc The /proc directory is also special. This directory does not contain files. In fact, this directory does not really exist at all. It is entirely virtual. The /proc directory contains little peep holes into the kernel itself. There are a group of numbered entries in this directory that correspond to all the processes running on the system. In addition, there are a number of named entries that permit access to the current configuration of the system. Many of these entries can be viewed. Try viewing /proc/cpuinfo. This entry will tell you what the kernel thinks of your CPU.
/media,/mnt Finally, we come to /media, a normal directory which is used in a special way. The /media directory is used for mount points for physical storage devices (like hard disk drives)

The /mnt directory provides a convenient place for mounting these temporary devices (removable devices). You will often see the directories /mnt/floppy (for floppy)and /mnt/cdrom (for CD-R or RW). To see what devices and mount points are used, type mount.

Installing software in Linux from source

    First of all you do not worry about how can read this loooooooong procedure. Be cooooooooooooooool yar it is just four steps of unpack, configure, build, install with four commands tar unpack, ./configure, make, make install.
    All are know about that linux softwares available in three formates.

  • RPM (Redhat Packmanager it is in .rpm file format for Redhat based Linux)
  • DEB (Debian Packmanager it is in .deb file format for Debian based Linux)
  • Source Packs(It is a universal pack for all platforms available in tarball compressed format like {packname.version}.tar.gz or .tar.bz2)
    We can install .rpm packages by typing rpm -i {packname-version.rpm (vlcplayer-0.9.5.rpm)} in command-line base or by using YUM Package manager in GUI friendly (select and install) in Redhat base Linux like Fedora and more... and same as we can install .deb packages by typing apt-get install {Packagename-version.deb} in command-line base or use Synaptic Packmanager in GUI friendly in Debian based Linux like Ubuntu and there are some more Package manager form different Linux distributors for manage there packages in GUI friendly and also in command-line. This two formates is easy as like .exe in windows click and install.

    Lets come to source packages it is a universal packages for all platform like Windows, Linux(both Redhat and Debian base Linux) and Power PC's . It is in the tarball compressed format with file extension .tar.gz or tar.bz2 and more... we uncompress the content to any location as we like by using tar command shown as below.   

# tar xvzf package-version.tar.gz (or tar xvjf package-version.tar.bz2)
# cd package-version (directory where package content uncompress)
# ./configure
# make
# make install

It is not same for all packages some packages will use some advanced procedure. I recommended it is better to read manual README  or INSTALL file for installation process.


  • Step 1. Unpacking
  • Step 2. Configuring
  • Step 3. Building
  • Step 4. Installing
  • Cleaning up the mess
  • Uninstalling

Step 1. Unpacking

After downloading the package, you unpack(uncompress) it with this command because it is in tarball compressed:

me@linux: ~$ tar xvzf packname-version.tar.gz

As you can see, you use the tar command with the appropriate options (xvzf) for unpacking the tarball. If you have a package with tar.bz2 extension instead, you must tell tar that this isn't a gcompressped tar archive. You do so by using the j option instead of z, like this:

me@linux: ~$ tar xvjf packname-version.tar.bz2

What happens after unpacking, depends on the package, normally when unpack the source file it unpack with the packname with version see by typing ls command:

me@linux: ~$ ls 
packname-version packname-version.tar.gz
me@linux: ~$

In above example unpacking our package packname-version.tar.gz did what expected and created a directory with the package's name vith version number packname-version . Now you must cd(change directory) into that newly created directory:

me@linux: ~$ cd packname-version 
me@linux: ~/packname-version$

Read any documentation you find in this directory, like README or INSTALL files, before continuing!

 Step 2. Configuring

Now, after we've changed into the package's directory (and done a little RTFM'ing), it's time to configure the package. I recomended to read the README and INSTALL or and manual for the package installation procegure befor going to running the configure script. 

You run the script with this command:
me@linux: ~/packname-version$ ./configure 

When you run the configure script, you don't actually compile anything yet. configure just checks your system and assigns values for system-dependent variables. These values are used for generating a Makefile. The Makefile in turn is used for generating the actual binary.

When you run the configure script, you'll see a bunch of weird messages scrolling on your screen. This is normal and you shouldn't worry about it. If configure finds an error, it complains about it and exits. However, if everything works like it should, configure doesn't complain about anything, exits, and shuts up.
If configure exited without errors, it's time to move on to the next step.

 Step 3. Building

It's finally time to actually build the binary, the executable program, from the source code. This is done by running the make command:

me@linux: ~/packname-version$ make

Note that make needs the Makefile for building the program. Otherwise it doesn't know what to do. This is why it's so important to run the configure script successfully, or generate the Makefile some other way.
When you run make, you'll see again a bunch of strange messages filling your screen. This is also perfectly normal and nothing you should worry about. This step may take some time, depending on how big the program is and how fast your computer is. At this point I usually lose my patience completely. Don't worry yar take a break with coffee.

If all goes as it should, your executable is finished and ready to run after make has done its job. Now, the final step is to install the program.

 Step 4. Installing

Now it's finally time to install the program. When doing this you must be root. If you've done things as a normal user, you can become root with the su command. It'll ask you the root password and then you're ready for the final step!

me@linux: ~/packname-version$ su
root@linux: /home/me/packname-version#

Now when you're root, you can install the program with the make install command:

root@linux: /home/me/packname-version# make install

For Debian base Linux like Ubuntu use sudo command as follows:
me@linux: ~/packname-version$sudo make install

Again, you'll get some weird messages scrolling on the screen. After it's stopped, congrats: you've installed the software and you're ready to run it!

Because in this example we didn't change the behavior of the configure script, the program was installed in the default place. In many cases it's /usr/local/bin. If /usr/local/bin (or whatever place your program was installed in) is already in your PATH, you can just run the program by typing its name.
And one more thing: if you became root with su, you'd better get back your normal user privileges type exit to become a normal user again as follow

root@linux: /home/me/packname-version# exit
me@linux: ~/packname-version$

It is not necessary for Debian user it will temporary changes as root in yours name and automatically forgets the root mode for some time. But some Linux distributors it is long up when your shell is open. So, it is better to close and re-open current shell.

 Cleaning up the mess

I bet you want to save some disk space. If this is the case, you'll want to get rid of some files you don't need. When you ran make it created all sorts of files that were needed during the build process but are useless now and are just taking up disk space. This is why you'll want to make clean:

me@linux: ~/packname-version$ make clean

However, make sure you keep your Makefile. It's needed if you later decide to uninstall the program and want to do it as painlessly as possible!


    It is easy to uninstall the package which are installed by rpm and same as .deb with apt-get remove other with other ways. And also easy to uninstall sourcepackages by needing Makefile file on where the file is created in building process and use following command where the file located.
root@linux: /home/me/packname-version# make uninstall

If we lose Makefile file, We can manually delete the installed files. It is not a easy way to manually id and delete the sertain application related file. My idea is re-process all the above as previously done without any change and don't re-install it and take the Makefile and use above Make uninstall command to uninstall application.

Linux Files and directories permissions

Linux operation system different from other operating system it has a multi-tasking and
multi-user operating in a same time. Linux is a UNIX like operating system. This operation same to UNIX and Linux.

    This topic will cover about the giving permissions for files & Directories on the
Linux/Unix Operation System with following commands:
  • chmod
    - modify file access rights
  • su
    - temporarily become the superuser
  • chown
    - change file ownership
  • chgrp
    - change a file's group ownership
me@linux:~$ ls -l some_file

-rw-rw-r-- 1 me me 1097374 Sep 26 18:48 some_file

    In above you see that have 10 dashes first dash is related to identify that is file or directory ('- ' means file or 'd' means directory). 2-4 dashes permissions related to owner of the file who creates the file or directory , 5-7 dashes permissions related to group of the file and directory, and 8-9 dashes permissions related to other user of the file and directory.
drwx rwx rwx = 111 111 111
-rw- rw- rw-   = 110 110 110
-rwx --- ---      = 111 000 000
- --- --- ---       = 000 000 000
- or d= id directory or not 
r   = Read the file or Directory
w = write the file or Directory
x  = Execute the file or Directory

And it is easy to:
rwx = 111 in binary = 7
rw- = 110 in binary = 6
r-x = 101 in binary = 5
r-- = 100 in binary = 4
--- = 000 in binary = 0
me@linux:~$ chmod 754 file
--rwxr-xr-- 1 me me 1097374 Sep 26 18:48 file

In above first dash ('-') indicates the directory or not like follows

--rwxr-xr-- 1 me me 1097374 Sep 26 18:48 file
drwxr-xr--  1 me me 1097374 Sep 26 18:48 dir1

In above list first one is the file and second one is directory so it
indicate as “drwxr-xr--”.

Files permissions

Value Meaning
777 (rwxrwxrwx) No restrictions on permissions. Anybody may do anything. Generally
not a desirable setting.
755 (rwxr-xr-x) The file's owner may read, write, and execute the file. All others
may read and execute the file. This setting is common for programs
that are used by all users.
700 (rwx------) The file's owner may read, write, and execute the file. Nobody
else has any rights. This setting is useful for programs that only
the owner may use and must be kept private from others.
666 (rw-rw-rw-) All users may read and write the file.
644 (rw-r--r--) The owner may read and write a file, while all others may only
read the file. A common setting for data files that everybody may
read, but only the owner may change.
600 (rw-------) The owner may read and write a file. All others have no rights. A
common setting for data files that the owner wants to keep

Directory permissions

Value Meaning
777 (rwxrwxrwx) No restrictions on permissions. Anybody may list files, create new
files in the directory and delete files in the directory.
Generally not a good setting.
755 (rwxr-xr-x) The directory owner has full access. All others may list the
directory, but cannot create files nor delete them. This setting
is common for directories that you wish to share with other users.
700 (rwx------) The directory owner has full access. Nobody else has any rights.
This setting is useful for directories that only the owner may use
and must be kept private from others.

SU Command - temporarily become the superuser.

    It is often useful to become the superuser to perform important system administration tasks, but as you have been warned (and not just by me!), you should not stay logged on as the superuser. In most distributions, there is a program that can give you temporary access
to the superuser's privileges. This program is called
su (short for substitute user) and can be used in those cases when you need to be the superuser for a small number of tasks. To become the superuser, simply type the su command. You will be prompted for the superuser's password:

me@linux:~$ su
    After executing the su command, you have a new shell session as the superuser. To exit the
superuser session, type
exit and you will return to your previous session. 
     It is different in some distributions like Ubuntu. We can perform SU alternative type as sudo and some command as like follow

me@linux:~$ sudo

me@linux:~$ continue with commands as root user

chown - change file ownership.

    We can change the ownership of the files and directories by using the chown
command as follows

me@linux:~$ su
root@linux#chown you some_file
root@linux# exit
For Ubuntu users

me@linux:~$ sudo chown you some_file

Notice that in order to change the owner of a file, you must be the
superuser. To do this, our example employed the su command, then we
executed chown, and finally we typed exit to return to our previous
chown works the same way on directories as it does on files.

Chgrp - change a files and directories group ownership.

we can change group ownership of the files and directories.
me@linux:~$ chgrp
new_group some_file
If a file or directory relative to root user you change to su or add sudo
on above, we changed the group ownership of some_file from its previous group to "new_group". You must be the owner of the file or directory to perform a chgrp.