23
Dec
07

Linux Directory Structure

The directory structure of Linux/other Unix-like systems is very intimidating for the new user, especially if he/she is migrating from Windows. In Windows, almost all programs install their files (all files) in the directory named: `Program Files.’ Such is not the case in Linux. The directory system categorises all installed files. All configuration files are in /etc, all binary files are in /bin or /usr/bin or /usr/local/bin. Here is the entire directory structure along with what they contain:

/ – Root directory that forms the base of the file system. All files and directories are logically contained inside the root directory regardless of their physical locations.

/bin – Contains the executable programs that are part of the Linux operating system. Many Linux commands, such as cat, cp, ls, more, and tar, are locate in /bin

/boot – Contains the Linux kernel and other files needed by LILO and GRUB boot managers.

/dev – Contains all device files. Linux treats each device as a special file. All such files are located in /dev.

/etc – Contains most system configuration files and the initialisation scripts in /etc/rc.d subdirectory.

/home – Home directory is the parent to the home directories of users.

/lib – Contains library files, including loadable driver modules needed to boot the system.

/lost+found – Directory for lost files. Every disk partition has a lost+found directory.

/media – Directory for mounting files systems on removable media like CD-ROM drives, floppy disks, and Zip drives.

/mnt – A directory for temporarily mounted filesystems.

/opt – Optional software packages copy/install files here.

/proc – A special directory in a virtual filesystem. It contains the information about various aspects of a Linux system.

/root – Home directory of the root user.

/sbin – Contains administrative binary files. Commands such as mount, shutdown, umount, reside here.

/srv – Contains data for services (HTTP, FTP, etc.) offered by the system.

/sys – A special directory that contains information about the devices, as seen by the Linux kernel.

/tmp – Temporary directory which can be used as a scratch directory (storage for temporary files). The contents of this directory are cleared each time the system boots.

/usr – Contains subdirectories for many programs such as the X Window System.

/usr/bin – Contains executable files for many Linux commands. It is not part of the core Linux operating system.

/usr/include – Contains header files for C and C++ programming languages

/usr/lib – Contains libraries for C and C++ programming languages.

/usr/local – Contains local files. It has a similar directories as /usr contains.

/usr/sbin – Contains administrative commands.

/usr/share – Contains files that are shared, like, default configuration files, images, documentation, etc.

/usr/src – Contains the source code for the Linux kernel.

/var – Contains various system files such as log, mail directories, print spool, etc. which tend to change in numbers and size over time.

/var/cache – Storage area for cached data for applications.

/var/lib – Contains information relating to the current state of applications. Programs modify this when they run.

/var/lock – Contains lock files which are checked by applications so that a resource can be used by one application only.

/var/log – Contains log files for differenct applications.

/var/mail – Contains users’ emails.

/var/opt – Contains variable data for packages stored in /opt directory.

/var/run – Contains data describing the system since it was booted.

/var/spool – Contains data that is waiting for some kind of processing.

/var/tmp – Contains temporary files preserved between system reboots.

About these ads

49 Responses to “Linux Directory Structure”


  1. December 24, 2007 at 6:12 am

    Thanks for the information!
    This little write up gave me more information than my two Linux college classes! (It’s alot cheaper too!)

  2. December 24, 2007 at 6:34 am

    A very promising beginning. Please keep blogging about this stuff.

  3. 3 Eddie Pasternak
    December 24, 2007 at 6:48 am

    Thanks!. For those who want a 100+ page guide
    to the Linux Filesystem Heirarchy, search the
    web for

    Linux File Hierarchy Binh Nguyen

  4. December 24, 2007 at 6:55 am

    thats a bunch of structure. hopefully after i get this new dell linux box, those [and many other linux] things will just become second nature like all that dos shit did back in the day.

    Taking Over The Net

  5. 6 Russell
    December 24, 2007 at 6:56 am

    Throw in that every distribution is just a little bit different and you wonder why average people don’t switch.

    OSX is still the best *nix based OS, and Windows is still the standard for many good reasons.

  6. 7 beargulch
    December 24, 2007 at 7:09 am

    Very useful, and thanks! Just one comment: in Windows, all programs install *some* of their files in c:\Program Files. But they also spray files all over the place, including c:\WINDOWS, and the registry. Linux can be more contained than that, and in general, Macs are new even better at keeping files contained in /Applications, and a few preference settings in ~/Library/preferences.

  7. December 24, 2007 at 7:15 am

    This is a great list. IT IS VERY INTIMIDATING INDEED TO HAVE TO VIEW ALL THOSE DIRECTORIES. Windows plops them all the c:/Windows folder. While our “personal” files are under My Documents.

    In a broad sense I think they did that to make Windows more user friendly.

    I hope sometime in the future – Linux adopts the same folder structure.

  8. 9 Maarten
    December 24, 2007 at 7:19 am

    Cool info, thanks!

  9. 11 tom
    December 24, 2007 at 7:32 am

    you forgot /dev/null ;p

  10. 12 Benoit
    December 24, 2007 at 8:27 am

    As someone who has been in the process of migrating to linux, understanding the file system is quite helpful.

  11. December 24, 2007 at 8:37 am

    Very well written thanks alot for your walkthrough.

  12. 14 Nate
    December 24, 2007 at 8:40 am

    A good breakdown.. It’s still fairly general though.

  13. 15 bob
    December 24, 2007 at 8:48 am

    this is very subjective, and somewhat inaccurate.

  14. 16 bob
    December 24, 2007 at 8:50 am

    I’ll be happy to clarify if needed… technically nothing outside the Kernel is part of the core operating system… Solaris focuses on /opt rather than on /usr/local for optional files. /var/mail is the local mailspool, not the users email box in the sense that it is above.

  15. 17 Sx66gns
    December 24, 2007 at 8:54 am

    Quality write up! good job.

  16. 18 ALok
    December 24, 2007 at 9:50 am

    /lost+found is only on ext partitions

    /media and /srv are not always there

  17. 19 Alex Dunlop
    December 24, 2007 at 10:10 am

    Thanks a ton! I just switched to Linux and that definitely helped me out. P.S. You’re on digg: http://digg.com/linux_unix/Linux_Directory_Structure_2

  18. 20 jim slaybaugh
    December 24, 2007 at 10:44 am

    Very helpful-thank you..

  19. December 24, 2007 at 10:48 am

    Very basic, but I’m sure it is helpful to some people.
    Congrats, you’re on the Digg Front-page.

  20. 22 kishore
    December 24, 2007 at 11:02 am

    nice and useful description!

  21. December 24, 2007 at 11:22 am

    You forgot /opt and /proc ;)

  22. December 24, 2007 at 11:33 am

    Good one ALoK! I had forgotten about /media, I reprogrammed my computer to put /media’s contents under /mnt. I also put all NFS imports there.

    /srv is there on several modern distributions; however my professional recommendation is that its contents actually be integrated into /var. For instance if HTTP server’s files are /srv/www they should be /var/www in my opinion, in most cases.

  23. 25 Angus
    December 24, 2007 at 11:43 am

    Keep going, thanks for this wonderful tutorial

  24. December 24, 2007 at 1:01 pm

    good job buddy. it’s really helpful :)

  25. December 24, 2007 at 1:11 pm

    I encourage you to take a look at GoboLinux (http://gobolinux.org/?page=at_a_glance) – the only distro that tries to do away with this outdated philosophy and propose a revised hierarchy.
    It might give you a good insight on what is going on regarding the whole thing.

  26. 28 mjc
    December 24, 2007 at 1:17 pm

    dannybuntu said:
    “Windows plops them all the c:/Windows folder. While our “personal” files are under My Documents.
    I hope sometime in the future – Linux adopts the same folder structure.”

    It seems like they already do. In Windows it’s “My Documents” and in *unix it’s “Home”.

  27. December 24, 2007 at 1:30 pm

    please get an RSS feed ASAP.

    this is the kind of stuff that forums and tutorials leave out.

    Very good work.

  28. December 24, 2007 at 1:32 pm

    Quite informative,

    However, if this directory structure corrupts and you are not able to access your saved information.

    That means you need a Linux data recovery software

    http://www.stellarinfo.com/linux-data-recovery.htm

  29. December 24, 2007 at 5:07 pm

    Keep up the good work.

  30. 32 v1ncent
    December 24, 2007 at 7:15 pm

    What about this Directory Structure:

    http://docs.google.com/View?id=dff6bkv5_12fwctx9&pli=1

    Is based on the GoboLinux directory structure.

    I think we must think A LOT about this subject, and find the perfect directory structure for Linux.
    This is my contribution.
    – – – –
    I don’t like the Linux Directory Structure not because im a Windows fan, but because i want to make Linux better.
    You see, the actual directory structure would be perfect for DEVELOPERS, would be perfect for a FEW programs, but is not perfect for hundreds of programs and for users that are not developers.
    That’s what i think… Im not saying that the actual directory structure is pure crap, but is not ideal nor perfect for all of us, nor for the growth of Linux.

  31. 33 Anon
    December 24, 2007 at 7:24 pm

    THANK YOU!! Seriously! THANK YOU! I switch to Linux in spring … and had still yet to define what every dictionary was for. What’s even more sad than that? The fact that my countless searches never once turned up with something like this! THANK YOU!

  32. December 24, 2007 at 7:46 pm

    Compliment and thanks for the info :)

  33. December 24, 2007 at 10:17 pm

    Thanks for that, man. I’ve been praying for that info for years!
    ~ from Brazil

  34. 36 yogi-one
    December 24, 2007 at 11:46 pm

    Very nice. How about a tree diagram to go along with it? Also useful if tree goes down to the webserver, like showing the apache directory substructure.

  35. December 25, 2007 at 1:16 am

    Very nice synopsis.
    Might I suggest another topic? Covering the first minute or so of the life of a linux box, from BIOS, to the bootloader, to the kernel unpacking itself, to init and the starting of services. I think it might give a complimentary view of the core proecesses that inhabit this directory structure.

  36. December 25, 2007 at 2:36 am

    To anyone who thinks that Linux aught to rearrange its directory structure.

    1) I understand your reasoning
    2) However, Windows is not UNIX and Linux is not UNIX either but is so close that it doesn’t matter
    3) Therefore Linux should behave like UNIX and not like Windows.
    4) The UNIX directory structure is logical (with the exception of /opt)
    5) The Windows directory structure was cobbled together without any thought.
    6) Therefore Linux should not remove the UNIX directory structure.

    (P.S. old does not mean obsolete)

  37. December 25, 2007 at 5:11 am

    Check this link out…

  38. 40 vgiszpenc
    December 26, 2007 at 10:47 pm

    You should make recommendations about putting which directories on which of how many partitions. It would be more details on the same subject which would be even more helpful.

    Thanks

  39. January 3, 2008 at 10:05 am

    Just type man hier. It will likely be more complete and up-to-date than this blog post.

  40. January 3, 2008 at 5:00 pm

    As a linux newbie, one of my first “problem” was when I tried using a second partition, and later a second hard disk to my Ubuntu installation. I couldn’t find any info on where I should mount it to.

    What is the “standard” operation for multiple disks on Linux?

  41. February 15, 2008 at 1:03 am

    Hello all, nice article, its extremely well written and easy to understand. thanks for sharing it with us.
    Best Regards

  42. February 21, 2008 at 7:02 pm

    Hi all, that was very very useful info… before reading this I was always wondering what this “/” this is all about (!!!!!!!) and now I am feeling very comfortable with that…thnx a lot to the writer.
    thnx and reds…Rajendra Uppal


Leave a Reply

Fill in your details below or click an icon to log in:

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


Follow

Get every new post delivered to your Inbox.

%d bloggers like this: