-->
Previous | Table of Contents | Next |
The ls command is used to list the files in the current or a given directory. In some ways, its an oddity in the Linux world, as its not used directly on a file, which is the method Linux uses for organizing information. As you browse through the rest of this book, youll see that the vast majority of commands are used in conjunction with files.
This isnt 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, youre 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 thats 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.
Thats why the main function of the Linux operating system is to keep track of and manipulate these files. The importance of the ls command cant be overstated, since it lets you know which files are in a portion of the filesystem at a given time. Thats 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:
Each is explained, in order of its importance in the Linux operating system:
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 youll 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. Thats where directories come in.
The directory hierarchy in Linux, which you can visualize as a pyramid, is actually pretty simple. Theres a root directory, which is at the top of the pyramid, and its 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 youre 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 |