The Filesystem

For users migrating from a non-UNIX “based operating system (such as any Microsoft Windows OS), Linux s organization of files, directories, disk drivers, and other devices takes a little getting used to. Fedora, being a flavor of UNIX, organizes files the UNIX way ”using one grand hierarchy of directories . This section looks at the filesystem hierarchy and how to use the filesystem in your work. (The filesystem is covered in further detail in Chapter 7.)

The Filesystem Hierarchy

In the Linux operating system, every file, directory, and device is one part of a grand hierarchy. The topmost member of this hierarchy is the root directory , and it is denoted by the symbol / . A subdirectory of a given directory is denoted by the concatenation of the names of the parent directory and the child directory. For example:

  • There is a subdirectory called usr under the root directory, and we denote the full path to that subdirectory by the expression /usr .

  • A subdirectory of the usr directory named local can be denoted by the expression /usr/local .

This simple hierarchy of directories can be represented by the tree diagram shown in Figure 2-19.

Figure 2-19

Files within a directory are named much like subdirectories. In fact, behind the scenes a directory is just a special kind of file that contains the names of the files inside it and their respective locations on the disk.


Note that the directory separator character in Fedora is / , whereas in Windows it is \ .

Listing the Contents of a Directory

You can find out the contents of a directory by using the ls command. Figure 2-20 shows the output when invoking the ls command with the root directory (/) as its argument.

click to expand
Figure 2-20

The ls command takes an argument, which you can use to specify the file or directory to be displayed. If you specify a directory (as we did in the preceding screenshot), the ls command displays the files contained in that directory.


For a detailed description of the different ways in which you can customize the output of the ls command, take a look at the program manual by typing man ls at the command line.


The Fedora filesystem consists of thousands of directories and files arranged in the hierarchy previously described. Within this hierarchy, all the various programs and data files on the system are carefully organized into directories. The directories have generally been organized with the purpose of keeping related programs and files together. For example, the directory /bin contains the essential binary (or executable) programs available to all users, whereas the directory /sbin contains the binary programs essential to the super user (or root user ”the user who has complete administrative control of the system).


Of late, Red Hat and all major Linux distributions are trying to conform to the Filesystem Hierarchy Standard (FHS). This standard tries to bring a uniform file organization to the Linux world (which, until some years back, was plagued by different file organizations in the various distributions). You can learn more about FHS at .

The current specification, available at /, explains the various standard directories to expect in a Linux system and the type of files that they are supposed to contain. That said, Red Hat still has some distribution-specific directories that you won t find in other Linux distributions.

You can see some of the regular directories in the system in the directory tree shown in Figure 2-21.

click to expand
Figure 2-21

The Top-Level Directories

A moment ago, we used the ls command to list the contents of the root ( / ) directory, and we found 17 subdirectories. Each of these top-level directories has a very specific purpose, and you will encounter some of them very frequently. Let s take a look at some of these directories in the following table, and find out what they re for.




Contains programs available to all users.


Contains programs meant for use by system administrators.


Contains the log files made by various applications. The log files are invaluable in keeping track of applications activities and errors.


Contains all the personal directories of the users of the system.


Contains the files needed by the operating system to load itself into memory.


Contains the system configuration files used by various applications.


Contains the mount points for any removable devices in the system (such as CD-ROMs, floppy disks, and network drives ).


Contains the system state information. The information in the files of this directory is maintained directly by the operating system kernel.

Invoking a Program by Using Its Path

When you launch a terminal, the terminal in turn executes a command interpreter program called the shell . In fact, the command prompt that you see in the terminal is generated by this shell program ”the shell outputs this command prompt, and then waits for you to type in a command. When you launch a program from the prompt, the shell searches for it within the filesystem and then executes it.

You can execute programs by typing out their full path name at the terminal prompt, like this:

   $ /bin/ls   

Alternatively, you can simply use the program s name, like this:

   $ ls   

The second of these two commands does not specify the exact location of the ls program, so the shell searches for the program among a specific set of locations. These locations are specified by a special environment variable, known as the search path . An environment variable consists of a name and a value, and is maintained by the shell for use by programs executed with it. The name of the search path environment variable is $PATH , and you can find out its value by executing the following command:

   $ echo $PATH     /usr/local/bin:/usr/bin:/bin:home/arodef/bin   

As you can see, the value of $PATH consists of a number of directories, separated by : characters . If you launch a program by typing only its filename (rather than its full path name), the shell tries to find the program among the directories named in your path.

The value of your $PATH variable depends on what account you re using. By default, Linux discourages normal users from executing certain programs, such as the various administrative programs located in the directories /sbin and /usr/sbin that are intended for execution only by the super user. Linux does this by omitting these directories from any normal user s $PATH (as in the preceding example); users cannot invoke these programs without specifying the full path name.


Even if you do try to invoke an administrative program from a non-root account, you will still be challenged to authenticate yourself as a root user before the program will run. This has the added effect of reminding you that you re accessing an administrative program, and to take the appropriate care when doing so.

Finding a Program s Location

The which command allows you to find the location of programs contained within any of the directories listed in the $PATH variable. The following example uses which to find the location of the vim text editor:

   $ which vim     /usr/bin/vim   

The whereis command is also useful for locating programs. This command allows you to find the location of programs that are not contained in directories listed in $PATH . In the following example, you can see how which and whereis behave differently:

   $ which ifconfig   /usr/sbin/which: no ifconfig in /usr/local/bin:/usr/bin:/bin:home/arodef/bin   $ whereis ifconfig   ifconfig: /sbin/ifconfig /usr/share/man/man8/ifconfig.8.gz 

Here, which is unable to locate the ifconfig program because ifconfig is not located within any of the locations specified by the $PATH . However, whereis locates two files by the name of ifconfig : one ( /sbin/ifconfig ) is the program we re looking for, and the other is the file that contains the pages of the manual that cover ifconfig .

If a program is not within the scope of your PATH environment variable and you do not know where it is located on the system, you can also use the locate command to find the executable file. The caveat is that using locate as a general-purpose file search program can generate lots of information, and the user may have to sift through it to get to the file of interest. For example, if you used locate to find the location of the date command, it would additionally display the man and info pages for date . The details on using locate are explained in a subsequent section in this chapter.

Navigating the Filesystem

This section helps you navigate the filesystem and all the files in your computer. The filesystem can be navigated using either a GUI file explorer (such as Nautilus) or the terminal.

Navigating Using the GUI

To start the GUI file explorer, you have to execute the Nautilus file manager. A quick way to start Nautilus is to select it from the menu, by choosing Main Menu>Home Folder. This opens up the Nautilus file manager, which (as you ve already seen) resembles Microsoft s Windows Explorer. When you open the Nautilus file manager in this way, the directory shown in the location bar is your home directory, as demonstrated in Figure 2-22.

click to expand
Figure 2-22

A user s home directory is the location in the computer where that user can store his or her personal data. Many applications store their user-specific configuration and customization data in the home directory. The user s home directory is by default named after the user login ID and is located under the directory /home . For example, in this case the figure shows the user account has the login ID arodef; the home directory of this account is named arodef and placed under the directory /home . Thus, the complete path to my home directory is /home/arodef .

Once it s open, you can type any location into the location bar, and Nautilus displays the contents at that location. Alternatively, you can click the button marked Up to make Nautilus display the contents of the parent directory instead. In this way, you can navigate all the way up to the root directory ( / ), where you will find all the computer s top-level directories. You can then double-click the directories here to navigate inside them.

Overall, the navigation of the filesystem using the file manager is very intuitive, and if you have any experience with a GUI-based operating system such as Windows, you ll find yourself right at home with Nautilus.

Navigating Using the Terminal Emulator

Opening up a terminal emulator window places you at the shell prompt, and in your home directory. As already noted, the shell is the program that interprets each of the commands that you type at the terminal.

The directory that you are located in at any particular time is called the current directory (or present working directory ). When you first open up the terminal, your current directory is set to be your home directory. At any time, you can find out which directory that is by executing the command pwd :

   $ pwd   /home/arodef 

This example shows the pwd program being used to confirm that the current directory just after opening the terminal application is the user s home directory.


Please note that the filenames are case sensitive, unlike in Microsoft operating systems.

Displaying the Contents of a Directory

To display the contents of a given directory, you can use the ls program that was introduced earlier in the chapter. If the ls program is executed without any arguments, it displays the files in the present working directory.

If you try this in your home directory just after installation (before you ve created any new files in your home directory), the ls program gives no output (to reflect the lack of content in the directory). However, you should note that the ls program s default behavior is to not display the hidden files in a directory. Hidden files are generally used to store user-specific configuration data, and you can usually spot a hidden file because its name begins with the . (dot) character.

To display these files you must use the -a parameter with the ls command. The following example shows how the -a parameter affects the output of the ls command:

   $ ls     $ ls -a   .   ..   .bash_logout   .bash_profile   .bashrc   .emacs   .gtkrc   .xauthkIUlWu 

The lack of output from the first command suggests that the directory is empty. However, the output from the second command reveals the existence of a number of hidden files.

Changing the Current Directory

To change the present working directory to a different directory, you use the cd command. Executing this command without any parameters changes the working directory to be the user s home directory. Adding a directory name as the parameter causes the working directory to be the one specified. The following terminal session provides a good example:

   $ cd /usr/bin     $ pwd   /usr/bin $ cd   $ pwd   /home/arodef 

Here, the first cd command changes the current directory to /usr/bin (as confirmed by the subsequent pwd command). The second cd command changes the current directory to be this user s home directory (which happens to be /home/arodef ).

Searching for Files

Two different CLI programs enable you to search for files ” locate and find :

  • The locate program works by building a daily database of files and their respective locations. When a search is conducted , it simply looks up this database and reports the file locations. (However, this database is updated once a day and, therefore, may not reflect the actual contents of the filesystem if changes have happened in the last 24 hours.)

  • The find program, by contrast, doesn t use any database and actually looks inside directories and their subdirectories for files matching the given criterion.

The find program is more powerful because of the wealth of search criteria that it allows in searches. Both of these commands are used to find a file named in the following example:

   $ locate   /usr/share/doc/pam-0.75/ps/   $ find /usr/share/doc -name   /usr/share/doc/pam-0.75/ps/ 

The find and locate commands are explained in more detail in Chapter 7.

Fedora has a separate GUI program for finding files. This program can be executed by selecting the Main Menu>Search for Files option. This opens up the dialog box shown in Figure 2-23.

click to expand
Figure 2-23

In this dialog box you can specify the name of the file that you want to search for and the path in which the search should be performed. By clicking Find, the Search Tool performs a file search based on these criteria and returns the name and location of any files found in the directory mentioned in this box and in any of its subdirectories. For example, the preceding figure shows an attempt to search for a file named report.txt in any directory under /home/arodef .

The Search Tool also offers more advanced options that allow you to specify more fine- tuned parameters for the search. This mode is selected by clicking the Additional Options caption. You select the options you want from the drop-down list box (shown in Figure 2-24), add them to the list, and then specify the parameter of the restriction.

click to expand
Figure 2-24

The preceding screenshot shows that one restriction has already been added, stating that we want the search to return only files exceeding 10Kb in size .

Adding Devices to the Filesystem

In Linux, almost every device is treated as a file. This concept might be a bit unusual to you if you re more familiar with other non-UNIX operating systems such as the Windows family, but you ll quickly get used to it.

The idea behind this is to provide a uniform interface to all resources ”whether that resource is a hard disk, a serial device, a floppy disk, the sound card, or even the TV tuner. The notable exceptions in this concept are the network devices, which are handled differently by the operating system.

Mounting a Device

For users coming from a Windows background, there are some notable differences here. In Linux, the different hard disks and their partitions are not considered different drives. Instead, when you need to use such a device, it is mounted to a directory within the filesystem hierarchy (which is called its mount point ). Mounting a disk drive causes its own filesystem to appear as a child of the directory on which the device is mounted. Then, you can access the disk drive s content by navigating the directory hierarchy, just like any other file in the filesystem.

For example, suppose you have a floppy disk that contains a single directory, /doc , and that this directory contains a single file called readme.txt . You can make the contents of this floppy disk accessible by mounting the floppy disk (say, to the computer directory /mnt/floppy ). Then, the file readme.txt will be accessible using the path /mnt/floppy/doc/readme.txt , as shown in Figure 2-25.

click to expand
Figure 2-25

Thus, when the floppy is mounted, it appears to be joined seamlessly to the filesystem, even though it is an entirely different type of media than the hard disk on which the main filesystem is situated. By convention, you create mount points in the /mnt directory ”for example, you might mount a floppy disk onto /mnt/floppy or a CD-ROM onto /mnt/ cdrom .

Representation of Devices on the System

Every device on the system is represented by a file in the /dev directory. For example:

  • The first floppy drive in the computer is represented by the device special file, /dev/fd0 .

  • The first master IDE hard disk or CD-ROM is represented by the file /dev/hda .

  • The first audio DSP device of the computer is represented by the file /dev/dsp .

  • The first video capture device is represented by the file /dev/video .

  • Similarly, the first serial port of the computer is /dev/ttyS0 .

Only devices that can contain a recognized filesystem are mountable. For example, floppy, CD-ROM, IDE, and SCSI hard disks generally contain filesystems to store their data, and can be mounted onto the computer s filesystem.

Mounting a Device Automatically

The Fedora desktop has an application called magicdev , which detects media in the disk drives and mounts them automatically. Whenever you insert a data CD into the CD-ROM drive, magicdev does the following:

  • Detects it and mounts it on the directory /mnt/cdrom

  • Opens a GUI filesystem explorer (called Nautilus), with the contents of this directory displayed in it

  • Creates a desktop shortcut button for quick access to the contents of the CD

If you were to insert a music CD into the CD-ROM drive, magicdev would automatically launch the CD player and play the first track on the CD, as shown in Figure 2-26.

click to expand
Figure 2-26
Ejecting a Mounted CD

Once the CD-ROM is mounted, the CD-ROM driver locks it into the drive. You won t be able to eject the disc by pressing the Eject button on the CD-ROM drive. To eject a mounted CD, right-click with your mouse on the CD s desktop shortcut and click the Eject option in the resulting menu, as shown in Figure 2-27. This unmounts the CD from the mount point and ejects the disk.

Figure 2-27

You can also eject a CD by running the eject command from a terminal window. The eject command with no options ejects the CD from the CD-ROM driver.

Mounting and Unmounting from the Command Line

You can also perform the tasks of mounting and unmounting from the command line. To mount a CD-ROM onto the filesystem, you can use the mount program. The mount program needs to be told the device that has to be mounted, the filesystem that is present on it, and the mount point (the point in the existing filesystem where the device needs to be mounted). For example, the following command takes the CD contained in the CD-ROM drive /dev/cdrom , and mounts it at the mount point /mnt/cdrom :

   $ mount t iso9660 /dev/cdrom /mnt/cdrom   

Some of the parameters for mounting a CD in a Fedora desktop are preconfigured and stored in the system configuration file /etc/fstab . Therefore, you will need to execute only the following command to mount the CD-ROM on the mount point /mnt/cdrom :

   # mount /mnt/cdrom   

To mount the CD-ROM on a mount point other than /mnt/cdrom , you can no longer rely on the preconfigured information; you must provide all the information to the mount program. For example, to mount the CD-ROM on the mount point /mnt/cdrom1 , you must execute the following command:

   $ mount t iso9660 /dev/cdrom /mnt/cdrom1   

This instructs the mount program to mount the CD-ROM device /dev/cdrom onto the mount point /mnt/cdrom1 . It also specifies the filesystem as iso9660 , which is present on most standard CD-ROM media.


You can find all the parameters that can be passed to the mount program in the corresponding manual page by executing the command man mount at the terminal.

To unmount devices from the filesystem, you execute the umount program. The umount program takes only one parameter ”the mount point of the device. For example, the following command unmounts the CD-ROM disc from its mount point:

   $ umount /mnt/cdrom   

For unmounting a device from the filesystem, it is absolutely necessary that no application is currently using the device filesystem data. If the device is being used at the time of the unmount process, the process will be unable to unmount the device you specified.

 $ eject 

Finally, the eject command ejects the CD from the CD-ROM drive.

Beginning Fedora 2
Beginning Fedora 2
ISBN: 0764569961
EAN: 2147483647
Year: 2006
Pages: 170 © 2008-2017.
If you may any questions please contact us: