Welcome Guest! To access all forums & features, please register an account or sign-in. → Why register?



[FAQ] Linux File System Overview


53 replies to this topic * * * * - 3 votes

#1 vetmarkjensen

    Linux noob since Red Hat 5.1

  • 24,481 posts
  • Joined: 02-October 03
  • Location: Middle Tennessee

Posted 22 December 2004 - 18:41

"This Linux file system is crazy..."

This FAQ is a quick overview that I have written to summarize how the files are generally organized into their directories. I have often described this, in the past, as looking at a vertical vs. horizontal method of determining where different files should be placed. :blink: However, that doesn't really clear things up for 99% of the people I have tried to describe this to, so I will attempt to better explain this here. I will cover the file & directory organization in very broad brush strokes. For more detailed information, there are thousands of in-depth resources to be found with a brief google. Most Linux books cover this as well (but are often skipped as they aren't readily understood by most people who haven't worked with Linux for a while).

Half Full Glasses and Photos
The first thing (or one of the first things, anyhow) that a Windows user who has moved to Linux (or any Unix-like OS) must shed is the belief of How Things Should Be. Just because one OS does things a certain way, doesn't mean that any other way is 'wrong'. Like whether you consider a glass to be half-empty or half-full, it is a matter of perspective.

Consider this to be like your digital family photos on your computer. You may keep your files organized by year (2003, 2004, 2005, etc.) and keep the sets of photos belonging to the separate events (Michael's Birthday or Joshua's Football Game) in their own folders inside each year. It is a convenient way to see all the events of each year, plainly organized in front of you when you open that 2004 folder.

But, that isn't the only way that photos can be organized. If you want to go to all of the "Summer Vacation" photos and reminisce about the all family vacation fun you have had, you will find them scattered into all the various year folders. This brings up another way photos can be organized: by subject. This can be done on your family photos, so that all the Birthdays that Timothy has had through the years can be found in their own specific folder. Modeling agencies would almost have to sort by model name, not by year of photo.

Windows and Linux Directories
What that talk about photos have to do with Linux file organization? Quite a bit, actually.

Windows organizes installed applications by their own folder in "My Programs". Each app creates a folder for everything to go into. This may sound extremely neat, but Windows really isn't as neatly organized as the that made it sound. It scatters .dll files around to different folders and modifies the registry, too. Try copying an app by moving the "Program Files" folder to a new computer, and it won't function.

Linux, on the other hand, puts all "executables" (or "binaries") into a bin/ directory. You won't find the man pages (help files) in there, as those are placed in the man/ directory. Any source code you have on your system will be in a src/ directory. It's a different way of seeing how a file system should be organized, and quite often it seems counter-intuitive to a Windows user.

Ok, Why so Many?
While the concept of bin/ may be easy enough to understand, Windows users will next run into the many different bin/ directories (and sbin/, for system binaries that are usually reserved for users with elevated privileges). Often this will be the next big stumbling block. After all, it just seemed to make sense - then they find that there is no "one place" for these binaries.

This is understood when you really accept that Unix has been a multi-user system for quite a long time (longer than Windows has been around!), and its filesystem reflects this. Different conventions exist, and the following is not a fact for all systems, but is meant to illustrate by example:
  • The basic OS installs what it needs in /bin/. Everyone needs to have access to these basic functions.
  • The distro will often install and additional apps it uses into /usr/bin/. Again, all users may have access to this.
  • Add-ons may be installed into /usr/local/bin/, as these files are local to the machine you are working on, and may not exist on another PC, even if installed with the same version.
  • Users without write/execute permissions outside their home directory may use /home/username/bin/, so they can have their own executables that are unique to them (perhaps they are learning C and making test programs).
To see what your particular system is set to look for any binaries you ask it to run, perform an
echo $PATH
to see what directories it uses.

File Extensions...
This is another piece of baggage from the days of DOS, and even Windows attaches great significance to a file extension. In particular, the whole .exe thing is thrown away in Linux. Not only a compiled binary file, but any file may be made "executable" by setting the proper file attribute (either via chmod at the command line, or by mouse click on Properties using the more advanced file managers available with Gnome or KDE). A text file can be made executable, which is then interpreted like a DOS .bat "batch file".

Hidden Files
Files in Unix don't have a "hidden" attribute. A file (or directory) is considered hidden when you start the filename with a dot. For example, the file .bash_history (which contains the last several hundred commands you have issued at the bash prompt) in your home folder is not shown by a plain ls command. If you wish to see the hidden files, you can use ls -a to display all files.

Almost Everything is a File!
Or, if not a file, then it is represented in the Linux file system. Your devices are all in the /dev/ folder. Various system and kernel information is represented (and can be set!) in the /proc/ directory. An interesting task is to do a cat /proc/cpuinfo and look what Linux tells you about your CPU.

The Forward Slash: The 'root' of all Goodness
Unlike what a DOS/Windows user is used to, drives (or, more accurately, partitions are not set up each as separate "tops" of the file tree. There is no C:\filename.ext with no file system above. All partitions that are mounted are assigned to a folder (typically in the /mnt/ directory). Unix and all variants use the forward slash '/' as the starting point for all file references, regardless of which drive, network attachment, or device you are referring to. There is no need to care whether /home/, /boot/, /mnt/cdrom or /mnt/windows_c are on your "Linux drive", or if they are elsewhere. Even devices such as scanners are found in the file tree. It can be a strange concept when you first migrate to Linux, but it makes sense when you become used to it.

More awaits you...
Alas, I will end this here. This little FAQ just touched on the filesystem that Linux (and other Unix variants) use to keep things organized. It may seem totally foreign at first, but once you get used to thinking the *nix way, things do get easier.

In closing, I would like to invite anyone else that wants to add to this with some additional detail or information that I did not cover, please post this information as an "addendum" to this first post. Or, if you feel particularly energetic, write your own short HOWTO or FAQ for the Linux section.



As always, those of you who are reading this and notice an error in what I have said, please let me know so that it can be corrected.

EDIT: I forgot to include a couple of links to some more detailed references. :blush:
http://www.comptechdoc.org/os/linux/comman...x_crfilest.html
and
http://web.archive.org/web/20050310142547/...p?articles_id=6
may be of interest...
Also: Filesystem Hierarchy Standard:
http://www.pathname.com/fhs/

Edited by markjensen, 27 June 2007 - 01:18.



#2 Hurmoth

    Neowinian Super Star

  • 20,303 posts
  • Joined: 09-March 03
  • Location: Virginia

Posted 22 December 2004 - 18:59

Awesome... thanks for the info (Y) Not a big Linux person, yet, so this really helps!

Edited by Hurmoth, 22 December 2004 - 19:05.


#3 Rix

    -_-

  • 3,915 posts
  • Joined: 20-February 04
  • Location: Bradford, UK
  • OS: Windows 7

Posted 22 December 2004 - 22:49

Wow, thanks for that info :D

#4 vetrezza

    They will return

  • 3,481 posts
  • Joined: 17-December 02
  • Location: Edinburgh, UK

Posted 23 December 2004 - 14:50

/bin : system-wide binaries essential to the running of the system
/boot : often separated from the root filesystem (ie on another partition) and contains the actual kernel as well as bootloader config files
/dev : a directory full of devices, populated either by the "devfs" filesystem, or more recently "udev". Really old systems had to have this directory filled with device nodes manually.
/etc : contains configuration files for the system, as well as stuff which doesn't fit into any other directory
/home : contains users' home directories
/lib : system-wide libraries essential to the running of the system
/lost + found : the directory to find things after your drive has been fscked (fsck = file system check)
/media : removable drives (such as CDs, DVDs, floppies) should be mounted to a sub-directory of this dir
/mnt : static filesystems (such as windows drives, etc) should be mounted to a sub-directory of this dir
/opt : used for add-on apps and some other software packages
/proc : a virtual filesystem which contains information about your system
/root : the root user's home directory
/sbin : system binaries, where things that are essential to system maintenance but not to normal users go
/sys : another virtual filesystem, which gives information on the running kernel, and can be used to pass options to the kernel during operation
/tmp : system-wide temporary files
/usr : this directory normally contains a whole new filesystem heirarchy, with its own bin, include, lib, and sbin subdirectories. This is where most installed software should put its binaries and libraries, as well as default option files (normally in /usr/share/<appname>). The /usr directory helps to keep files essential to the running of the system/OS separate from user-installed applications.
/var : contains variable data files such as mailboxes, news directories, spooling files, and logs.

#5 enklus

    ARRR!!!!!

  • 1,518 posts
  • Joined: 06-August 03
  • Location: CIA safehouse

Posted 23 December 2004 - 14:52

Thank you very much! (Y)

#6 macssuck

    Neowinian²

  • 173 posts
  • Joined: 19-December 04

Posted 24 December 2004 - 05:54

markjensen, on Dec 22 2004, 12:41, said:

File Extensions...
This is another piece of baggage from the days of DOS, and even Windows attaches great significance to a file extension.  In particular, the whole .exe thing is thrown away in Linux.  Not only a compiled binary file, but any file may be made "executable" by setting the proper file attribute (either via chmod at the command line, or by mouse click on Properties using the more advanced file managers available with Gnome or KDE).   A text file can be made executable, which is then interpreted like a DOS .bat "batch file".
The primary reason file extensions are considered a bad idea are because they contain important meta-data about a file (what it is and to a lesser extent what to do with it) in a place that's easy to edit/change or corrupt. Why should it matter what your files are named when you have a billions of CPU cycles that could be used to figure out what they are and what to do with them? UNIX-like operating systems follow this mantra as do other operating systems like BeOS and Mac OSDiscovering Specific File-type Information Without Extensions Using a CLI/b>
Tfile/i>[1] is used for finding content-type information about a file. The commafile somefile.xyz/i> will look at somefile.xyz and determine what kind of information is stored inside by performing a series of tests. The exact nature of the tests and the file-type information is controlled by tmagic/i>[2] file is typically found /usr/share/file/magic/i>. It is possible to add tests and associated file types to the magic file but there is little need because most distributions ship with a fairly comprehensive magic file.

An example of the file command's out put is:
[code]
$ file /bin/ls
/bin/ls: ELF 32-bit LSB executable, Intel 80386, version 1, for OpenBSD, dynamically linked (uses shared libs), stripped

$ file /usr/share/pf/faq-example1
/usr/share/pf/faq-example1: ASCII text

$ file /sys
sys: broken symbolic link to `usr/src/sys'

$ file /dev/tty01
/dev/tty01: character special (8/1)
[/codeGeneric File Information With the ls Command/b>
If you want more generic information about a file like whether it is a directory, block device, ascii file, link, socket, etc. then you can use tls/i>[3] command along with either t-G/i> --color/i> arguments (variable depending on your OS).BSD tends to use -G to colors output, Linux tends to respond to --color or -G, and some *NIX operating systems won't color output at all so you will need to install GNU/ls from the GNU File Utilities[4] to get color outputls -G/i> ls --color/i> will show directories in a dark blue, named pipes in yellow, symbolic links in purple, executable files in green, etc.

If you have trouble seeing color or you are using a terminal device that does not support ANSI colors then you can use t-F/i> argument wils/i> to display special characters after the file names instead of or in addition to color information. symbolic links have an "@" character after their name, executables are marked with a "*", and directories with a "/", etc. More information can be found in tman page for ls/i>[3].

The colors used for differentiating files are controlled by the LS_COLORS environmental variable which can be configured using tdircolors/i>[5] command. The specifics of colorizils/i> output are worth of their own FAQ.

It is also perfectly acceptable to use file extensions if you want to. You are free to continue naming your JPEG images with .jpg extensions, doing so may save you a lot of hassle if you ever need to access those files on Windows (as an example). *NIX doesn't force you to use file extensions a certain way, but it doesn't penalize you either.

--Edit 1--
[1] Die.net: file(1): Determine File Type Information - Linux Man Page
[2] Die.net: magic(5): File Commands Numbers File - Linux Man Page
[3] Huntsville Macintosh User Group: Mac OS X / Darwin Man Pages
[4] GNU Operating System - Free Software Foundation: Fileutils
[5] Rt.com: Unix Man Pages: dircolors(1)

Edited by macssuck, 24 December 2004 - 06:14.


#7 anir

    .

  • 183 posts
  • Joined: 01-December 04

Posted 24 December 2004 - 15:48

Nice overview, but I thought this topic would be about file systems like ext2, ext3, XFS, ReiserFS, etc...

And there are no "folders" in a file system, only directories.

Edited by anir, 24 December 2004 - 15:54.


#8 Knight'

    OS agnostic

  • 3,983 posts
  • Joined: 28-December 02
  • Location: United Kingdom

Posted 24 December 2004 - 16:28

anir, on Dec 24 2004, 16:48, said:

Nice overview, but I thought this topic would be about file systems like ext2, ext3, XFS, ReiserFS, etc...

And there are no "folders" in a file system, only directories.

View Post


That's interesting, what's the difference between a Folder and a Directory?

#9 ChuckFinley

    Neowinian DOMINATING

  • 8,637 posts
  • Joined: 14-May 03

Posted 24 December 2004 - 16:31

anir, on Dec 24 2004, 16:48, said:

And there are no "folders" in a file system, only directories.

View Post


Arent they the same thing :huh:

#10 OP vetmarkjensen

    Linux noob since Red Hat 5.1

  • 24,481 posts
  • Joined: 02-October 03
  • Location: Middle Tennessee

Posted 24 December 2004 - 20:54

Sawyer12, on Dec 24 2004, 11:31, said:

Arent they the same thing  :huh:

View Post

Normally, in the *nix world they are referred to properly as 'directories'. A 'folder' is a GUI representation that sort of symbolizes the concept visually.

#11 tiagosilva29

    If you're in trouble PM me

  • 11,890 posts
  • Joined: 08-May 04

Posted 26 December 2004 - 03:01

Very useful guide, thanks (Y) :D

#12 SaguratuS

    Follower of Gentooish Ways

  • 1,451 posts
  • Joined: 30-May 02
  • Location: Colorado

Posted 26 December 2004 - 09:31

(Y)(Y)(Y)
Another good one Mark :)
Perhaps adding the differences between FS types might be beneficial? I see a lot of users pick ext3 by default since they are unaware of the differences. But I guess I'm just a die-hard gentoo / reiserfs fan

#13 OP vetmarkjensen

    Linux noob since Red Hat 5.1

  • 24,481 posts
  • Joined: 02-October 03
  • Location: Middle Tennessee

Posted 26 December 2004 - 15:07

SaguratuS, on Dec 26 2004, 04:31, said:

(Y)(Y)(Y)
Another good one Mark :)
Perhaps adding the differences between FS types might be beneficial? I see a lot of users pick ext3 by default since they are unaware of the differences.  But I guess I'm just a die-hard gentoo / reiserfs fan

View Post

Thanks! But I don't know much about the different filesystem types, except what I have read. Maybe you could write something up, and explain the differences (and advantages/disadvantages)?

#14 Rablet

    Resident Elite

  • 1,283 posts
  • Joined: 20-May 04
  • Location: Sweden

Posted 26 December 2004 - 15:13

Thanks for a very good guide!

#15 cork1958

    Neowinian

  • 6,569 posts
  • Joined: 04-October 02

Posted 26 December 2004 - 15:23

Whoa! Awesome!! Double thanks for the info. Tracking this topic for future reference while trying to figure out this OS.