Concepts:This chapter begins by telling us that a file is the basic structure for data storage. In fact, it is the basic structure for data and device use, as well. The text agrees that UNIX and Linux like to see everything they encounter as a file, including hardware components. For the moment, we will consider the data structures you typically call files, and will consider the implications of treating devices as files a bit later. We can think of a file system in three ways that may be useful.
The UNIX file system is meant to operate as a virtual storage system. It presents a hierarchical concept of file storage to users, regardless of whether there is a graphic user interface. The text tells us that the original UNIX file system is called ufs (UNIX people love acronyms), and its extended version is called ext or ext fs. (Sometimes the short name is not an acronym.) We are told that a newer version of ext has added a concept called an extent, which is also used in some database programs. This makes sense if we think of a file system as also being a database about its component files and folders. (Folders are also called directories.) An extent, in this sense, is a contiguous group of data blocks allocated for a file when we store it. It need not be just the space needed to store the initial file. It will be more data blocks as well, in anticipation of the file growing in size. Why does it matter that the extent is contiguous blocks of storage space? A file that is stored in blocks that are physically next to each other can be accessed and manipulated faster than a file that is stored in discontiguous blocks. This is an advantage when dealing with large files. There are tables of information about file systems supported by UNIX on pages 56 through 58 in the text. You should browse through this material to learn about file systems you may never have known existed.
In the image on the right, a common Linux file structure is shown on the left side of the picture, and a common Windows file structure is shown on the right. In both cases there are icons for devices and for folders, and if we opened a folder we would see icons for files as well.. If you click the image, you will open a browser window on a short article which introduces some of the concepts of this chapter. The author of that article points out that the beginning of UNIX and Linux file systems is always called the root, and is represented by the slash, also called forward slash character: /. The slash is also used as a marker between directory names in a path to a file. Note that UNIX/Linux systems use the slash for this purpose, but Windows systems use the backslash: \. Paths in URLs follow UNIX notation perhaps because most servers on the Internet were running UNIX when the Internet was created. The text reminds us that folders are also called directories,
which you will need to know when creating, removing, or otherwise managing
them from a UNIX or Linux command line. Directories can, and often do,
contain other directories. These directories are in a parent/child
relationship, and the child can be called a subdirectory
with respect to its parent. We will talk more about folders and files
in a bit, but the text covers two other concepts first. Before you can add a file system to a hard drive, you have to create a partition on that drive to hold the file system. A partition may be an entire hard drive or only a portion of it, which allows you to create several partitions on a hard drive. Each of them may contain different file systems if that is what you need, or just different parts of the same file system. When making partitions on a disk with UNIX or Linux, they are numbered and the first one is numbered 1. The text's discussion is about some older technologies, IDE and SCSI. If you have a system that still uses them, an IDE drive might have partitions called hdax, where x is some number, and where a indicates that this is primary (boot) device. A device with SCSI disks might have partitions called sdax. Using the table below as a guide, you would choose one element from each column to form the name of a partition. To avoid confusion in naming partitions, use of automatic naming
is recommended.
You will not have to partition your virtual machine in our lab, but if you install Linux on an actual hard drive, you will need to know some of the material on pages 60 through 62. You may also want to read this article on the How-To Geek website, that has slightly different recommendations.
The second topic covered with partitions is inodes,
which is short for information nodes,
according to our text. That may be so, but I think the quote
on Wikipedia attributed to Dennis Ritchie (one of the creators of
UNIX) is probably also true: it may have meant index
node when it was created. An inode is a data structure that holds
information about and points to a file or a directory. UNIX and Linux
use inodes the same way that DOS and Windows use File Allocation Table
information to find files and note their size. Let's go back to the idea of the file structure, as the text does on page 63. The text is rather pedantic about the idea of mounting the file system. This is something that takes place automatically when the computer starts. As a user or administrator, you would only need to worry about mounting new devices to the file system when they are added to your computer. Let's assume that the file system exists and starts (as it must) at the root, as shown in the image above. The text discusses the first three folders in that image on page 64, and the discussion continues with several others through page 70.
The text explains the use of the mount command on the next three pages. It is not as clear as it might be. The mount command potentially has four parts, so I will try to explain it a little differently: mount [if the device has a file system on it, -t name-of-the-file-system] pathname-of-the-driver-for-the-device pathname-of-the-mount-point-you-are-creating-for-the-device The command is not optional,
but the name of the file system
is optional if the device has no file system on it. The paths to the driver
and to the mount point are not
optional. To remove the device from the system, use the unmount command, which only requires the path to its mount point as an argument. Having shown us a command that requires us to use pathnames,
the text pauses to explain what a pathname is.
On pages 73 and 74, the text explains how to change a system prompt to show more, less, or different information than it currently shows. There is a system variable called PS1 that holds a series of codes that are used to create the system prompt. This information about changing the prompt is not used on a daily basis by anyone, so you should be aware that it exists and be able to look up the codes that might be used to change the system prompt as desired. The text explains that the pwd
command is useful when you want to verify which directory the system is
thinking about presently. The text says that the command stands for print
working directory. I have also heard it called present
working directory. Both interpretations are correct. "print" means
to show it to us on the default output device (the screen), while "present"
(emphasis on the first syllable) reminds us that the system's attention
may be changed from one directory to another, and it may not be thinking
about the directory that we intend it to be thinking about. The text seems to be making a habit of telling us about something, then deciding that there is something else we should have been told first to understand its explanation. That being the case, it proceeds to tell us about a command to move the system's attention from the current working directory to some other directory. The command is cd, which stands for change directory. The cd command must be given one argument, the path to a specific directory, but that path can be given in one of two forms.
The contents of a folder can be shown with the ls
command, which stands for list.
This short command has several options shown on page 77. One of
the more useful ones is ls -l,
which means list in long
form, showing details about files and folders. Note the example on page 78, ls -l /, which means to list the content of the root directory in long form. This listing includes more information that the chapter has not explained yet, so hold on a bit for more details. For the moment, note that the listing shows a d in the first column for items that are directories, and a dash for items that are files. The text continues with some variations on using the ls command with
wildcard characters. The first example, on page 79, is the command ls *.txt.
Directories can be created and deleted with the
commands mkdir (make directory) and rmdir (remove directory).
Those of you who know the DOS commands for these actions will be tempted
to type md and rd, but those abbreviations do not always exist in UNIX
or Linux, so be content to type the entire five characters, followed by
the name of the directory, or the path to it. Note the warning about rmdir on page 81:When removing a directory, you should first make sure that it contains no files. Most versions of UNIX/Linux require that a directory be empty before removing it. Oh wait, the text has not told us how to delete a file yet. The command to remove a file takes one argument: rm filename (I guess someone didn't like the word "delete".) The command to copy a file takes two arguments: cp sourcefile destinationfile The text continues with a section about file system security. Linux/UNIX files (and directories) have permissions assigned to them. There are three basic permissions:
Linux/UNIX also divides the world into three categories, with regard to files. First, you should know that users on a Linux/UNIX system are classified as belonging to groups. These groups are artificial, and are set up by the system administrator. A user on the system must fall into one of three categories with respect to any particular file:
Think of permissions as being in three groups of three when seen on a list of files. Use the ls command with the modifier -al (In DOS we use forward slashes to show how to do a command. In Linux/UNIX we often use hyphens.) The command might look like: ls -al It means you want the long form listing of all files in the current directory. On the left side of the listing are the permissions. Directories
have a d first, file permission lists start with a hyphen
(They love that hyphen in Linux/UNIX. Just wait...) -rwxr-xr-- If we ignore the leading hyphen, this is three sets of three letters or hyphens.
There are several ways to set or change the permissions assigned to a file. Only the owner, a system administrator, a superuser, or a semi-talented hacker can do so. I usually use the chmod command with the octal number system described on page 85 of your text. You summarize the permissions down to three digits. Each digit represents the rights you grant one category above. Use this chart to decide what number to give each kind of person:
Issue the command like this: chmod 751 filename This sets the owner's permissions to full (7), the group's permissions to read and execute (5), and common people's rights to execute only (1). You might want to do this to protect shell scripts you write. That is sufficient for this chapter. Let's think about doing some exercises/projects.
|