More on the Linux File System

May 11, 2010

Some of you might remember when I did a few post on the Linux file system.  If not, or you would just like to reread them just follow these links: part1, part2, and part3.  I’ll admit that I didn’t finish this series as I had originally planned, but it does provide a good place to start learning.  Maybe one day I’ll try and finish/improve upon this series, but I won’t hold your breath.

For those of you that would like to learn more about the file system you can either go to Google or you can run the command man hier from the terminal.  This will provide you with a general overview of each of the partitions for the file system.


Linux File System: Part 3

September 15, 2009

Well sorry it has taken so long but here is the third installation in the series on the Linux file system. In case you haven’t been following before now, here are the links to part1 and part2.

In this portion I will discuss the following directories/partitions: /lost+found /lib /mnt and /tmp.

/lost+found

So you are working and all of a sudden there is a power outage. Or even worse your system suddenly crashes for no reason. Well the next time you boot up your machine Linux will try to recover any lost data/files. The result of this recovery attempt will be saved here. Sure the files in here might not make much sense but there is a small chance that there might be something that you might be able to actually use. Finally, for those of you that really want to know, this recovery is done by using the fsck command. Look into it yourself, since this isn’t the place to go into depth on it.

/lib

The location of all the shared library files. Think DLL files on Windows.

/mnt

This is the generic place to mount other file systems. Such as internal/external hard drives, CD-ROMS, DVD, and floppy disk if people still use those. For more information on mounting see the link to the post dedicated to this topic.  But I should mention that you can make any location a mount point, but it’s usually a good idea to have them all relatively “close” to each other.  Plus try not to overdo it, because really 50 different mount points might just be a little excessive.

/tmp

Temporary files are stored here. In other words, DON’T SAVE IMPORTANT STUFF HERE! This directory is cleared upon each reboot of the system. As a side note, this is really useful for getting around disk quotas. Just save your files here and then when you restart they will be gone. All you have to do is make sure that you won’t be needing those files ever again.


Linux File System: Part 2

September 7, 2009

This is a continuation from part 1, so you might want to read that first in order to get a general idea of what’s going on.  That is  of course you are a somewhat experienced Linux user.

In this part of the series I will be discussing the following directories/partitions: /bin /boot /dev /etc /home.

/home

I will start by discussing the partition that is most familiar to most new users, /home.  First you should know that Linux, unlike Windows, was originally designed to be a multi-user system.  Thus in the home directory you will find a set of directories, one for each user.  Every user (along with the system administrator) can access their directory by entering cd /home/[user name].  Each user’s home directory contains their own personal files in addition to their personal settings for programs.

/bin

This directory contains programs that are able to be used by the system(Linux), the administrator and non-privileged users. Examples of such programs would include cp, mv, rm, and other such commands/programs. In addition to programs it also contains the shells, like bash, csh, sh, and so on. Just as a side note, you should be aware that there is also a /usr/bin which also contains programs that the system, administrator, and non-privileged users can use. However, unlike those in /bin, these programs are not essential-meaning that you can do without them and not have any real problems. Some programs that are located in my /usr/bin are: g++, apt-get, javac, whoami, and acroread. Sure it would be a pain not having these programs, but the system would still run perfectly fine.

/boot

All of the system startup files and the kernel (vmlinuz) are located in this directory (also I would suggest reading the Wikipedia article on System.map, which is also stored in this directory). On Ubuntu, this is also where Grub (GRand Unified Boot loader) stored.  For those of you that are dual-booting here is something that might interest you.  When you start up your system you will normally see a list asking you which OS you want to enter.  This list normally contains the various Linux kernels along with Windows (or whatever OS you have on your computer).  If you would like to change the order these elements are presented along with other properties here is what you need to do.  cd /boot/grub then sudo gedit menu.lst (actually you can use whatever text editor you desire)  The file is pretty well documented so editing it is pretty straight forward.

/dev

All computers have hardware, and this is where the information on all your hardware is stored. Once again let me reiterate that EVERYTHING is a file (or directory but I don’t distinguish between them in this case). If you list all of the files here, you should find sda, sda1, sda2… which represent the partitions of you master drive (instead of sda you might have hda depending on your drive type). Also you might see a files /dev/cdrom and /dev/fd or (/dev/fd0). These represent your CDROM and floppy drive (if you have them that is, because really who still has a floppy drive?). Here is something “cool” that you should all try (don’t worry it won’t damage your computer. I have done it on mine if that makes you feel any better). The file /dev/dsp represents your speakers (or whatever sound output device you have). So anything written to this file will be redirected to your speakers and played for you to hear. Thus if you run cat ~/funfile.java > /dev/dsp you will hear what funfile.java “sounds like”, assuming that you have a file called funfile.java in your home directory. Pretty cool hu?

/etc

Finally, I will slightly discuss the /etc directory.  One overview that I read, described this directory as the Linux equivalent to the Control Panel in Windows.  Basically most of the important configuration files are located here.  There are a lot of important files here that have to do with system start up (one being /etc/rc.d which contains the startup scripts for the system). It is always a good idea to back up your system, but this file more than any other I would say should really be backed up. Doing so would save you a lot of headache later when you have to reconfigure your settings, because you reinstalled your system or somehow managed to lose your installation.

Well that’s all there is for part 2. Hope you will stick around for part 3.


Linux File System: Part 1

September 5, 2009

You just moved over from Window and are now working with Ubuntu.  The only problem is that you have no idea how the file system is laid out.  In Windows you know that there are partitions D:\ (usually the recovery partition/drive) and C:\ (which acts like the main partition/drive).  Even further, these partitions are visible when you boot up your computer so you don’t have to worry about mounting them.

Now as for a Linux system, EVERYTHING IS A FILE!!! (and if it isn’t a file it’s a process).  Directories like /home (similar to C:\Users\[user name] in Windows) is just a special kind of file, that contains “pointers” do it descendants.  At this point I should mention that in Linux the file system is set up like a tree, with root node /.  Those of you that are familiar with working in DOS will have to get use to using / to navigate between directories and not \.  Really it’s not that hard to do, but does take some getting used to.  And if you are going to say “Why does Linux not adhere to the standard?” Just remember that Linux is based off of Unix which has been around much longer than Windows.  Additionally Windows doesn’t have a great track record when it comes to adhering to standards (IE for example).  Something else to keep in mind is that file names are case sensitive.  That means that THIS.txt is different from tHiS.txt or This.txt and even this.txt.  In Windows this isn’t the case (Thanks Kevin telling me this.  I always entered file names as if they were case sensitive when working with Windows.)

Remember earlier when I said that under Windows you don’t have to mount drives/partitions once you boot up the system?  Well under Linux you don’t have this convenience.  However, there are some advantages to this set up, so you shouldn’t cry too much.  For instance the /usr (the file that contains most of the system executables, I’ll talk about this more later) can be mounted from another computer on your network and everything will work just fine.  Just try moving the folder C:\WINDOWS to another location (have fun fixing your registry errors if you actually do this by the way).  The reason this will work under Linux is because it will still see /usr as a local directory that’s part of the local directory structure.

It is finally time to talk about the different parts of the Linux file system. To see what the directories under / are just go to that directory and enter ls -p. The entries with a / after them are directories, everything else is just a regular file.
On my system the list of directories is:

/bin /boot /dev /etc /home /initrd /lib /lib32 /lost+found /media /mnt /opt /proc /root /sbin /srv /sys /tmp /usr /var

The /lib32 directory seems to be special to 64-bit machines so I won’t be talking about it. However, I figure that it is similar to /lib, but provides support for 64-bit systems.

In part 2-and part 3, if it is needed, I will discuess each of these directories.  Nothing too detailed but it should provide you with a good starting point.