-->
Previous Table of Contents Next


Files

The ls command is used to list the files in the current or a given directory. In some ways, it’s an oddity in the Linux world, as it’s not used directly on a file, which is the method Linux uses for organizing information. As you browse through the rest of this book, you’ll see that the vast majority of commands are used in conjunction with files.

This isn’t surprising when you stop to consider that everything in the Linux operating system is a file. You saw the ls command used to list files in a directory, and the reason that command is so handy is that everything in Linux is a file. Commands are actually files that are invoked as programs. Devices attached to your PC are actually represented in the Linux operating system by files (usually beginning with dev). When you print a file, you’re actually sending a file to a file representing the printer.

At a basic level, a file is nothing more than an organized area of a storage device (like a hard disk or a floppy drive), made up of bits. Bits are nothing more than digital players in an electronic format, representing either 0 or 1. The Linux operating system takes these bits and formats them in a way that’s recognizable to both you and the operating system. Without this organization, the contents of a hard drive would just be random zeroes and ones. This organizational scheme is called the filesystem.

That’s why the main function of the Linux operating system is to keep track of and manipulate these files. The importance of the ls command can’t be overstated, since it lets you know which files are in a portion of the filesystem at a given time. That’s why the most frequently used commands in Linux relate to manipulating files on basic levels, such as elvis for editing files, del for deleting files, and mv for moving files.

There are four types of files:

  Device files
  Directories
  Links
  Ordinary files

Each is explained, in order of its importance in the Linux operating system:

  Ordinary files are the rank and file of Linux files, usually containing data that’s acted upon by other programs and the operating system itself. An ordinary file can be an ASCII text file, a data file for a program (such as a formatted file for a page-layout program or a database file for a database manager), a command file (which contains further instructions for a program but is stored in ASCII text, such as a Perl or Tcl script), or an executable program file.
  Directories are files that represent information about other files. Files in the Linux operating system are stored hierarchically, with files stored within collections of other files. Directories will be explained later in this chapter.
  Device files represent the devices attached to your PC. These devices are stored in the /dev directory; for instance, a tape drive is represented by /dev/st0.
  Links are multiple names in the filesystem that represent the same file. Links aren’t that big a deal with Linux, unless you’re working on a network. Links are a remnant of the old UNIX days, when hard-disk space was so tight users would share one file, but because of the needs of the network, different names were given to the file.

Directories

As you saw earlier, directories are merely files that are used to store other files. Directories are an absolute must for an operating system like Linux. In Linux, every command is a file, every device is a file, and every program is at least one file (but usually many more). Add up all of these files, and you’ll end up with a mess of a filesystem, with thousands of individual files. To make matters worse, Linux is designed to be on a network, which means that every user has access to thousands of other files across the network and possibly on a file server. There would be no workable way to keep track of these files unless they could be stored in some sort of hierarchy. That’s where directories come in.

The directory hierarchy in Linux, which you can visualize as a pyramid, is actually pretty simple. There’s a root directory, which is at the top of the pyramid, and it’s represented by a slash (/). Every directory is a subdirectory of the root directory. In addition, there are subdirectories within subdirectories.

As a user, you are “in” a directory at all times. This is called the current directory. Your command prompt usually lists the name of the current directory (beginning with a slash, which indicates that the directory hierarchy begins with a root directory).

A standard Linux installation, such as Slackware Linux, has a fairly predictable set of directories. When your current directory is the root directory, Linux features a set of subdirectories like those shown in Figure 1.5.


Figure 1.5  The root directory in a typical Slackware Linux installation.

Some of these directories are found in almost all Linux and UNIX installations, such as etc, sbin, usr, and var. Other directories are unique to Linux, such as boot, cdrom, mnt, proc, and shlib. Still others are devoted to users, such as root and users. If you installed Linux on your own, you probably have at least one home directory (root, used when you’re logged in as the root user) and probably two (like a named directory under users).

Linux features a number of commands for creating your own directories, which are covered throughout the course of this book.


Previous Table of Contents Next