2.3. The Linux Filesystem2.3.1. Drives and PartitionsIf you're used to the drive-oriented layout of Windows, the Linux filesystem structure might be a bit confusing. There is no C: drive; in fact, there are no drives as such, only partitions. To muddy the waters a little more, the partitions' actual locations on the hard drive aren't identified clearly. The Linux filesystem is much more abstract than that. Let me give you an example. My workhorse machine at home, cortex, contains two physical hard drives. One is an old 40GB drive that contains the operating system and all the programs I use. The other is a new, 160GB behemoth I added later, which is partitioned into two sections. The first section contains my personal files: the photos I've taken with my digital camera, my MP3 collection, and few odds and ends. I leave the second section free for temporary files created by my programs. On a Windows system , these drives would most likely be seen by both the system and the user as C:, D: and E:. Windows would be installed at C:\WINDOWS\, Firefox would live in C:\Program Files\Mozilla Firefox\, my digital photos would reside in a directory called D:\Photos\, and so on. With Windows, the directory name is directly related to the partition, and therefore the hard disk, on which it's stored. This concept is illustrated in Figure 2-11. Figure 2-11. How C:, D: and E: relate to my physical hard disks.The Linux filesystem hides this unnecessary detail from you (until, of course, you want to see it). The operating system kernel is stored in a directory called /boot/, Firefox is in /usr/lib/firefox-1.0.4/, my photos and MP3s go into directories called /home/username/photos/ and /home/username/music/, and temporary files go into a directory called /tmp/. There are no obvious signs that these directories reside in different partitions or on different hard disks. The Linux filesystem assigns each partition a different mount point : a directory through which we access the partition. In our example, the D: in Windows is analogous to /home/tony/ on our Linux system, E: is similar to /tmp/, and C: would be /, the top of the filesystem hierarchy. This structure is depicted in Figure 2-12. Figure 2-12. The same partitions viewed in Linux.There's no doubt that it's confusing when you first make the transition from the physical disk-oriented view of Windows to the hierarchical filesystem of Linux. In time, however, you get over the shock and start to see the sense in viewing the system holistically, rather than as separate compartments. 2.3.2. The ext3 FilesystemLinux is deservedly renowned for its ability to work with many different filesystems. A modern Linux distribution will read, write, and keep track of files in nearly all the Microsoft filesystemsfrom the original FAT through to NTFSas well as filesystems used by Mac OS X, OS/2, and all sorts of esoteric operating systems. For Linux, it's a simple matter of loading the appropriate kernel module and mounting a partition. This makes it easy to handle files written on other systems on your Linux machine. In this section, we'll look at the filesystem that's native to your Fedora Core server: ext3. The ext3 filesystem is an extension of the native Linux filesystem, ext2 , and is now the default filesystem for Fedora Core. ext3 extends ext2 with a journaling layer that facilitates quick system recovery, and ensures a high level of data integrity . The journal is constantly updated with notes of file actions that are pending, and those that have been completed. Journaling protects against data corruption with speed and ease. All pending and completed operations are logged to the journal. The system checks the journal when rebooting , and completes those operations that were pending at the time of a system failure or "dirty shutdown." This protects the consistency of the data that was buffered at the time the system went down. Recovery time is also decreased by the use of a journaling layer. Rather than checking each file, bit by bit, for consistency, the system merely completes any pending writes noted in the journal. This reduces what was once a 20- to 30-minute reboot operation to mere secondsan improvement that's especially critical in an enterprise environment. Note: Other Linux distributions utilize different filesystems. SuSE Linux, for example, uses the ReiserFS filesystem by default. Extensive benchmarking has shown that ReiserFS can more efficiently handle large numbers of small files than can ext3. However, we won't have time to look at these other filesystems. If you'd like more information on the other filesystem options available for your Linux system, you can find a detailed list, descriptions and installation instructions online at Linux Gazette. 2.3.3. A Quick Tour of the FilesystemThe Linux filesystem depicted in Figure 2-13 has a different structure than you're probably used to. Let's look at an outline of the filesystem structure, and explore its various functions and elements.
Tip: The concept of mount points may be a bit confusing, despite their existence in every operating system, including Windows. To avoid confusion, think of mount points as containers into which the contents of a device or filesystem will be emptied. For example, /media/cdrom is a mount point for the contents of the CD-ROM device. Emptying the contents of the device into the mount point makes the files accessible to the system and its users. In general, devices and filesystems must be mountedattached to a mount pointbefore they can be used. In a later chapter, we'll discuss a way by which we can mount these devices and filesystems automatically in Linux. Figure 2-13. The Linux filesystem displaying in the File Browser application.2.3.4.1. Navigating the FilesystemNavigating the filesystem begins on the desktop with Nautilus , GNOME's graphical representation of the filesystem. There are two icons sitting on the desktop that act as starting points to Nautilus: Computer and username's Home, as shown in Figure 2-14. Figure 2-14. The desktop filesystem icons.The Computer icon begins at the top level of the system, similar to My Computer in Windows; while the username's Home icon begins within the current user's home directory. Double-clicking the Computer icon presents us with a view similar to that shown in Figure 2-15. We see the removable media attached to the computer, as well as icons representing the root of the local filesystem and any other filesystems to which we have access over the network. Double-clicking on the Filesystem icon opens a new window displaying the root directory of the filesystem, as shown in Figure 2-16. Double-clicking any of these icons will open another window, providing a view of the contents of the chosen directory, just like Windows Explorer or Finder on a Mac. Figure 2-15. The Computer icon's top-level view.Figure 2-16. Viewing the Computer icon filesystem.Figure 2-17. The Home icon view.Double-clicking on the username's Home icon on the desktop will jump straight to the current user's home directory. To start with, the home directory will only contain one visible folder icon, Desktop, as depicted in Figure 2-17. 2.3.4. Handling Linux FilesLiterally everything in a Linux system is a file, including directories, links, and so on. Even the commands are files, ranging from the simple to the extremely complex. Because of the nature of the Linux system and its files, it's important to understand the processes of file handling and editing on your new system. In this section, we'll take a quick spin through the file permissions structure, get a grip on the system's ability to link from one file to another, and explore some of the more common text editing applications for Linux. Because everything in Linux is a file, it's very important that you understand how files are accessed and edited. These are skills you'll find yourself using nearly every day. 2.3.5.2. File PermissionsLinux utilizes one of the most granular file permissions systems of any computer operating system. As we've already seen, that granularity is due, in part, to the fact that everything in Linux is a file. Commands, configurations, device files: all are editable, depending upon who the editing user is, and how the permissions on the file have been set. Accordingly, it's important to understand the permissions structure and how it will affect both your and your users' interaction with system files. At their most basic, Linux permissions are broken into three sets of permissions. These are:
Each of these sets can grant any combination of the following, self-explanatory permissions:
What's especially interesting in the Linux permissions structure is how these three sets of three permissions interact. A particular user may belong to a group that can only read a particular file, but if that user also happens to be the file's owner, the owner permissions of the file might also grant the user access to write to the file's contents. Figure 2-18. Default permissions for a text file.As an example, let's look at the default permissions structure of a simple text file. Open the gedit application by choosing Applications > Accessories > Text Editor from the menu. Enter some text into gedit, then save the file in your home directory. Locate the file in Nautilus, right-click on the file, and select Properties. Click the Permissions tab to see the permissions that have been given to the file as shown in Figure 2-18. Let's take an in-depth look at this dialog.
2.3.5. Symlinks, or Linking Files: More AbstractionMost people who have ever worked with Windows understand the concept of shortcuts. A shortcut is really a pointer from one location to a file in another area of the system. In fact, some users understand and become so obsessed with shortcuts in Windows that their desktops are eventually covered with them! The ability to launch a file from somewhere other than its real location clearly has value for computer users. And Linux offers such capabilities, too. As an administrator, you'll find Linux's shortcuts nearly as exciting as those in Windows. A shortcut in Windows and a symbolic link in Linux really amount to the same thing: they're abstractionsmere representationsof the original file. Creating a shortcut in Windows doesn't actually move the executable file to the desktop. Similarly, in Linux, we can write for a file an abstraction that appears to be the file itself. The file doesn't really exist in the new location, it just operates as if it does. One important difference between the way Windows and Linux create shortcuts is that a Linux symbolic link (normally called a symlink) can be treated exactly as if it were the file for most purposes. For example, if you open a symlink in your editor, and make changes to the file, the editor will edit the actual file to which the symlink points. If you try that under Windows, you're likely to get a surprise when the editor opens up the shortcut file for editing, rather than the file that to which the shortcut links! Symlinks are used frequently under Linux because they're a powerful abstraction that can make it seem as if a file is in multiple places at once. You can create a symbolic link in Nautilus by right-clicking on a file or folder, and selecting Make Link, as shown in Figure 2-19. This will create a symlink with "link to" at the start of the filename, as depicted in Figure 2-20. You can drag and drop this file anywhere, and rename it as you choose. Figure 2-19. Creating a symlink in Nautilus.Figure 2-20. A newly created symlink.2.3.6. Editing Text FilesA reasonable command of a Linux-compatible text editor will be crucial to the success of your day-to-day administration. As most of the configuration in a Linux system is done via text files, you'd be wise to find one that works for you. In fact, Linux is replete with text editors: editors without a GUI, editors with a GUI, editors intended primarily for programmers, editors targeted at HTML developersthere's no shortage of tools to make your administrative tasks easier. In this section, we'll take a look at some of the GUI-based text editors that are available to you. We'll look at some of the command line-based editors a little later. Fedora Core provides two robust GUI text editors in the default installation: gedit and Kate. gedit is the default text editor for the GNOME desktop environment, and Kate is the default for KDE , but both will work in either desktop environment. If you were a longtime Notepad or Wordpad user in Windows, you'll find that many of the same features are available in Linux's GUI text editors, plus much, much more. 2.3.7.3. geditgedit is GNOME's default text editor. Pictured in Figure 2-21, it offers a full range of features, including:
In addition to these standard features, the following plugins can be added to extend the gedit application:
Figure 2-21. The main gedit screen, ready to edit the Apache configuration file.Tip: You'll quickly realize that most GUI applications for Linux are written specifically for one desktop environment or another. The naming conventions for these applications remain fairly consistent, and reasonably obvious. Most applications written for the GNOME desktop environment will begin with the letter "G," while applications written specifically for the KDE desktop environment will begin with the letter "K." 2.3.7.4. KateThe KDE counterpart to gedit is Kate, the "KDE Advanced Text Editor," pictured in Figure 2-22. If it's not available in the Applications menu, you can start it by selecting Applications > Run Application… and entering kate. Note: The Kate text editor, originally a standalone application, is now included in the kdebase package. It's not available as a separate download. In order to use Kate, you'll need to have all the KDE libraries and base applications installed. To install additional applications, select Desktop > System Settings > Add/Remove Applications. Like gedit, Kate is a multi-view editor: it will allow you to open and edit multiple documents in the same window. As well as that single, very useful feature, Kate offers a full range of other capabilities that make it a very powerful text editor. Its features include:
Figure 2-22. The main Kate screen, in which the Apache configuration file is being edited.Ultimately , Kate is a bit more friendly, and offers greater flexibility for editing configuration files and writing shell scripts, than do some other editors. The syntax highlighting capabilities are unsurpassed, as Kate makes available a full range of programming languages and styles. Additionally, Kate provides such features as an open document listing (shown in Figure 2-23) and an integrated filesystem browser (Figure 2-24). Figure 2-23. Kate's Documents tab.While Linux does provide other GUI text editing options, gedit and Kate are two of the most powerful and user-friendly on offer. Either will suit your Linux text-editing purposes well. Figure 2-24. Kate's Filesystem Browser tab. |