Tuesday, December 5, 2006

Welcome to Your Linux Filesystem

If you're trying Linux (or Unix) for the first time, you may be alarmed when you first see the filesystem. Windows users (who install fresh) are used to seeing something like this:

Volume in drive C has no label.
Voume Serial Number is EXPE-NSIV

Directory of C:\

12/05/2006 04:04 AM 0 AUTOEXEC.BAT
12/05/2006 05:34 AM 12,286,482 AVG7QT.BAT
12/05/2006 04:13 AM 241 boot.ini
12/05/2006 04:04 AM 0 CONFIG.SYS
12/05/2006 05:28 AM <dir> Documents and Settings
12/06/2006 01:22 AM 267,964,416 hiberfil.sys
12/05/2006 04:04 AM 0 IO.SYS
12/05/2006 04:04 AM 0 MSDOS.SYS
08/03/2004 01:38 PM 47,564 NTDETECT.COM
08/03/2004 01:59 PM 250,032 ntldr
12/06/2006 01:21 AM 402,653,184 pagefile.sys
12/06/2006 10:44 PM <dir> Program Files
12/05/2006 05:26 AM <dir> RECYCLER
12/06/2006 11:28 PM <dir> WINDOWS
10 File(s) 683,201,919 bytes
4 Dir(s) 984,405,442 bytes free

The picture in Linux is very different:

bin   cdrom  etc   initrd      lib         media  opt   root  srv  tmp  var
boot dev home initrd.img lost+found mnt proc sbin sys usr vmlinuz

As one continues to use Windows, the root directory of your boot drive continues to gain a few additional files (fewer in the latest versions than in the past, mostly all you'll see is logs now) In Linux, the root directory almost invariably remains pristine without much variation from the 22 items listed above. I never had anyone bother to explain these to me, so I thought this might be a useful subject to cover for those becoming acquainted with Linux for the first time.

/bin/ ... This is like the Windows folder (or more accurately, like the old DOS folder), in that it holds the basic system tools that all users may access. In Linux, these are considered "essential" programs.

/boot/ ... This folder holds the files for the boot loader. It is similar to ntldr on a Windows system.

/cdrom/ ... This is just a convenient symbolic link to /media/cdrom (see below)

/dev/ ... This folder holds devices, which in Linux are treated like files. The items listed in here are visualized in a method similar to serial ports (COM1, COM2) and parallel ports (LPT1) in Windows or DOS.

/etc/ ... System-wide program settings are held here. This is similar to the HKEY_LOCAL_MACHINE hive in the Windows Registry, or the "C:\Documents and Settings\All Users\Application Data" folder. For newer and more elaborate packages, a specific subdirectory within /etc is usually created to hold system-wide settings for the package.

/home/ ... Each local user gets a home directory here. This is similar to the "Documents and Settings" folder in Windows, with the root of each home directory being considered similar to the Windows "My Documents" folder.

/lib/ ... *.so Libraries (sets of compiled functions in shared object files, used by many programs) These are like the *.DLL files found in the C:\WINDOWS\System or C:\WINDOWS\System32

/lost+found/ ... This is where files recovered during a file system check (fsck) are placed. I like to think of it as similar in its temporary nature to the Windows RECYCLER folder, but it isn't really the same purpose. (Windows places deliberately deleted files in RECYCLER until you empty the Recycle Bin.) In reality, the Windows chkdsk utility saves recovered fragments directly in the root.

/mnt/ ... This is where mount points go for temporarily mounted filesystems. On Windows, you would use A: B: and possibly D: E: or F: for this sort of storage, but in Linux drives get mapped to a mountpoint in the root ("/") filesystem.

/media/ ... This is similar to /mnt, but specifically for removable media such as a CD-ROM drive which is typically found in /media/cdrom. On a Windows system, this would be found as D:, E:, or F:.

/opt/ ... Optional software packages are installed into this folder. It is similar to "Program Files" on a Windows system. In reality, this folder is slightly confusing and hardly used, it serves arguably the same purpose as /usr/local (see below)

/proc/ ... This holds a virtual filesystem with kernel and process information. There really isn't a Windows equivalent, but it gives access to information somewhat similar to what can be found in the Microsoft "System Information" tool (click Start, Help and Support. Click Support button on the Toolbar, under Tools and Links on the left side click Advanced System Information, and then in the details pane click View detailed system information. They make this really easy to get to. To do the same thing in Linux you type cd /proc)

/root/ ... This is the home directory for the main system administrator account. In Linux, the administrator is named root (because they have access to the whole filesystem from the root down). Root shouldn't represent an individual, but is an account used during administrative tasks by utilities such as sudo or su. Thus, the administrator will also have their own personal account, as well.

/sbin/ ... This folder is similar to /bin/ but contains utilities specifically for tasks restricted to the superuser (i.e. root, the system administrator). See also /usr/sbin, and /usr/local/sbin.

/tmp/ ... Temporary files. This is similar to C:\TEMP, C:\TMP, or "C:\Documents and Settings\UserName\Local Settings\Temp" on a Windows system.

/usr/ ... This contains "user" files, meaning non-system files (the system should be able to boot without these files). It contains another bin, lib, and sbin with like meanings to their root level counterparts, excepting that the files are non-essentials. It also contains include (standard include files) and src (kernel source code), which are useful for developers, X11R6 which is where the graphical "X Window System" resides, and local where another set of bin, include, lib, sbin, share, and src reside which are considered specific to this single host (machine). I should point out that /usr is limited to read only data. Host specific (machine specific) data is stored in /usr/local rather than directly in /usr.

/var/ ... Variable files. This includes logs, databases, websites, and temporary email files. There is another tmp folder in here, which is preferred in lieu of /tmp when the system is in multiuser mode.

I will soon post a follow-up article on Filesystem Permissions in Linux.

No comments: