Wednesday, 12 March 2008

Meeting the Linux Filesystem

Among the many differences between Windows and Linux, the filesystem is one of the most significant. While both are logical, the difference may take some getting used to.

One of the most significant changes is that while Windows keeps all system files in one directory, Linux (and its Unix cousins such as FreeBSD or Mac OS X) spreads them out a bit more.
Everything in Linux is relative to the root directory. This is referred to by the system as /. To demonstrate this, open the terminal and enter the following:
cd /

Follow this with the following:
ls

The cd / command moves you to the root directory. The ls command then lists the files in that directory. Here's my output from this:
bin cdrom etc initrd lib media opt root srv tmp var
boot dev home initrd.img lost+found mnt proc sbin sys usr vmlinuz
Equally, you can use a file manager such as Nautilus or Konqueror to view your root directory. Konqueror allows you to specify the path to a folder to view it, so in the URL bar you can just enter / to view the root directory. Other file managers, such as Nautilus, don't all support this, so for these you can just keep moving up through the directories to reach the root directory.

One important point - don't confuse this with the root user! Think of the filesystem as a tree, with the root directory being the base of the tree and the folders being branches on that tree.

Now, I'll tell you what the individual folders are for:
  • /bin - Essential commands for your system
  • /boot - The information used to boot your system, including the Linux kernel
  • /dev - Device drivers
  • /etc - Configuration files for your system
  • /home - This directory contains the home folders of all users on the system. For instance, as I'm the sole user on my laptop, the /home folder contains one folder, which is /home/matthew. This contains all your settings and preferences as hidden folders, together with anything you choose to save there.
  • /lib - The libraries that many programs use.
  • /media - This is where the system adds temporary media such as floppy disks or CD-ROM's. When I connect my iPod Shuffle to my Kubuntu laptop, it gets mounted by default to /media/ipod.
  • /mnt - This is where you add extra filesystem components such as networked drives. Basically, anything that's not permanent, but less temporary than the kind of things that go in /media.
  • /opt - This is generally used for installing new software. Not all programs installed by apt-get or dpkg use this by default though. If you ever have to install something from tarballs (a common format for applications packaged for any Linux distribution), this is a safe place to install it.
  • /proc - Current settings for your kernel.
  • /root - The root user's home directory. As Ubuntu doesn't have a separate root account, you may find this doesn't get used much.
  • /sbin - Commands the system administrator needs.
  • /srv - Data for your system's services.
  • /sys - Kernel information about your hardware.
  • /tmp - Temporary files.
  • /usr - This is virtually a separate filesystem in its own right! Contains a huge number of important files and folders.
  • /var - Data that changes frequently, such as log files and mail.
So, that's the Linux filesystem. You'll be using it a lot, so it pays to get at least some idea of what's in it. A word of warning though: don't mess around with the bin, boot, dev, etc, lib, proc, sbin, srv, or sys folders unless you know what you're doing! Also, usr contains lots of subdirectories which you should leave alone. I'll discuss the /usr subdirectories in detail next time.

2 comments:

  1. Hey first I want to say that I enjoy your blog. There is always something to learn from it.

    Just a minor correction on nautilus. You can type in a full path, by first clicking the pad/pencil button in the upper left. Then an entry box will show, where you can directly enter th path.

    I personally enjoy using krusader, which is a twin-view file manager, like the classic midnight commander. It's pretty easy for manipulating files between two directories.

    Buzz

    ReplyDelete
  2. Thanks for your comment ! I didn't realise you could specify the full path in Nautilus as I use Kubuntu, so thanks for pointing that out! If anyone notices any errors like this, please feel free to point these out - I don't want to be giving out the wrong information!

    I also like Krusader, but for me Konqueror is the best file manager - I find it especially good for creating web pages as you can have the directory open in one tab and the page in another. The fact that there are so many different file managers you can use in Linux is yet another of the things that make it so great.

    ReplyDelete