rha030 workbook01 student 6.1 2

50
Part Workbook 1. Quick Tour

Upload: mcoronado

Post on 01-Jan-2016

102 views

Category:

Documents


0 download

DESCRIPTION

sdasd

TRANSCRIPT

Page 1: Rha030 Workbook01 Student 6.1 2

Part Workbook 1. Quick Tour

Page 2: Rha030 Workbook01 Student 6.1 2

2

Table of Contents1. Logging In ................................................................................................................... 4

Discussion .............................................................................................................. 4Starting Linux Sessions ..................................................................................... 4Virtual Consoles .............................................................................................. 4The X Graphical Environment ............................................................................ 5Terminals in the Graphical environment ............................................................... 6Logging out from the graphical environment ......................................................... 8Using the who command to determine who's on the system. ..................................... 9Logging into a machine over the network ............................................................. 9

Examples .............................................................................................................. 10Example 1. Using virtual consoles ...................................................................... 10

Online Exercises .................................................................................................... 11Online Exercise 1. Using multiple virtual consoles ................................................. 11

Specification .......................................................................................... 11Deliverables ........................................................................................... 12

Questions .............................................................................................................. 122. The Kernel, Programs, and Processes ............................................................................... 14

Discussion ............................................................................................................. 14The Linux Kernel ........................................................................................... 14Programs ....................................................................................................... 15Processes ...................................................................................................... 15Shells ........................................................................................................... 16The ps command ............................................................................................ 16

Questions .............................................................................................................. 17The kernel, programs, and processes .................................................................. 17

3. Examining the Filesystem .............................................................................................. 19Discussion ............................................................................................................. 19

The Naming of Files and Directories .................................................................. 19Listing directory contents with ls ....................................................................... 19Viewing the contents of a file with cat ............................................................... 20Redirecting command output to files .................................................................. 20Permissions, and a user's home directory. ............................................................ 21

Examples .............................................................................................................. 21Example 1. Redirecting command output to a file. ................................................. 21

Online Exercises .................................................................................................... 22Online Exercise 1. The ls Command ................................................................... 22

Specification .......................................................................................... 22Deliverables ........................................................................................... 22Possible Solution .................................................................................... 22

Questions .............................................................................................................. 22Multiple Choice Questions. .............................................................................. 22

4. Running Commands ..................................................................................................... 24Discussion ............................................................................................................. 24

Command Line Grammar ................................................................................. 24Commands .................................................................................................... 24Command Line Switches ................................................................................. 25

Short Command Line Switches ................................................................. 25Multiple Short Command Line Switches ..................................................... 25Long Command Line Switches .................................................................. 26

Arguments ..................................................................................................... 26Getting Help: Usage ........................................................................................ 27

Page 3: Rha030 Workbook01 Student 6.1 2

Quick Tour

3

Examples .............................................................................................................. 27Example 1. Learning to Use the cat Command ...................................................... 27

Questions .............................................................................................................. 29Command Line Syntax .................................................................................... 29

5. Managing Terminals ..................................................................................................... 32Discussion ............................................................................................................. 32

Controlling Terminals ...................................................................................... 32Resetting Terminals ........................................................................................ 32Terminal control sequences .............................................................................. 32Identifying terminals ....................................................................................... 35Tab Completion ............................................................................................. 36

Examples .............................................................................................................. 37Example 1. Resetting the terminal after viewing a binary file. ................................... 37Example 2. Canceling a command ...................................................................... 37

Online Exercises .................................................................................................... 38Online Exercise 1. Suspending terminal output ...................................................... 38

Specification .......................................................................................... 38Deliverables ........................................................................................... 38Cleaning Up .......................................................................................... 38

Online Exercise 2. Sorting your socks. ................................................................ 38Specification .......................................................................................... 38Deliverables ........................................................................................... 39

Questions .............................................................................................................. 396. Getting Help ............................................................................................................... 42

Discussion ............................................................................................................. 42Getting Help .................................................................................................. 42Obtaining Usages with -h, -?, and --help ............................................................. 42Man Pages .................................................................................................... 42

The less Pager ....................................................................................... 43Man Chapters ........................................................................................ 43Keyword Searches, and the -a Switch. ........................................................ 43

Info Pages ..................................................................................................... 44The /usr/share/doc Directory ............................................................................. 44Red Hat Documentation Guides ........................................................................ 45The Linux Documentation Project ..................................................................... 45yelp: The Gnome Help Browser ........................................................................ 46

Questions .............................................................................................................. 48

Page 4: Rha030 Workbook01 Student 6.1 2

4

Chapter 1. Logging InKey Concepts

• In Linux, user sessions are started by "logging in" to the machine.

• To login, you must have already been provided a username and password.

• If a Linux machine is running an X server, users may login using the graphical interface.

• Users may login on any of six virtual consoles.

• The CTRL+ALT+F2 through CTRL+ALT+F6 key sequences switch between the six virtual consoles.

• The CTRL+ALT+F1 key sequence switches to the default X server.

• If a Linux machine supports it, users can login in over the network using a remote shell.

• The who command lists which users are currently logged in, and how they logged on.

Discussion

Starting Linux Sessions

The Unix operating system, which was originally developed in the early 1970s, predates the days ofpersonal computers. Originally, many users would simultaneously use Unix running on a mainframecomputer. Rather than each user having a personal computer, they would use what is (these days)commonly called a "dumb terminal" - really just a keyboard and text monitor, connected to the mainframecomputer with a serial line connection. In order to identify oneself to the Unix operating system, a userwould first have to "log on" by providing a userid and password.

Although Linux (and other versions of Unix) has grown to take advantage of affordable personalcomputers, it has not lost the core concepts of users, passwords, logging on, and text based terminals. Thislesson will describe various ways to start an interactive session with a Linux system.

Virtual Consoles

Red Hat Enterprise Linux provides six "virtual consoles" that are available to users physically at thecomputer. The virtual consoles act like "dumb terminals". The virtual consoles are accessed using theCTRL+ALT+F2 through CTRL+ALT+F6 key sequences, with one virtual console mapped to each ofthe first 6 function keys. (If you are in a graphical environment, you should know that CTRL+ALT+F1will return you to it before trying to switch to a virtual console.)

When starting a session on a Linux machine using a virtual console, the screen will look something likethe following:

Red Hat Enterprise Linux Server release 6.1 (Santiago)Kernel 2.6.32-131.0.15.el6.x86_64 on an x86_64

station login:

Page 5: Rha030 Workbook01 Student 6.1 2

Logging In

5

To login, a user types their username, with no spaces, and hits the RETURN key. Next, the user is promptedfor their password, which is not echoed to the screen as the user types it, again followed by RETURN.Once successfully logged in, the user is greeted with a shell prompt.

Red Hat Enterprise Linux Server release 6.1 (Santiago)Kernel 2.6.32-131.0.15.el6.x86_64 on an x86_64

station login: elvisPassword:[elvis@station elvis]$

The rest of this course is about what can be done from the shell prompt. For now, we are simply goingto learn how to end a session, by typing "exit", and hitting RETURN. The virtual console should returnto the original login screen.

Why would users want to use a virtual console instead of the graphical environment? First, the machinemight not have enough memory or hardware to support the graphical environment, and the virtual consolesmight be all that are available. Even on modern machines, however, the virtual consoles are often a muchquicker and more efficient interface for experienced users. Because they are implemented by the Linuxkernel directly, they are also useful in debugging systems where the graphics might not be working. Lastly,for network servers that usually spend their lives in locked closets, administrators often want to avoid thecomplexity that the graphical interface adds to the system.

The X Graphical Environment

When running on modern personal computers, Linux uses a low level program known as the "X server"to provide the graphics environment. As a user of the system, you don't interact with the X server directly,but it provides the canvas for all of the graphical programs that you run.

When the X server starts, usually as part of the system's startup sequence, it looks for the "first available"virtual console. If you are on a virtual console, and think that an X server is running on the machine, youcan usually switch to it using the CTRL+ALT+F1 key sequence.

If a system is configured to boot to the graphical environment, a user will be presented with the LoginManager, which looks like the following.

Page 6: Rha030 Workbook01 Student 6.1 2

Logging In

6

Figure 1.1. Red Hat Enterprise Linux Login Manager

A user logs on by clicking on their username then typing their password followed by RETURN. If theirusername is not listed, the user can click "other" then log on by typing their username, followed byRETURN, and their password, again followed by RETURN.

Terminals in the Graphical environment

The Applications menu in the graphical environment is found in the upper left-hand corner and servesas your gateway to a wide variety of graphical applications, including web browsers, text editors, imageeditors, games, and much more. While you are encouraged to explore these applications, we begin thiscourse by focusing on the fundamentals of operating within the Linux environment, such as managingfiles and processes. For now, the most important application in the graphical environment for you is theterminal.

In Red Hat Enterprise Linux, the most commonly used terminal application is called gnome-terminal. Anew gnome-terminal window can be opened by right-clicking on the desktop background, and choosingthe top menu item in the pop-up menu, "Open in Terminal". Alternately, you may select the Applications :System Tools : Terminal menu item.

Page 7: Rha030 Workbook01 Student 6.1 2

Logging In

7

Figure 1.2. Opening gnome-terminal

Experienced Linux users often prefer the versatility and power of the command line interface overgraphical applications. Akin to a virtual console, the terminal provides a shell command line interface.Because the user has already logged in to start the graphical session, he does not need to login again whenopening new terminal.

Page 8: Rha030 Workbook01 Student 6.1 2

Logging In

8

Figure 1.3. gnome-terminal

When finished, the gnome-terminal can be closed by typing the exit command (followed by RETURN),or left clicking in the "go away box" found in the upper right-hand corner of the terminal.

Logging out from the graphical environment

When finished with the graphical environment, a user logs out by selecting "Log Out ..." from the Systemmenu, which is the rightmost menu. Logging out closes all open windows, and returns the graphicsenvironment back to its original login screen, ready for the next user.

Page 9: Rha030 Workbook01 Student 6.1 2

Logging In

9

Figure 1.4. Logging out of the graphical environment

Using the who command to determine who's on thesystem.

Users can use the who command to determine who is on the system, and how they logged on. From anyterminal, users can type who and hit the RETURN key. They should see output similar to the following.

[elvis@station elvis]$ whoelvis tty2 May 5 15:07root tty3 May 3 07:50blondie tty1 May 5 08:48 (:0)blondie pts/0 May 5 09:03 (:0.0)

The first column lists the users who have logged on, and the last few columns the time that they loggedon. With a little experience, the second column tells where the user logged on. For the first two users,elvis, and root, tty2 and tty3 refers to virtual consoles number 2 and 3, respectively. The first entry forblondie on tty1 with the :0, refers to the X server itself running on the first virtual console, and pts/0refers to the first terminal opened within the X server. Without getting too bogged down in the details,we can see that elvis is logged on the second virtual console, root on the third, and blondie has logged inusing the graphical environment.

Logging into a machine over the networkUsing the ssh ("secure shell") utility, users can easily log in to remote machines, either in the same room,or halfway across the world. Assuming the remote machine is configured to allow remote logins, and theuser has an account on the machine, logging in to a remote machine can be as easy as logging in on a

Page 10: Rha030 Workbook01 Student 6.1 2

Logging In

10

virtual console. In the following example, elvis will login to a virtual console on the local machine, calledstation.redhat.com. He will then use ssh to login to the remote machine nimbus.example.com, potentiallyhalfway around the world.

Pay careful attention to the shell prompt in the following example. Because Linux users are often "hopping"from machine to machine using remote shells, the prompt has been designed to help the user keep straightwhat machine the shell is running on.

Red Hat Enterprise Linux Server release 6.1 (Santiago)Kernel 2.6.32-131.0.15.el6.x86_64 on an x86_64

station login: elvisPassword:Last login: Thu Apr 3 13:03:06 from hedwig[elvis@station elvis]$ whoelvis tty2 May 3 07:48[elvis@station elvis]$ ssh [email protected]@nimbus.example.com's password:Last login: Thu May 1 17:38:43 2003 from station.redhat.com[elvis@nimbus elvis]$ whoelvis pts/1 May 3 11:59 (station.redhat.com)

[elvis@nimbus elvis]$ exitConnection to nimbus.example.com closed.[elvis@station elvis]$ exit

Note that when elvis ran the who command on the remote machine, it reported the machine that he loggedin from, namely station.redhat.com.

There are ssh clients for operating systems other than Linux. For example, the Open Source PuTTY[http://www.chiark.greenend.org.uk/~sgtatham/putty/] application can be installed on almost any windowsmachine, and used to open a shell into a remote Linux server.

Examples

Using virtual consolesIn the following example, a user logs on the second virtual console as the user elvis, but then realizes hissystem is mis-configured. In order to fix the misconfiguration, he is going to switch to the third virtualconsole, and log in as the administrative user root and fix the problem. He will then exit, switch back tothe second virtual console, and be on his way.

Red Hat Enterprise Linux Server release 6.1 (Santiago)Kernel 2.6.32-131.0.15.el6.x86_64 on an x86_64

station login: elvisPassword:Last login: Mon May 5 15:07:16 on tty2[elvis@station elvis]$ cat /tmp/READMEcat: /tmp/README: Permission denied[elvis@station elvis]$ whoelvis tty2 May 5 15:54

At this point, elvis has tried to read the file /tmp/README, but found out the file's permissions did not lethim. Because the user knows the password to the root (administrator's) account on the machine, he can fixthe problem by switching to another virtual console (using the CTRL+ALT+F3 key sequence), loggingin as root, and changing the file's permissions.

Page 11: Rha030 Workbook01 Student 6.1 2

Logging In

11

Red Hat Enterprise Linux Server release 6.1 (Santiago)Kernel 2.6.32-131.0.15.el6.x86_64 on an x86_64

station login: rootPassword:Last login: Mon May 5 15:54:18 on tty6[root@station root]# who root tty3 May 5 15:55elvis tty2 May 5 15:54[root@station root]# chmod go+r /tmp/README[root@station root]# exit

Note that the output of the who command shows the user logged on as elvis on the second virtual console,and logged on as root on the third. The user now switches back to the second virtual console usingCTRL+ALT+F2, and picks up where he left off.

[elvis@station elvis]$ cat /tmp/README GNU GENERAL PUBLIC LICENSE Version 2, June 1991

Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.

Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software...

Online Exercises

Using multiple virtual consoles

Lab Exercise

Objective: Learn to manage multiple virtual consoles

Estimated Time: 10 mins.

Specification

Your machine should have been configured with multiple accounts, all with the same password. If yourusername is elvis, for example, you should also have accounts named elvis_a, elvis_b, andelvis_c, all with the same password.

For this exercise, you should log into virtual consoles 2-5, using each one of your accounts in order.

Virtual Console Username

2 username

3 username_a

4 username_b

5 username_c

Page 12: Rha030 Workbook01 Student 6.1 2

Logging In

12

If you have completed the exercise correctly, you should be able to run the who command from anyterminal, and see output similar to the following:

[elvis@staion elvis]$ whoelvis_a tty3 May 5 16:18elvis tty2 May 5 16:18elvis_b tty4 May 5 16:18elvis_c tty5 May 5 16:18

Deliverables

1.1. 4 active login sessions, one on each of the first 4 text only virtual consoles.

Questions1. Which of the following best describes why Linux is referred to as a multiuser operating system?

a. Multiple users can use the same machine simultaneously, using multiple network connectionsand dumb terminals.

b. Multiple users can use the same machine, but only one at a time.

c. Many people contributed to the development of the Linux operating system.

d. Linux is not referred to as a multiuser operating system.

2. Which of the following is not an advantage of using virtual consoles instead of a graphicalinterface?

a. Virtual consoles often respond more quickly than graphical environments.

b. Virtual consoles operate at the kernel level, and so can be used to debug the system whenhigher level components are mis-configured.

c. Virtual consoles are very intuitive, and help is available in an obvious manner.

d. Graphical environments add a lot of complexity to a system, and can make them harder tomaintain.

3. From the fourth virtual console, which key sequence(s) will take you to the second virtual console?

a. CTRL+ALT+2

b. CTRL+ALT+F2

c. CTRL+2 (using the numeric keypad)

d. None of the above.

4. From the X graphical environment, which key sequence(s) will take you to the second virtualconsole?

a. ALT+F2

b. CTRL+ALT+F2

c. Both a and b.

Page 13: Rha030 Workbook01 Student 6.1 2

Logging In

13

d. None of the above.

5. If a user has logged into the X graphical environment, but desires to use a terminal command lineinterface, how might she go about obtaining a terminal?

a. Using the CTRL+ALT+F3 key-sequence to switch to a virtual console.

b. Clicking the terminal icon that appears in the bottom panel.

c. Right click in the desktop, and choose "Open in Terminal" from the pop-up menu.

d. Both a and c

6. What does the who command report?

a. The users who have logged onto the machine since midnight.

b. The users who are currently logged onto the machine, and where they logged on from.

c. The users who are currently logged onto the machine, and how much time they have remainingbefore their session expires.

d. The command is used to lookup users from an Internet database of all users.

7. Which of the following is NOT required in order to open a remote shell using ssh?

a. The remote machine must be running the ssh service.

b. You must know the username and password of an account on the machine.

c. The local machine must be a Linux machine.

d. You must know the hostname or IP address of the remote machine.

Page 14: Rha030 Workbook01 Student 6.1 2

14

Chapter 2. The Kernel, Programs, andProcesses

Key Concepts

• The Linux kernel is an operating system, which provides an environment for the running of processes.

• Programs are executable (usually binary) files that reside in the filesystem.

• A process is an instance of a executing program.

• A shell is an interactive process that allows the user to specify other processes to run.

• Although Red Hat Enterprise Linux ships with several different versions of shells, the default shell isa program called bash.

• The ps command lists processes started from a single terminal. The ps aux command gives a detailedlisting of all processes currently running on a machine.

Discussion

The Linux Kernel

The Linux kernel is an operating system, just as Windows, MacOS, and OS/2 are operating systems. Theoperating system is an environment in which programs run, providing mechanisms for programs to interactwith the computer hardware. The kernel lets programs know when a keyboard key was struck, when themouse moved, or when a packet destined for the program arrived over the network. The kernel allowsprograms to access the harddrive, perhaps to read a configuration files or store data.

Just as it would be difficult to explain what a language is to people who have grown up only knowingabout one language, it is often difficult to explain what an operating system is to people who are new tocomputers, or who have only used one operating system. The operating system operates at such a lowlevel, that users don't interact with it directly, and often don't realize that the programs they are runningare using it.

Page 15: Rha030 Workbook01 Student 6.1 2

The Kernel, Programs, and Processes

15

Figure 2.1. The Kernel and Processes

ProgramsPrograms are files that are stored on a computer's harddrive. A program is a series of very basic instructions,that tell the operating system what to do and when to do it in a very detailed and specific manner. Thefollowing might be the instructions written down in the file /usr/bin/gcalctool, the GNOME calculatorprogram.

"While the user isn't doing anything, blink the cursor. When the user hits a key, if it's anumber, write it to the screen. If it's not a number, ignore it, unless it's the return key. Ifit's the return key, add the previous number to the total, and print the total."

Of course, the instructions are not written in English, or any other human readable language. Instead,a computer, at the lowest level, only knows how to perform a small number of tasks, say 256 of them.Imagine that each of these tasks were numbered, task number 0 through task number 255. Programs reallylook more like the following instructions:

"Do task 23. If the result is greater than 0, do task 45. Otherwise, do task number 82.Take the result, and store it into memory."

Because the tasks that a computer can do vary from one type of CPU to another, and because differentoperating systems can be thought of as numbering the tasks differently, programs that are compiled forone type of operating system will generally not run on other operating systems.

ProcessesWhen a user instructs the kernel to run a program, the kernel reads the instructions found in the programfile, and loads them into memory. It then begins performing the instructions. The copy of the programrunning in memory is called a process. Note that the same program can be loaded into memory and runmore than once, so that at any point the kernel might be running several processes which are instancesof the same program.

Linux, like most modern operating systems, is a multitasking operating system. This means that the kernelgives the appearance of running multiple processes simultaneously. In reality, the kernel is running a single

Page 16: Rha030 Workbook01 Student 6.1 2

The Kernel, Programs, and Processes

16

process for a brief amount of time, usually on the order of 50 milliseconds. It then swaps that process out,and swaps in another one for its 50 milliseconds of action. Eventually, the kernel works its way throughall of the processes and starts over again. The rapid switching from process to process gives the users ofthe machine the impression that all of the processes are running simultaneously.

ShellsLinux users often use a special type of program, called a shell, to interact with the kernel. The shell runswithin a terminal, issuing a prompt and waiting to be told what to do. A user then asks the shell to run aprogram by typing in the name of the program. In the following example, the user elvis asks the shell to runa simple calendar program called cal. The shell dutifully executes the program, and reports the program'soutput back to the terminal:

[elvis@station elvis]$ cal September 2011Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 1011 12 13 14 15 16 1718 19 20 21 22 23 2425 26 27 28 29 30 [elvis@station elvis]$

Because users use a shell to perform almost every task on the system, the shell is an important andsophisticated program. Much of this course will be devoted to learning how to use the shell to performtasks effectively.

When the user asks the shell to run a program, the user is said to be specifying a command for the shell.The shell is often referred to as a Command Line Interface.

The ps commandThe ps command is commonly used to list processes running on a system. The ps command, withoutarguments, shows all of the processes that were started from a single terminal (or terminal window ina graphical environment). In the following example, elvis discovers that his terminal currently has twoprocesses running: his bash shell, and the ps command itself.

[elvis@station elvis]$ ps PID TTY TIME CMD 1378 pts/1 00:00:00 bash 1418 pts/1 00:00:00 ps

The first column shows the process's PID, or Process ID. Every process running on the system is identifiedby a unique PID. The second column identifies elvis's terminal, and the third column reports how muchCPU time the process has consumed.

The ps aux command shows a detailed list of all processes that are currently running on the system. Fornow, we will not go into the details of what "aux" stands for, just consider it black magic to be memorized.Neither will we give a detailed discussion of all of the following fields. All of this will be addressedin a following workbook. Simply realize that at any given moment, there are usually a large number ofprocesses running on a Linux system. (Note that in the following output, many lines have been removedand replaced with "...").

[elvis@station elvis]$ ps auxUSER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMANDroot 1 0.0 0.1 19328 1476 ? Ss 08:44 0:00 /sbin/initroot 2 0.0 0.0 0 0 ? S 08:44 0:00 [kthreadd]root 3 0.0 0.0 0 0 ? S 08:44 0:00 [migration/0]

Page 17: Rha030 Workbook01 Student 6.1 2

The Kernel, Programs, and Processes

17

... root 1124 0.0 0.3 248680 3392 ? Sl 08:44 0:00 /sbin/rsyslogdrpc 1166 0.0 0.0 18952 856 ? Ss 08:44 0:00 rpcbinddbus 1191 0.0 0.2 98024 2072 ? Ssl 08:44 0:00 dbus-daemon root 1202 0.0 0.5 97408 5152 ? Ssl 08:44 0:00 NetworkManager root 1207 0.0 0.2 55832 2296 ? S 08:44 0:00 /usr/sbin/modemroot 1234 0.0 0.1 9100 1520 ? S 08:45 0:00 /sbin/dhclient -d -4 -sf /usrpcuser 1237 0.0 0.1 23124 1160 ? Ss 08:45 0:00 rpc.statdroot 1244 0.0 0.0 39328 600 ? Ss 08:45 0:00 /usr/sbin/wpa_supplicant -c root 1275 0.0 0.0 0 0 ? S 08:45 0:00 [rpciod/0]root 1282 0.0 0.0 29440 540 ? Ss 08:45 0:00 rpc.idmapdroot 1292 0.0 0.3 189016 3288 ? Ss 08:45 0:00 cupsd -C /etc/cups/cupsd.confroot 1317 0.0 0.0 4068 628 ? Ss 08:45 0:00 /usr/sbin/acpid...root 1415 0.0 0.1 63944 1072 ? Ss 08:45 0:00 /usr/sbin/sshdroot 1495 0.0 0.3 78544 3148 ? Ss 08:45 0:00 /usr/libexec/postfix/masterpostfix 1502 0.0 0.3 78692 3156 ? S 08:45 0:00 qmgr -l -t fifo -uroot 1506 0.0 0.4 262256 4440 ? Ss 08:45 0:00 /usr/sbin/abrtdroot 1514 0.0 0.1 117168 1340 ? Ss 08:45 0:00 crondroot 1525 0.0 0.0 21412 464 ? Ss 08:45 0:00 /usr/sbin/atdroot 1542 0.0 0.0 4048 316 ? Ss 08:45 0:00 /usr/bin/rhsmcertd 240root 1555 0.0 0.2 121468 2060 ? Ss 08:45 0:00 /usr/sbin/gdm-binary -nodaemonroot 1562 0.0 0.0 4052 520 tty2 Ss+ 08:45 0:00 /sbin/mingetty /dev/tty2root 1564 0.0 0.0 4052 516 tty3 Ss+ 08:45 0:00 /sbin/mingetty /dev/tty3...elvis 3599 0.0 0.1 108324 1748 pts/1 Ss 12:53 0:00 -bashelvis 3628 1.0 0.1 108048 1044 pts/1 R+ 12:55 0:00 ps aux

Questions

The kernel, programs, and processes1. Which of the following is not considered an operating system?

a. Red Hat Enterprise Linux

b. Windows XP

c. Microsoft Office

d. Mac OS X

2. Which of the following is not true for the Linux operating system?

a. Multiple processes appear to be running at the same time.

b. Only one instance of any given program may be running as a process.

c. Programs are stored as files in the filesystem.

d. Only one instance of the kernel may be running at any given time.

3. Which of the following is a true statement?

a. Only the root user may run processes from a shell.

b. The shell is a process that is commonly used to execute other processes.

c. The shell is the kernel component that interacts directly with hardware.

d. Only one instance of a shell may be running as a process.

Page 18: Rha030 Workbook01 Student 6.1 2

The Kernel, Programs, and Processes

18

4. Which of the following is the default shell for Red Hat Enterprise Linux?

a. /bin/bash

b. /bin/tcsh

c. /bin/zsh

d. /bin/sh

5. Which of the following is the command for listing processes?

a. ps

b. lsps

c. lps

d. ls

Page 19: Rha030 Workbook01 Student 6.1 2

19

Chapter 3. Examining the FilesystemKey Concepts

• The base of the Linux directory tree is a directory named / and referred to as "the root directory".

• Absolute file references, such as /home/elvis/lsout.txt, refer to files relative to the rootdirectory.

• Relative file references, such as lsout.txt, refer to files relative to a process's current workingdirectory.

• The ls command is used to list a directory's contents

• The cat command is used to examine the contents of a file.

• Using the > character from the shell's command line, the output of a command can be redirected fromthe terminal into a file.

• A user's home directory is one of the few places where users are able to create new files.

Discussion

The Naming of Files and DirectoriesIn Linux, information and programs are stored on disks as files. Files are grouped into directories, whichcan contain files and other directories. (Other operating systems often refer to directories as "folders").This hierarchy of directories containing directories is often referred to as the "directory tree".

The base of the directory tree is a directory named simply /, and referred to as "the root directory". Fileswithin the root directory can be referred to as /filename. In Red Hat Enterprise Linux, the root directorycontains mostly other directories, such as /etc. Files within these subdirectories may be referred to as /etc/filename, and the process continues for each new level of subdirectories. For example, the filenetwork found in the directory sysconfig, which is in turn found in the directory etc, which is inthe root directory /, can be referred to as /etc/sysconfig/network.

Obviously, starting at the root directory every time you refer to a file is a lot of work. Fortunately, Linuxprovides an easier way. Every process, including a user's shell, uses a "current working directory" forcontext. Files in a process's current working directory can be referred to as simply filename, without theleading slash. Files in subdirectories of the current working directory can be referred to as dirname/filename, again without the leading slash. For example, if a process's current working directory were /etc, the network file referred to above could be referred to as sysconfig/network. If the workingdirectory was /etc/sysconfig then the file could simply be referred to as network.

In summary, there are always two ways to refer to a file. File references relative to the root directory alwaysstart with a leading /, and are called absolute references. File references relative to the current workingdirectory start with something other than a /, and are referred to as relative references.

Listing directory contents with lsFrom a shell, users use the ls command to list the contents of a directory. (Think of the ls as a shorteningof the verb "list".) In the following example, the user elvis wants to list the contents of the /etc/sysconfig/rhn directory.

Page 20: Rha030 Workbook01 Student 6.1 2

Examining the Filesystem

20

[elvis@station elvis]$ ls /etc/sysconfig/rhnclientCaps.d rhnsd systemid up2date

The ls command, when called without arguments (i.e., without specifying a directory), lists the contents ofthe shell's current working directory. If using a color terminal, the ls command also colorizes the filenamesto help distinguish which of the directory contents are regular files (white), and which are directories (blue).

The ls command is a very flexible command that can provide a lot of different information. It will bediscussed in more detail in later lessons.

Viewing the contents of a file with catWhile the ls command lists the files contained in a given directory, it does not reveal the contents ofthe files. While several commands are available for viewing files, the simplest command is cat. The catcommand, when given a list of files, concatenates the files to the terminal output. If given one filename,the contents of that single file is displayed as output.

In the following example, the user elvis wants to view the contents of the /etc/hosts configuration file.

[elvis@station elvis]$ cat /etc/hosts# Do not remove the following line, or various programs# that require network functionality will fail.127.0.0.1 localhost.localdomain localhost::1 localhost6.localdomain6 localhost6192.168.0.254 server1.example.com server1192.168.0.1 station1.example.com station1

For now, don't worry about what the contents mean, just realize that the cat command displayed the entirecontents of this 5 line file.

Note that if you ask cat to display a very long file, or a binary (non text) file, cat will happily comply.There are more sophisticated commands for browsing large files, a screen full at a time, which will beintroduced later.

Redirecting command output to filesWhen the previous ls and cat commands were performed, their output was displayed on the terminal. InLinux, most commands which generate text output use a common Unix concept called the "standard out"stream. By default, this stream is connected to the terminal. The bash shell allows users to "redirect" thestandard out stream to other locations. For now, we will only learn the simplest case: using the > characterto redirect standard out into a file.

In the following example, the user elvis is again going to list the contents of the /etc/sysconfig/rhn directory, but redirect the output into a newly created file.

[elvis@station elvis]$ ls /etc/sysconfig/rhn > lsout.txt[elvis@station elvis]$ lslsout.txt[elvis@station elvis]$ cat lsout.txtclientCaps.drhnsdsystemidup2date

The output of the ls /etc/sysconfig/rhn command was not displayed on the terminal, but instead placedinto the newly created file lsout.txt. elvis next takes a ls of his current working directory, and seesthe newly created file. He then uses the cat command to observe the contents of the file. In "Unix speak",elvis "redirected the output from the ls command to the file lsout.txt".

Page 21: Rha030 Workbook01 Student 6.1 2

Examining the Filesystem

21

Permissions, and a user's home directory.

Notice what happens when elvis tries to redirect output to a file somewhere other than his shell's currentworking directory.

[elvis@station elvis]$ ls /etc/sysconfig/rhn > /etc/lsout.txt-bash: /etc/lsout.txt: No such file or directory

The user elvis has encountered another common Unix concept, that of file ownerships and permissions.elvis tried to create the new file /etc/lsout.txt, but elvis does not have permissions to create filesin the /etc directory.

By default, in Red Hat Enterprise Linux, users are not able to create files just anywhere. In fact, there areonly a few places where files can be created. Every user has a home directory, where they can create newfiles (and new subdirectories). Fortunately, when user's log in to a Linux session, their shell uses theirhome directory as its current working directory. By default in Red Hat Enterprise Linux, a user's homedirectory is named /home/username, where username is replaced with the user's username.

Upcoming workbooks will explore the filesystem and permissions in much more detail. For now, justrealize users are generally only allowed to create files in their home directory.

Examples

Redirecting command output to a file.

The user prince wants to use the cal command to store a calendar of the current month into the filecalendar.txt.

[prince@station prince]$ cal September 2011Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 1011 12 13 14 15 16 1718 19 20 21 22 23 2425 26 27 28 29 30

[prince@station prince]$ cal > calendar.txt

[prince@station prince]$ ls calendar.txt

[prince@station prince]$ cat calendar.txt September 2011Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 1011 12 13 14 15 16 1718 19 20 21 22 23 2425 26 27 28 29 30

prince first views the output of the cal command directly.prince runs the cal command again, redirecting the output to the file calendar.txtprince confirms that the new file was created by listing the contents of his current working directory(in this case, his home directory).prince examines the contents of the new file, to confirm that it does contain the output of the calcommand.

Page 22: Rha030 Workbook01 Student 6.1 2

Examining the Filesystem

22

Online Exercises

The ls Command

Lab Exercise

Objective: Redirect command output into a newly created file.

Estimated Time: 5 mins.

Specification

Use the ls command to list the contents of the /etc directory, redirecting the output of the command intoa file called lsetc.txt in your home directory.

Deliverables

1.1. The file lsetc.txt in your home directory, which contains the output of the command ls /etc.

Possible Solution

The following command provides a possible solution to this exercise.

[student@station student]$ ls /etc > lsetc.txt

Questions

Multiple Choice Questions.1. Assuming the shell's current working directory is /home/elvis, which of the following would

refer to the file /home/elvis/Mail/sent?

a. Mail/sent

b. /Mail/sent

c. sent

d. /sent

2. As the user elvis, whose shell's current working directory is /home/elvis, which of thefollowing would refer to the file received, which is in the directory Mail, which is in the homedirectory?

a. /home/elvis/Mail/received

b. Mail/received

c. received

d. both A and B.

3. Which of the following commands would list the files in the /usr/lib directory?

Page 23: Rha030 Workbook01 Student 6.1 2

Examining the Filesystem

23

a. cat /usr/lib

b. lsdir /usr/lib

c. /usr/lib list

d. ls /usr/lib

4. Which of the following commands would successfully redirect the output of the cal to the filelsout.txt?

a. lsout.txt > cal

b. cal ==> lsout.txt

c. cal > lsout.txt

d. cal } lsout.txt

5. For the user elvis, with /home/elvis for a home directory, which of the following commandswould succeed on a default Red Hat Enterprise Linux installation?

a. ls /etc > /etc/lsetc.txt

b. /etc/lsetc.txt < ls /etc

c. ls /etc > /home/elvis/lsetc.txt

d. /home/elvis/lsetc.txt < ls /etc

Page 24: Rha030 Workbook01 Student 6.1 2

24

Chapter 4. Running CommandsKey Concepts

• Like any language, the bash shell uses a specific grammar.

• The first word on any command-line is the name of the program to be run.

• The behavior of commands can be modified with (usually optional) command line switches, whichalways start with one or two hyphens (- or --).

• Any words that follow the command and any command line switches are called the arguments to thecommand.

• Some command line switches also take arguments.

• Commands usually support the --help, -h, or -? command line switch, which dumps a summary of howto use the command.

Discussion

Command Line GrammarWhile the command line interface has many advantages, including efficiency and flexibility, simplicity isnot one of them. Fortunately, there are conventions that (almost) all programs follow. A little time spentlearning these conventions can make learning new programs much easier.

If commands entered on the command line were compared to English sentences, the commands could bethought of as having verbs, adverbs, and direct objects. The verb is the command to run, the adverbs arethe various command line switches that can be used to modify the behavior of the command (“quietly”,or “verbosely”), and any remaining words are the direct objects (what the command is supposed to acton). Again, as in languages, there are irregularities, and for almost every rule mentioned, there will beexceptions.

CommandsThe first word on any command is generally the name of a program that lives as a file somewhere in thefilesystem. 1 For example, the previous lessons used the ps and who commands. If we want to know whichfile contains these programs, there is a program called which which can help us. The which command,followed by the name of another command, will tell you "which" file is being run.

[elvis@station elvis]$ which ps/bin/ps[elvis@station elvis]$ which who/usr/bin/who

When running a command, the shell process asks the kernel to execute the specified program as a separateprocess, and arranges the output (or, more correctly, the standard out stream) of the process to be written tothe terminal. The shell then pauses until the command's process terminates. Once the command finishes,the shell prints another prompt, and waits to be told what to do next.

1Exceptions to this rule include shell internals, shell aliases, and shell functions, which will be handled in the bash shell workbook.

Page 25: Rha030 Workbook01 Student 6.1 2

Running Commands

25

Command Line SwitchesMany commands can have their behavior modified by specifying different command line switches. Aneasy example is the ls command, which is used to list the contents of a directory. Consider the followingthree uses of the ls command, each time listing the files in the /usr directory:

[elvis@station elvis]$ ls /usrbin etc include lib local share tmpdict games kerberos libexec sbin src X11R6[elvis@station elvis]$ ls -s /usrtotal 132 40 bin 4 games 40 lib 8 sbin 0 tmp 4 dict 8 include 4 libexec 8 share 4 X11R6 4 etc 4 kerberos 0 local 4 src[elvis@station elvis]$ ls -l /usrtotal 132drwxr-xr-x 2 root root 40960 Apr 25 06:36 bindrwxr-xr-x 2 root root 4096 Jan 24 18:52 dictdrwxr-xr-x 2 root root 4096 Jan 24 18:52 etcdrwxr-xr-x 4 root root 4096 Jan 24 18:52 gamesdrwxr-xr-x 100 root root 8192 Apr 11 05:55 includedrwxr-xr-x 8 root root 4096 Mar 31 21:52 kerberosdrwxr-xr-x 90 root root 40960 Apr 25 06:36 libdrwxr-xr-x 10 root root 4096 Apr 11 05:51 libexeclrwxrwxrwx 1 root root 14 Sep 13 2002 local -> ../home/local/drwxr-xr-x 2 root root 8192 Apr 25 06:36 sbindrwxr-xr-x 212 root root 8192 Apr 23 16:30 sharedrwxrwxr-x 5 root pst 4096 Apr 25 08:12 srclrwxrwxrwx 1 root root 10 Apr 1 11:07 tmp -> ../var/tmpdrwxr-xr-x 8 root root 4096 Jan 24 18:52 X11R6

The first ls command simply lists the contents of the directory. The second ls -s command, which includesthe -s command line switch, gives the sizes of the contents as well. The third ls -l command gives a "long"listing, including all kinds of details about the files, such as ownerships, permissions, and modify times.For now, don't worry about all of the detailed output. This will be covered in an upcoming workbook onusing the filesystem. Just note how command line switches are used to modify the basic behavior of thels command.

Short Command Line Switches

Notice that both switches used above, -s and -l, are single letter switches. These are referred to as "short"command line switches. Sometimes, short command line switches can also take an argument. For example,the ls command has a -w command line switch, which specifies how "wide" the output should be, incharacters. Consider the following example.

[elvis@station elvis]$ ls -w 40 /usr/bin games lib sbin tmpdict include libexec share X11R6etc kerberos local src

In this case, the word 40 is not considered an argument to the ls command, but instead it is an argumentto the -w command line switch. (How wide should the output be? 40 characters.) Command line switcharguments simply follow the command line switch. How do you know which command line switches takearguments and which don't? The short answer is through experience, but we will soon mention ways tofind help as well.

Multiple Short Command Line Switches

More than one command line switch can be used at a time. The multiple command line switches are simplybunched together, squeezed between the command and any command arguments. The following example

Page 26: Rha030 Workbook01 Student 6.1 2

Running Commands

26

introduces a new -r switch for the ls command, which reverses the sorting order. Note how it is used alongwith the -s and -w switches.

[elvis@station elvis]$ ls -s -w 40 -r /usr/total 132 4 X11R6 0 local 4 games 0 tmp 4 libexec 4 etc 4 src 40 lib 4 dict 8 share 4 kerberos 40 bin 8 sbin 8 include

Often, when using multiple command line switches, users will take advantage of a shortcut that lets all ofthe switches be "piled together" onto one hyphen (-), as in the following example.

[elvis@station elvis]$ ls -srw 40 /usr/total 132 4 X11R6 0 local 4 games 0 tmp 4 libexec 4 etc 4 src 40 lib 4 dict 8 share 4 kerberos 40 bin 8 sbin 8 include

All of the single letter switches that don't take an argument, in this case -s and -r, can be piled together,sharing a single -. If a switch does take an argument, such as -w 40, it can only share a hyphen if it comeslast. That way, its argument can be specified next on the command line.

Long Command Line Switches

In the early days of Unix, all command line switches shared the syntax above. As Unix evolved, peoplecame to see a need for what are called "long" command line switches. Rather than single letter switches,long switches are composed of words. And rather than starting with a leading hyphen, long switches areproceeded by double hyphens (--). Some commands use only short switches, some commands use long.Many commands, including ls, handle some of both.

[elvis@station elvis]$ ls --size /usr/total 132 40 bin 4 games 40 lib 8 sbin 0 tmp 4 dict 8 include 4 libexec 8 share 4 X11R6 4 etc 4 kerberos 0 local 4 src

When long command line switches take an argument, the syntax differs slightly as well. Rather than theargument following the switch as a separate word, the argument is bunched together with the long switch,separated by an =, as in --width=40. Note also, that short and long command line switches can be mixed.

[elvis@station elvis]$ ls --width=40 --size -r /usr/total 132 4 X11R6 0 local 4 games 0 tmp 4 libexec 4 etc 4 src 40 lib 4 dict 8 share 4 kerberos 40 bin 8 sbin 8 include

ArgumentsCompared to command line switches, arguments are easy. Whatever words are left over on the commandline, after the command name and after any command line switches, are called arguments to the command.What a command expects as arguments, or if it expects any at all, depend on the command. For example,the ls command, if given arguments, will treat the arguments as the files or directories to be listed. Theps command expects no arguments. The cal command takes from zero to two, a possible month and apossible year to generate the calendar for. Learning what arguments a program expects, and what it doeswith its arguments, is part of learning how to use that command.

Page 27: Rha030 Workbook01 Student 6.1 2

Running Commands

27

Getting Help: UsageHow does anyone remember all of these command line switches? They don't. But experienced Linux userslearn how to easily refresh their memories. Most commands support either the --help long command lineswitch, or the -h or -? short command line switches. These switches usually make the command dump a"usage" message, rather than performing it's normal operation. The usage message contains a summary ofwhat arguments are expected, what command line switches are supported and what they do. Note that theusage message generated by the ls command is rather long, and has been abbreviated in the output below.

[elvis@station elvis]$ ls --help

Usage: ls [OPTION]... [FILE]... List information about the FILEs (the current directory by default).

Sort entries alphabetically if none of -cftuSUX nor --sort.

Mandatory arguments to long options are mandatory for short options too. -a, --all do not hide entries starting with . -A, --almost-all do not list implied . and .. --author print the author of each file -b, --escape print octal escapes for non-graphic characters

...

-k like --block-size=1K -l use a long listing format

...

-r, --reverse reverse order while sorting -R, --recursive list subdirectories recursively

-s, --size print size of each file, in blocks

...

-v sort by version

-w, --width=COLS assume screen width instead of current value -x list entries by lines instead of by columns

...

Some things to note in the usage message:

Optional elements are enclosed in square brackets ([ and ]).Here, the usage message refers to multiple short command line switches using the shortcut notation.Note that ls supports both the short (-s) and long (--size) forms of this command line switch.Here is the -w or --width command line switch, which requires an argument.

Usage messages do not provide a complete reference for the command, but merely provide enoughinformation to refresh memories. More ways to find help will be discussed in a later lesson in thisworkbook.

Examples

Learning to Use the cat CommandThe user madonna had a friend tell her that the cat command is used to look at the contents of files. Shehas never used the command before, and is interested in learning how to use it. She starts by examiningthe command's usage message.

[madonna@station madonna]$ cat --help

Page 28: Rha030 Workbook01 Student 6.1 2

Running Commands

28

Usage: cat [OPTION] [FILE]...Concatenate FILE(s), or standard input, to standard output. -A, --show-all equivalent to -vET -b, --number-nonblank number nonblank output lines -e equivalent to -vE -E, --show-ends display $ at end of each line -n, --number number all output lines -s, --squeeze-blank never more than one single blank line -t equivalent to -vT -T, --show-tabs display TAB characters as ^I -u (ignored) -v, --show-nonprinting use ^ and M- notation, except for LFD and TAB --help display this help and exit --version output version information and exit With no FILE, or when FILE is -, read standard input. Report bugs to <[email protected]>.

She doesn't yet understand all of the usage message, such as the references to standard input and standardoutput, but she can understand enough of the first line to understand that the cat command expectsfilenames for arguments. She tries to display the contents of the file /etc/anacrontab.

[madonna@station madonna]$ cat /etc/anacrontab# /etc/anacrontab: configuration file for anacron # See anacron(8) and anacrontab(5) for details. SHELL=/bin/shPATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin 1 65 cron.daily run-parts /etc/cron.daily7 70 cron.weekly run-parts /etc/cron.weekly30 75 cron.monthly run-parts /etc/cron.monthly

Looking at some of the usage messages command line switches, she notes that the -n command line switchnumbers the output lines. She tries out this switch.

[madonna@station madonna]$ cat -n /etc/anacrontab 1 # /etc/anacrontab: configuration file for anacron 2 3 # See anacron(8) and anacrontab(5) for details. 4 5 SHELL=/bin/sh 6 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin 7 8 1 65 cron.daily run-parts /etc/cron.daily 9 7 70 cron.weekly run-parts /etc/cron.weekly 10 30 75 cron.monthly run-parts /etc/cron.monthly

From the output, it's now easy to see that this file contains 10 lines, or to refer to line number 6. Shesuspects that the spacing between the words in lines 8 through 10 is made up of tab characters instead ofspaces. Noting from the usage message that the -t command line switch will replace any tab characterswith ^I, she tries to confirm her suspicion.

[madonna@station madonna]$ cat -t /etc/anacrontab# /etc/anacrontab: configuration file for anacron # See anacron(8) and anacrontab(5) for details. SHELL=/bin/shPATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin 1^I65^Icron.daily^I^Irun-parts /etc/cron.daily7^I70^Icron.weekly^I^Irun-parts /etc/cron.weekly

Page 29: Rha030 Workbook01 Student 6.1 2

Running Commands

29

30^I75^Icron.monthly^I^Irun-parts /etc/cron.monthly

She now notes from the usage that the -A command line switch is "equivalent to -vET", which she takesto be the shortcut combination of the short command line switches -v, -E, and -T. She tries both out, tosee if she's right.

[madonna@station madonna]$ cat -A /etc/anacrontab# /etc/anacrontab: configuration file for anacron$$# See anacron(8) and anacrontab(5) for details.$$SHELL=/bin/sh$PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin$$1^I65^Icron.daily^I^Irun-parts /etc/cron.daily$7^I70^Icron.weekly^I^Irun-parts /etc/cron.weekly$30^I75^Icron.monthly^I^Irun-parts /etc/cron.monthly$[madonna@station madonna]$ cat -vET /etc/anacrontab# /etc/anacrontab: configuration file for anacron$$# See anacron(8) and anacrontab(5) for details.$$SHELL=/bin/sh$PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin$$1^I65^Icron.daily^I^Irun-parts /etc/cron.daily$7^I70^Icron.weekly^I^Irun-parts /etc/cron.weekly$30^I75^Icron.monthly^I^Irun-parts /etc/cron.monthly$

Seeing the identical output, she decides she has interpreted the usage message correctly.

Questions

Command Line SyntaxThe touch command is used to update timestamps on specified files. Use the following usage and sampleinvocations for the command touch to answer the next 6 questions.

[madonna@station madonna]$ which touch/bin/touch[madonna@station madonna]$ touch --helpUsage: touch [OPTION]... FILE...Update the access and modification times of each FILE to the current time. Mandatory arguments to long options are mandatory for short options too. -a change only the access time -c, --no-create do not create any files -d, --date=STRING parse STRING and use it instead of current time -f (ignored) -m change only the modification time -r, --reference=FILE use this file's times instead of current time -t STAMP use [[CC]YY]MMDDhhmm[.ss] instead of current time --time=WORD set time given by WORD: access atime use (same as -a) modify mtime (same as -m) --help display this help and exit --version output version information and exit

Note that the -d and -t options accept different time-date formats.

If a FILE is -, touch standard output.

[madonna@station madonna]$ touch -r /etc/servicestouch: file arguments missing

Page 30: Rha030 Workbook01 Student 6.1 2

Running Commands

30

Try `touch --help' for more information.[madonna@station madonna]$ tooch /etc/services-bash: tooch: command not found[madonna@station madonna]$ touch -k /etc/servicestouch: invalid option -- kTry `touch --help' for more information.[madonna@station madonna]$ touch -r /etc/services /tmp/foo

1. Which of the following would be a legitimate invocation of the touch command?

a. touch -k /etc/services

b. touch -ac /etc/services

c. touch -nocreate /etc/services

d. touch -t

2. Which of the following would be a legitimate invocation of the touch command?

a. touch -frm /etc/services

b. touch --cm /etc/services

c. touch --no-create -a /etc/services

d. touch

3. Which best describes why madonna got the "file arguments missing" error message when runningtouch -r /etc/services?

a. The -r command line switch requires an argument, which madonna didn't supply.

b. The file /etc/services does not exist.

c. The touch command could not be found on the system.

d. -r is not a supported command line switch.

4. Which best describes why madonna got the "command not found" error message when runningtooch /etc/services?

a. The file /etc/services does not exist.

b. madonna misspelled the command name, and no command named tooch could be found.

c. The touch command requires a mandatory -a command line switch.

d. madonna does not have the right permissions to execute the command.

5. Which best describes why madonna got the "invalid option" error message when running touch-k /etc/services?

a. The file /etc/services does not exist.

b. madonna misspelled the command name, and no command named touch could be found.

c. The touch command requires a mandatory -a command line switch.

d. The touch command doesn't support the -k command line switch.

Page 31: Rha030 Workbook01 Student 6.1 2

Running Commands

31

6. When madonna ran the command touch -r /etc/services /tmp/foo, what best describes the role ofthe word /etc/services?

a. The word serves as an argument to the touch command.

b. The word serves as an argument to the -r command line switch.

c. The word serves as the name of the command to run.

d. The word is misplaced, and caused the command to exit in failure.

7. When a user runs the command who from the command line, which of the following best describeswhat happens?

a. The shell asks the kernel to execute the contents of the file /usr/bin/who as a separateprocess, displaying the process's output on the terminal.

b. The shell makes the who system call, prompting the Linux kernel for the output directly.

c. The shell exits, and is replaced by the who process. When the who process terminates, itreplaces itself with a new shell process.

8. When long command line switches were introduced, which best describes why they were precededwith a double hyphen (such as --size) instead of a single hyphen (such as -size)?

a. The creators of long command line switches liked to type a lot.

b. The word -size could be interpreted as a shortcut for the -s -i -z -e short command line switches,instead of a single long command line switch.

c. A single hyphen already implied a mandatory command line switch argument.

d. The creators of long command line switches liked to make things complicated.

Page 32: Rha030 Workbook01 Student 6.1 2

32

Chapter 5. Managing TerminalsKey Concepts

• Various control sequences, such as CTRL+C, CTRL+D, and CTRL+Z, can be helpful for managingprocesses from the terminal.

• A terminal's settings can usually be reset to a sane behavior with the reset command.

• The bash shell provides tab completion, which can be save a lot of typing when specifying commandor files.

• Various types of terminals can be distinguished by knowing how Linux refers to devices.

DiscussionControlling Terminals

The bash shell, and the terminal it runs on, are the primary tools used by experienced Linux users. Laterin this course, an entire Workbook will be devoted to using the bash shell's powerful features. This lessonintroduces some features shared by terminals in general, and one feature of the bash shell that is too usefulto delay until later, tab completion.

Resetting TerminalsWhen terminals display information, they usually display one byte at a time. When computers are handlinghuman readable text, the characters are usually encoded as an integer byte value using the ASCII format.While a byte can encode up to 256 different values, only a small number of these (about 100) are used fortext characters and punctuation. The others are used to encode control sequences (see below) and otherspecial conditions.

Sometimes, users accidentally (or intentionally) ask a terminal to display data that is not encoded as ASCIItext, such as an image or an executable. The terminal does the best job it can, displaying characters forASCII text, but what often appears to be random garbage for bytes that refer to control characters. Evenworse, the terminal can end up in an alternate graphics mode, so that even what should be normal ASCIItext looks unreadable.

In these situations, the reset command can restore the terminal to sane behavior. Usually, when you'd liketo use this command, you won't even be able to see yourself type it. However, if at an unreadable bashprompt, blindly typing reset and followed by the RETURN key will usually restore the terminal to sanebehavior.

Terminal control sequencesLinux terminals share a lot in common with their primitive ancestors, teletypes and "dumb" or vt100-like consoles. These early devices had mechanisms for sending "out of band" signals, or sequences thatsignaled some event outside of the normal flow of typed characters, such as a backspace, a linefeed, anaudible bell, or an end of transmission. Linux terminals, like their predecessors, use the CTRL key to sendthese "out of band" signals.

The following table summarizes many of the commonly used control sequences that are shared by allLinux terminals, and their common usage, in alphabetical order. Following the table, the various controlsequences are discussed in order of general usefulness.

Page 33: Rha030 Workbook01 Student 6.1 2

Managing Terminals

33

Table 5.1. Linux Terminal Control Sequences

Key Combination Symbolic Name Conventional Use

CTRL+C SIGINT Abnormal Interrupt - terminatethe foreground process

CTRL+D EOT Normal signaling of the end ofinput

CTRL+G BEL Sound an audible terminal bell

CTRL+H BS Backspace - erase the previouscharacter

CTRL+J LF Line feed - alternative for theRETURN key

CTRL+L FF Form feed - causes bash to clearscreen, and other screen basedprograms to "refresh" the currentscreen.

CTRL+Q Thaw the terminal display (seeCTRL+S)

CTRL+S Freeze the terminal display (thawwith CTRL+Q)

CTRL+U NAK Erase current line

CTRL+Z SIGSTOP Suspend the foreground process

CTRL+C CTRL+C is probably the most useful of the above sequences, coming to the rescuewhenever a user is feeling "JUST MAKE IT STOP!" When using the bash shell, typingCTRL+C will terminate the currently running process, and return you to the bash prompt.

The /dev/zero device node is a pseudo device that, when read, returns an infinite numberof (binary) zeros. The /dev/null device node is a pseudo device that throws away anyinformation written to it. The following command, therefore, would run forever, readingzeros and throwing them away. Someone stuck in this situation could use CTRL+C tocancel the command.

[elvis@station elvis]$ cat /dev/zero > /dev/null(... user types CTRL-C ...) [elvis@station elvis]$

CTRL+D As will be discovered in a later workbook, many Unix commands read their input directlyfrom the keyboard. Unfortunately for new Unix users, it's not always obvious how to tellthe command when to stop listening. The answer is CTRL+D. This control sequence isused to send an "End of Transmission" (usually interpreted as "End of File") to the listeningprocess.

The wc command is an example of a command that, when not given a filename as anargument, will count the number of lines, words, and characters that a user types in fromthe keyboard. The user signals the end of the input with CTRL+D.

[elvis@station elvis]$ wcpolly wants a crackerpolly wants a crackerpolly wants a cracker(... user types CTRL-D ...)

Page 34: Rha030 Workbook01 Student 6.1 2

Managing Terminals

34

3 12 66[elvis@station elvis]$

The wc command dutifully reports that the user typed 3 lines, as 12 words, using 66characters. (While this doesn't seem so useful now, many more uses will be found for wcin a later workbook.) What would have happened if the user had typed CTRL+C instead?

The wc command would have been canceled, not reporting any output.

CTRL+Z CTRL+Z is used to suspend a program, which can later be restored with the fg("foreground") command. While in the middle of an ftp session, elvis wants to determinehis shell's current working directory. He suspends the ftp session with CTRL+Z, runs thepwd command from the shell, and then restores the ftp session with fg.

[elvis@station elvis]$ ftp ftp.redhat.comTrying 66.187.232.51...Connected to ftp.redhat.com (66.187.232.51).220 Red Hat FTP server ready. All transfers are logged. (FTP)Name (ftp.redhat.com:elvis): anonymous331 Please specify the password.Password:230 Login successful. Have fun.Remote system type is UNIX.Using binary mode to transfer files.ftp>(... user types CTRL-Z ...)[1]+ Stopped ftp ftp.redhat.com[elvis@station elvis]$ pwd/home/elvis[elvis@station elvis]$ fgftp> ftp.redhat.comftp> ls227 Entering Passive Mode (66,187,232,51,67,212)150 Here comes the directory listing.drwxr-xr-x 6 ftp ftp 4096 May 24 01:33 pub226 Directory send OK....

Managing processes in this manner is a fairly complicated subject, which will be discussedin detail in a later Workbook. For now, just know that CTRL+Z suspends, and fg resumes.

CTRL+U CTRL+U is commonly used to "wipe" the current line. If you have so mangled a bashcommand line that you just want to start over, type CTRL+U. Also, CTRL+U is veryhelpful when you mess up while entering a password. Because your characters are usuallynot echoed back to you, its often hard to know what you've type. Just type CTRL+U andstart over.

CTRL+H CTRL+H serves the exact same role as the BACKSPACE key. On some terminals,however, the BACKSPACE key is incorrectly mapped, and doesn't function correctly.CTRL+H will almost always work in these situations.

CTRL+L CTRL+L was traditionally used to tell a line printer to eject the current page and starton the next one. For online terminals, it has been repurposed for redrawing screens. Formany screen based programs, including the vi and nano editors, if the screen ever becomesmangled because of unexpected messages, a CTRL+L will cause the program to refreshthe screen, redrawing it correctly.

For the bash shell, CTRL+L causes bash to clear the screen, but preserve the currentcommand line.

Page 35: Rha030 Workbook01 Student 6.1 2

Managing Terminals

35

CTRL+Q CTRL+Q "thaws" a screen (causing it to become active again) after it has been "frozen"with a CTRL+S. Although it is only useful after a CTRL+S has been used, it is introducedfirst (as the more useful command) because almost no one intentionally uses CTRL+S.Instead, new Unix users will sometimes accidentally type a CTRL+S, and not understandwhy their terminal has gone unresponsive. If your terminal ever seems dead, try typing aCTRL+Q and see if that fixes it.

CTRL+S See CTRL+Q above.

CTRL+J Almost never used. (People use the RETURN key instead.)

CTRL+G The only real use is to make the terminal beep, impressing your friends with your vastreservoirs of Unix knowledge.

Identifying terminalsDating back from it's origins as a terminal server, Unix is obsessed with the concept of a terminal. Processesare grouped into "sessions" based on which terminal they were started from. While somewhat outdated,knowing how to recognize terminals can help in tracking the origins of processes.

As with most other devices, programs interact with terminals at a low level through device nodes, foundwithin the /dev directory. For example, communication with the first virtual console uses the devicenode /dev/tty1. Most processes keep a record of which terminal they were started from, and user'slogin sessions are usually associated with the terminal they are using. When identifying terminals in thesesituations, the terminal is referred to by its device node, for example, tty1.

In the following excerpt, elvis is listing the current users on a machine with who, and listing the currentprocesses running from his terminal with ps. In both cases, the terminal is specified in the column "TTY".

[elvis@station elvis]$ whoroot tty2 Jun 21 10:12elvis tty3 Jun 21 16:50blondie tty1 Jun 21 10:13 :0blondie pts/0 Jun 21 16:43 (:0.0)blondie pts/1 Jun 21 10:14 (:0.0)blondie pts/2 Jun 21 10:31 (:0.0)blondie pts/3 Jun 21 10:39 (:0.0)[elvis@station elvis]$ ps PID TTY TIME CMD 4384 tty3 00:00:00 bash 4427 tty3 00:00:00 ps

Many different devices are treated by Linux as a terminal, including virtual consoles, serial line connectedVT100 terminals, modems, etc. The following table lists some of the common terminal names that areconventionally used for some common terminal devices.

Table 5.2. Terminal Device Names

Name Device How used

ttyn Virtual Console Accessed with the CTRL+ALT+Fn key combination.

ttySn Serial Port device A modem or VT100 like terminal attached to a serial port.The terminal ttyS0 in Unix relates to COM1 in DOS, ttyS1 toCOM2, and so on.

pts/n Pseudo-terminal A terminal emulation, most often used by terminal windows inthe X graphical environment, or shells which originate over thenetwork, such as with telnet or ssh. Pseudo-terminals cannotbe related directly to a physical device.

Page 36: Rha030 Workbook01 Student 6.1 2

Managing Terminals

36

Name Device How used

:0 X server The X server is not really a terminal. When a user logs in usingthe X graphical environment, their terminal may be listed asthe X server itself.

Tab CompletionTab completion is not really a feature of terminals, but of the bash shell that is usually run within them. Tabcompletion could well be the most helpful topic within this lesson. When typing the names of commandsand files, a lot of time and effort can be saved by learning how to make good use of the TAB key.

When typing the name of a command as the first word of a bash command line, start typing the commandyou would like to run, but at some point before you finish the word, stop and hit the TAB key. One ofthree things will happen.

1. The rest of the command you were beginning to type magically appears.

2. Part of the command you were typing magically appears, but then bash stops and beeps at you.

3. bash just beeps at you.

The bash shell does the best job that it can in selecting the command you were starting to type from thelist of all possible commands. In the first case, there is only one command that started out with the lettersthat you typed, so bash was able to figure out exactly what command you were starting, and finished itfor you. You're done.

In the second and third cases, more than one command started out with the letters you were typing. bashcompleted the command as far as possible, but stopped with a beep to let you know that you still have somechoices to make. In order to see the selection of commands that bash has narrowed it down to, hit the TABkey a second time. bash will list all commands that start with what you have typed. Supply enough of theremainder of the command to make it unique, and hit TAB again. bash will finish the command off for you.

An example is in order.

The user elvis wants to enable Unicode mode for his terminal. Don't worry about what Unicode mode is,or why he wants to do it. Just know that the command that enables Unicode mode is called unicode_start,and the command that disables it is called unicode_stop. He begins typing the command, and hits theTAB key.

[elvis@station elvis]$ unic<TAB>

bash expands the word to unicode_st, and beeps. In order to see the list of possible completions, elvishits the TAB key twice.

[elvis@station elvis]$ unicode_st<TAB><TAB>unicode_start unicode_stop

bash returns with a list of two commands that both start unicode_st. Seeing that the command that elviswants to run is the only one that starts out unicode_sta, elvis types an a, and hits TAB again.

[elvis@station elvis]$ unicode_sta<TAB>

bash completes the command, and positions the cursor so that its ready to begin typing any arguments orcommand line switches for the command.

[elvis@station rha030]$ unicode_start

Page 37: Rha030 Workbook01 Student 6.1 2

Managing Terminals

37

Not only does bash complete the first word against available commands, but all other words on thecommand line can be completed against files in the filesystem. For example, suppose madonna wanted toexamine the file /etc/updatedb.conf. Rather than typing out the entire file name, she could typethe first part, and hit TAB.

[madonna@station madonna]$ cat /etc/upd<TAB>

Because /etc/updatedb.conf is the only file that starts out /etc/upd, bash is able to completethe file.

[madonna@station madonna]$ cat /etc/updatedb.confPRUNEFS = "auto afs iso9660 sfs udf"PRUNEPATHS = "/afs /media /net /sfs /tmp /udev /var/spool/cups /var/spool/squid /var/tmp"

As you proceed through the course, a little time spent exploring tab completion can save a lot of time andeffort down the road. After a while, using the TAB key to save typing becomes second nature. After theend of a busy day, the left little finger can hurt because it spent the day pounding the TAB key.

Examples

Resetting the terminal after viewing a binary file.The user blondie accidentally uses the cat command to view an executable file, /bin/arch. Because thefile is a compiled executable, it contains bytes that aren't meant to be displayed on a terminal, and sendsher terminal into haywire behavior.

[blondie@station blondie]$ cat /bin/archELF??414 (44???4????/lib/ld-linux.so.2GNU???y??6,?????aaa????aac????-?????[???

In order to reset her terminal, blondie blindly types the reset command, and her terminal is restored toa sane condition.

[blondie@station blondie]$

Canceling a commandThe user prince thought it would be interesting to recursively list the contents of his filesystem, startingwith the root directory /.

[prince@station prince]$ ls -R //:bin data etc initrd lost+found mnt proc root sbin usr webboot dev home lib misc opt rha RPMS tmp var /bin:arch cut gawk mail rm touchash date gettext mkdir rmdir trueash.static dd grep mknod rpm umountaumix-minimal df gtar mktemp rvi unameawk dmesg gunzip more rview unicode_startbasename dnsdomainname gzip mount sed unicode_stopbash doexec hostname mt setfont unlinkbash2 domainname igawk mv setserial usleep...

After a few minutes watching files go by, he feels like he's seen enough. He cancels the command bytyping a CTRL+C. The command terminates, and he is returned to the bash prompt.

[prince@station prince]$

Page 38: Rha030 Workbook01 Student 6.1 2

Managing Terminals

38

Online Exercises

Suspending terminal output

Lab Exercise

Objective: Learn to manage terminal output for long running commands.

Estimated Time: 5 mins.

Specification

1. Like prince in the example, take a recursive listing of the root directory of the filesystem, using thecommand ls -R /.

2. While the output is flowing by, freeze your terminal using the CTRL+S control sequence.

3. Thaw the terminal using the CTRL+Q control sequence. You should be able to alternately freeze andthaw the streaming output by using these control sequences.

4. With the output from the command still flowing, suspend the process with the CTRL+Z controlsequence.

5. Confirm your lab with the process suspended.

Deliverables

1.1. A stopped (suspended) ls -R / command.

Cleaning Up

After you have finished confirming your deliverable, restore the suspended process to the foreground withthe fg command. Now cancel it with the CTRL+C control sequence.

Sorting your socks.

Lab Exercise

Objective:Learn how to usefully terminate input for a command reading from the keyboard.

Estimated Time: 5 mins.

Specification

You would like to generated a list of (alphabetically) sorted socks in the file sorted_socks.txt inyour home directory.

1. Run the command sort > sorted_socks.txt in your home directory. The command should notimmediately terminate, but instead wait for input from the keyboard.

2. Type in several types of socks, such as "yellow socks", "dirty socks", "cool winnie the pooh socks",etc. Separate each type of sock with a new line by using the RETURN key.

Page 39: Rha030 Workbook01 Student 6.1 2

Managing Terminals

39

3. After listing several socks, terminate the list with the CTRL+D control sequence. You should nowhave a file that contains a list of sorted socks.

4. Exit your shell, so that your history gets saved.

[student@station student]$ sort > sorted_socks.txtyellow socksdirty sockscool winnie the pooh socks(... type CTRL-D ...)[student@station student]$ cat sorted_socks.txtcool winnie the pooh socksdirty socksyellow socks

Deliverables

1.1. A file in your home directory called sorted_socks.txt, which contains a list of sorted

socks, and a .bash_history file that contains the command sort > sorted_socks.txt.

Questions1. Which of the following commands can restore a terminal to sane behavior?

a. sanetty

b. reload

c. start-unicode

d. reset

e. sane

2. Which of the following control sequences can be used to suspend a command?

a. CTRL+C

b. CTRL+D

c. CTRL+Q

d. CTRL+U

e. CTRL+Z

3. If you walk up to a terminal that seems completely non-responsive, which control sequence mightrestore activity?

a. CTRL+C

b. CTRL+D

c. CTRL+Q

d. CTRL+U

Page 40: Rha030 Workbook01 Student 6.1 2

Managing Terminals

40

e. CTRL+Z

4. If you suspect that you have mistyped while entering a password, which control sequence wouldallow you to start over?

a. CTRL+C

b. CTRL+D

c. CTRL+Q

d. CTRL+U

e. CTRL+Z

5. If you want to cancel a command that is generating too much output, which control sequence wouldbe most helpful?

a. CTRL+C

b. CTRL+D

c. CTRL+L

d. CTRL+S

e. CTRL+U

6. If you want to freeze the terminal output, so that you can resume it later, which control sequencewould be most helpful?

a. CTRL+C

b. CTRL+D

c. CTRL+L

d. CTRL+S

e. CTRL+U

7. Which control sequence causes bash to clear the screen?

a. CTRL+C

b. CTRL+D

c. CTRL+L

d. CTRL+S

e. CTRL+U

Use the output from the who command to answer the following questions.

[prince@station prince]$ whoblondie tty2 Apr 21 22:07elvis tty3 Apr 21 22:07elvis tty4 Apr 21 22:07

Page 41: Rha030 Workbook01 Student 6.1 2

Managing Terminals

41

root tty6 Apr 21 22:07prince tty1 Apr 21 21:50 (:0)prince pts/0 Apr 21 21:53 (:0.0)prince pts/1 Apr 21 21:54 (:0.0)prince pts/2 Apr 21 21:55 (:0.0)madonna pts/3 Apr 21 22:08 (:0.0)

8. How has the user blondie logged onto the Enterprise Linux machine?

a. Using the Login Manager in the X graphical environment.

b. A virtual console.

c. A serial line connected terminal.

d. A ssh network connection

e. The login method cannot be determined with the information provided.

9. How has the user prince logged onto the Enterprise Linux machine?

a. Using the Login Manager in the X graphical environment.

b. A virtual console.

c. A serial line connected terminal.

d. A ssh network connection

e. The login method cannot be determined with the information provided.

10. Which user logged on as the administrative user root?

a. blondie

b. elvis

c. madonna

d. prince

e. It cannot be determined with the information provided.

Page 42: Rha030 Workbook01 Student 6.1 2

42

Chapter 6. Getting HelpKey Concepts

• Most commands provide terse summaries when invoked with the -h, -?, or --help command line switch.

• More complete reference information can be found in the "man pages", which are viewed with the mancommand.

• The man pages have chapters, and the content of a preceding chapter might obscure the content of atrailing chapter.

• More complicated commands are often more fully described in info pages.

• In Red Hat Enterprise Linux, any less conventional documentation associated with a specific packagecan be found in /usr/share/doc.

• The Linux Documentation Project provides a wealth of Linux related documentation.

• Red Hat manuals provide documentation specific to the Red Hat Enterprise Linux distribution.

Discussion

Getting HelpUnix, and Linux in particular, has a tradition that manuals and documentation should not be kept on abookshelf, but found within the system, in easy reach of the system's users. No one remembers everycommand line switch to the ls command, so most commands provide terse summaries called "usages"when invoked with the appropriate command line switches. More complete reference information for mostcommands can be found in structured "man" pages and "info" pages. In Red Hat Enterprise Linux, the/usr/share/doc directory contains less structured documentation specific to a particular package.Lastly, a wealth of guides and tutorials can be found at the Linux Documentation Project, or in Red HatEnterprise Linux documentation packages.

Obtaining Usages with -h, -?, and --helpYou will probably discover, as you proceed through this course, that Unix often makes design choices infavor of terseness and efficiency, rather than transparency, when naming commands and command options.This is particularly true of the more commonly used commands, such as mv, ps, and vi. This choice makesUnix very efficient for the knowledgeable user, often at the expense of the learner.

No one remembers all of the functionality of every command, but experienced Unix users know howto quickly find the information they are looking for online. The first layer of help is often provided bycommands themselves, in the form of "usages", or short summaries of syntax that are produced when thecommand is invoked with the -h, -?, or --help command line switch. Usages were covered in a previousLesson, but are mentioned here again for the sake of completeness.

Man PagesManual pages, more often abbreviated "man pages", are the traditional source of reference information ofUnix systems. A documentation page for most commands, file formats, programming calls, and generaltopics can be viewed using the man command. For example, man ls generates documentation for the lscommand.

Page 43: Rha030 Workbook01 Student 6.1 2

Getting Help

43

The less Pager

Red Hat Enterprise Linux uses the less pager for viewing man pages. When viewing files (including manpages) in less, navigation is provided by single letter keystrokes: space is used to view the next page, b isused to go back a page, q is used to quit. less will be covered in more detail in a later lesson, but the tablebelow summarizes some of the most useful navigation commands when viewing man pages with less.

Table 6.1. Basic less Navigation

Command Action

space View next page

b View previous page

q Quit

/ text RETURN Search for word text

n Find next occurrence of previously used search term

Man Chapters

Man pages are organized into eight standard chapters, as itemized in the following tables. Some pagesshare identical names in different chapters. For example, pages exist for both the passwd command, foundin chapter one on user commands, but also the /etc/passwd file, found in chapter five on file formats.Unfortunately for the user trying to find documentation on the /etc/passwd file format, man passwdonly displays the first page it finds, in this case the entry from chapter one. In order to view the man pagefrom chapter five, the chapter must be explicitly specified, as in man 5 passwd.

Table 6.2. Man Chapters

Chapter Audience Topic

1 standard users Commands

2 developers System Calls

3 developers Library Calls

4 administrators Device Files

5 standard users File Formats

6 standard users ??? (see questions)

7 standard users General Information

8 administrators Administrator Commands

In Unix, references to man pages customarily include the chapter number in parentheses after the name ofthe page, such as passwd(1) or passwd(5). Each chapter contains an introductory page called intro, so thecommand man 5 intro would produce an introduction to chapter 5.

Keyword Searches, and the -a Switch.

Two switches commonly used with the man command include -k, for performing keyword searches, and-a, for viewing "all relevant" pages for an argument. The user madonna is trying to find information on theformat for the /etc/passwd file. She has already discovered that man passwd only produces the manpage for the passwd command, so she uses man -k to perform a keyword search on the word passwd.

[madonna@station madonna]$ man -k passwd

Page 44: Rha030 Workbook01 Student 6.1 2

Getting Help

44

...chpasswd (8) - update password file in batchgpasswd (1) - administer the /etc/group filehesiod_free_passwd [hesiod_getpwnam] (3) - Hesiod functions for retrieving passwd informationhesiod_getpwnam (3) - Hesiod functions for retrieving passwd informationhesiod_getpwuid [hesiod_getpwnam] (3) - Hesiod functions for retrieving passwdinformationhtpasswd (1) - Create and update user authentication filesldappasswd (1) - change the password of an LDAP entrylppasswd (1) - add, change, or delete digest passwordspam_localuser (8) - require users to be listed in /etc/passwdpasswd (1) - update a user's authentication tokens(s)

passwd (5) - password file passwd [sslpasswd] (1ssl) - compute password hashessaslpasswd (8) - set a user's sasl passwordsmbpasswd (5) - The Samba encrypted password filesmbpasswd (8) - change a user's SMB password...

madonna got more than she bargained for, but included in the output is a reference to the passwordfile, and the fact that the information is found in chapter 5 of the man pages.

Now that madonna knows the right chapter, she pulls up the appropriate page with man 5 passwd. Asanother approach, madonna could have used the -a command line switch, which tells the man commandto view all relevant pages, in order.

Info PagesMan pages are usually designed to provide reference information, not tutorials or help on general context.Many more complicated commands are more fully documented in hyperlinked "info" pages. Info pagespredate the days of web browsers and clickable links. Info pages are viewed using either the traditionalinfo command, or Red Hat Enterprise Linux provides a similar command with an easier interface calledpinfo. Info pages are primarily used by software developed by the GNU project [http://www.gnu.org].

The command pinfo, without arguments, will list a table of contents for all installed info pages. Basicnavigation is similar to the less pager. Links among the info pages can be traversed using the four arrowkeys, as outlined in the table below.

Table 6.3. pinfo Navigation

Command Action

SPACE Next page

b Previous page

q Quit

/text RETURN Search for word text

RIGHT ARROW Follow Link

LEFT ARROW Back

UP ARROW Previous Link

DOWN ARROW Next Link

The /usr/share/doc DirectoryOne of the design principles behind open source software is often summarized "release early, releaseoften". When developing software, distribute it as soon as it is useful, even if it is not yet polished or well

Page 45: Rha030 Workbook01 Student 6.1 2

Getting Help

45

documented. By allowing users to use software early, they can help influence the ongoing design of thesoftware for the better.

Red Hat Enterprise Linux embraces this philosophy, and will include useful, stable software, even if thesoftware is not formally documented in man pages or info pages. Often, documentation about how touse newly developed products might be a simple text file called README hastily thrown together by thedeveloper. Red Hat Enterprise Linux includes such unstructured, but often still helpful, documentation,within the /usr/share/doc directory, organized by the Red Hat package that owns the software.

Your mileage will vary about how useful the documentation is for any given package. For example, elvisdiscovers that the informal documentation provided for the evince document viewer is rather skimpy,consisting primarily of the developers' unstructured ChangeLog and a terse README.

[elvis@station elvis]$ ls -s /usr/share/doc/evince-0.6.0/total 308300 ChangeLog 8 README

In contrast, a wealth of information about configuring the complicated file sharing service samba can befound under its /usr/share/doc directory, including subdirectories containing documentation in avariety of formats, and PDF copies of three texts on the subject.

[elvis@station ~]$ ls /usr/share/doc/samba-3.0.23c/autofs libsmbclient README Samba3-Developers-Guide.pdfCOPYING Manifest registry Samba3-HOWTO.pdfhistory misc REVISION THANKShtmldocs printer-accounting Roadmap WHATSNEW.txtLDAP printing Samba3-ByExample.pdf

Red Hat Documentation GuidesRed Hat Enterprise Linux includes documentation manuals, developed as a service provided by Red Hat,Inc. The following documentation manuals, amongst others, are available online [http://docs.redhat.com],and some are also available using the help utility discussed in an upcoming section.

• Deployment Guide

• Installation Guide

• Release Notes

• Virtualization Guide

These manuals provide information specific to the Red Hat Enterprise Linux operating system, includingbackground information and step by step instructions for various tasks.

The Linux Documentation ProjectThe Linux Documentation Project [http://www.tldp.org] has adopted the unenviable task of documentingall of the fast paced developments associated with the Linux Operating System. Documentation at this sitefollows formats developed in the the early days of Linux development.

FAQs FAQs are compilations of Frequently Asked Questions about a particular topic, such as theLinux-RAID FAQ.

HOWTOs HOWTOs provide step by step instructions about how to set up or configure a particularfacet of Linux, such as the CD-Writing-HOWTO, or the ETHERNET-HOWTO.

Page 46: Rha030 Workbook01 Student 6.1 2

Getting Help

46

GUIDES Guides provide more in depth coverage of broad topics, such as System Administration, oreven Linux Kernel Module Programming.

While the documentation is not specific to the Red Hat Enterprise Linux distribution, much of theinformation is still useful and relevant.

yelp: The Gnome Help Browser

Lastly, we introduce yelp, the GNOME Help Browser, which can be started by choosing "Help" from theSystem menu.

Figure 6.1. Starting Yelp

While yelp provides the primary documentation for many GNOME specific graphical applications,including the Nautilus File Manager and GNOME applets, there are also subtle entries referring to "ManualPages" and "GNU Info Pages" at the bottom of the table of contents. These provide a "clickable" front endto the man pages and info pages, respectfully, and the wealth of information contained therein.

Page 47: Rha030 Workbook01 Student 6.1 2

Getting Help

47

Figure 6.2. yelp: The GNOME Help Browser

Additionally, the Red Hat Release Notes, mentioned previously when introducing the documentation foundat www.redhat.com [http://docs.redhat.com], can be accessed by choosing the nearby "Documentation"selection from the System menu.

Figure 6.3. Accessing The Red Hat Enterprise Linux Release Notes

Page 48: Rha030 Workbook01 Student 6.1 2

Getting Help

48

Questions1. Which of the following is not a way to obtain help for the ls command?

a. help ls

b. ls --help

c. man ls

d. pinfo ls

e. All are legitimate ways of obtaining help.

2. When viewing a man page, which key causes the pager to quit?

a. Z

b. TAB

c. q

d. RETURN

e. SPACE

3. Which chapter of the man pages would contain documentation on the /etc/group configurationfile?

a. 1

b. 4

c. 5

d. 7

e. 8

4. Which chapter of the man pages would contain documentation on the groups command?

a. 1

b. 4

c. 5

d. 7

e. 8

5. Which chapter of the man pages would contain documentation on filename suffixes, and the typeof file that they imply?

a. 1

b. 4

Page 49: Rha030 Workbook01 Student 6.1 2

Getting Help

49

c. 5

d. 7

e. 8

6. In the table listing man page chapters, chapter 6 was omitted. What does this chapter containinformation on?

a. Unix history

b. hardware devices

c. networking protocols

d. graphical applications

e. games

7. Which of the following commands would generate a keyword search of the man pages for theword sleep?

a. mankey sleep

b. man --key sleep

c. man -key sleep

d. keyword sleep

e. None of the above commands would work.

8. Informally structured documentation is found where in a Red Hat Enterprise Linux distribution?

a. Red Hat Enterprise Linux only includes formally structured documentation.

b. /usr/share/doc

c. /usr/doc

d. /usr/doc/share

e. /tmp/doc/

9. Which of the following interfaces to the info pages allows someone to navigate links with mouseclicks?

a. The pinfo command.

b. The info command.

c. The yelp application.

d. A and C

10. What type of help can be viewed with the GNOME Help Browser, yelp?

a. documentation for GNOME graphical applications

Page 50: Rha030 Workbook01 Student 6.1 2

Getting Help

50

b. man pages

c. info pages

d. A and C

e. All of the above