Monday, February 23, 2009

Software as a Subversive Activity, Part 14: The Directory

Linux Monday: Directory for Beginners

One of the things that throws people when they're first looking at Linux is that they can't find their C:\ drive. Linux looks at files a little differently than Windows, but it's not too complicated and you shouldn't have to look too deep to find stuff.

You won't see drive letters in Linux. Everything is a directory within a single file system: your hard drive, your flash drive, your CD drive—all of it. Think of the file system as if it's My Computer, and you'll be pretty close.

You can look at your file system structure at the command prompt or with your distribution's file manager. Let's use the command line because that's the same across distributions (and easier to cut and paste).

Open the command line and type cd /

john@john-firebolt:~$ cd /

This navigates you to the root directory. Sometimes it's actually called root, but usually it's just the slash. The root directory holds as few files as possible. Let's peek with a ls command::

john@john-firebolt:/$ ls
bin dev initrd lib mnt root sys var
boot etc initrd.img lost+found opt sbin tmp vmlinuz
cdrom home initrd.img.old media proc srv usr vmlinuz.old

Only the listings in bold are files; the rest are directories. Linux keeps as few things as possible in the root directory.

Most of your stuff is going to be in the home directory. If you're moving from Windows, think of this as My Documents (or, more accurately, Documents and Settings\Users)There will be a subdirectory under home for each user.:

john@john-firebolt:/$ cd home
john@john-firebolt:/home$ ls
dumbledore ginny harry hermione john ron voldemort

The system's administrator or root user has more magical powers than all these wizards put together. Voldemort can't get to my stuff, unless he has my password. (Most hackers are unable to obtain the root password by use of Cruciatus, Imperius, or other Dark Arts, so it's not yet considered a major Linux security flaw.) But let's check in on him:

john@john-firebolt:/home$ cd Voldemort
bash: cd: Voldemort: No such file or directory

Everything in the file system is case sensitive. Voldemort is different than voldemort. Let's try that again.

john@john-firebolt:/home$ cd voldemort
john@john-firebolt:/home/voldemort$ ls
Desktop Examples Music Public Videos
Documents Firefox_wallpaper.png Pictures Templates

Only the wallpaper is a file (I gave Voldy a nice ugly picture of himself, but he can change that) .Ubuntu will set up several default subdirectories within your home folder: Music, Pictures, etc. Again, we're case sensitive here. I have Pictures and PICTURES directories. (Don't ask.) Ubuntu's file manager program, Nautilus, has some skills in organizing, but just as with My Documents in Windows, some of that is up to you. Voldemort likes order and has a less cluttered directory than Harry or Ron. Or me.

That's fine for the hard drive. But what about your portable gadgets?

Linux connects to external devices through a process called mounting. In the dark ages you had to do this manually at the command line, even for a floppy disk, but a modern distribution will do this for you automatically.

You can mount a device within any directory, though you don't generally need to think about it. Ubuntu uses the directory /media, and some distributions use the directory /mnt

john@john-firebolt:/home$ cd /
john@john-firebolt:/$ cd media
john@john-firebolt:/media$ ls
CAMERA cdrom cdrom0 Sansa View STORE N GO

You see my various devices show up as subdirectories within the /media directory.. The cdrom directories are included by default. Again, you can navigate all this through Nautilus or another file manager.

So you know where to find your “My Documents” and your drives and gadgets. The rest of the directory structure is fairly standard across Linux, with minor variation. Here's a wallpaper-friendly chart to help you learn through osmosis. If you're in an environment where you're forced into Windows, this is a nice little Stickin It To The Man wallpaper.

The Linux kernel files are in /boot, and /bin has contains the system binary files that load right after the kernel. /sbin is similar to /bin, except access is restricted to the administrator-level user (the "root" user, or someone using the temporary, password-protected root-level powers of the sudo command).

/lib has most of the important system files, sort of like Windows\system32. /usr has most of the application files, you can pretend it's C:\Program Files if you like. Note that in the Linux directory, the slashes go lower left to upper right, like when you're browsing the web. In the Windows directory tree, slashes are upper left to lower right. I can never remember which one is a slash and which is a backslash--hell, I'm doing well to remember left and right in any context other than the political.

/opt has some configuration files for applications. The only thing I have here is some config files for Open Office.

/lost+found is usually empty, but if you have a system crash the system will temporarily store recovered files here. My only system crashes since moving to Linux have been to to 1) power failures or 2) overheating (a problem that plauged by laptop in Windows, too. In Linux I'm able to contol my CPU speed and thus my temperature, more easily.

/etc contains configuration files specific to your system: your network card, graphics, etc. The rest are various sorts of Don't Muck With Them things, the distinctions of which are detailed well in this article.

If you have a CD in the drive, the files will show up BOTH in the /cdrom directory and in the /media/cdrom, which seems a little redundant and repetitive, but is harmless. And there I leave you for the week, one step closer to being a Linux wizard instead of a Microsoft Muggle.

1 comment:

Sausalitoscynic said...

This post is an excellent example of why Linux is still not ready for prime time, much as I regret it. "Command line"? OK, I remember them, but no one else does.