rha030-workbook01-student-3.0-0

56
Workbook 1. Quick Tour Red Hat, Inc.

Transcript of rha030-workbook01-student-3.0-0

Page 1: rha030-workbook01-student-3.0-0

Workbook 1. Quick Tour

Red Hat, Inc.

Page 2: rha030-workbook01-student-3.0-0

Workbook 1. Quick Tourby Red Hat, Inc.Copyright © 2003-2005 Red Hat, Inc.

Revision HistoryRevision rha030-2.0-2003_11_12-en 2003-11-12First RevisionRevision rha030-3.0-0-en-2005-08-17T07:23:17-0400 2005-08-17First Revision

Red Hat, Red Hat Network, the Red Hat "Shadow Man" logo, RPM, the RPM logo, PowerTools, and all Red Hat-based trademarks and logos aretrademarks or registered trademarks of Red Hat, Inc. in the United States and other countries.Linux is a registered trademark of Linus Torvalds.Motif and UNIX are registered trademarks of The Open Group.Windows is a registered trademark of Microsoft Corporation.Intel and Pentium are a registered trademarks of Intel Corporation. Itanium and Celeron are trademarks of Intel Corporation.SSH and Secure Shell are trademarks of SSH Communications Security, Inc.All other trademarks and copyrights referred to are the property of their respective owners.

Published 2005-08-17

Page 3: rha030-workbook01-student-3.0-0

Table of Contents1. Logging In............................................................................................................................................... 5

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

Examples.......................................................................................................................................... 11Example 1. Using virtual consoles ......................................................................................... 11

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

Questions.......................................................................................................................................... 132. The Kernel, Programs, and Processes................................................................................................ 16

Discussion ........................................................................................................................................ 16The Linux Kernel.................................................................................................................... 16Programs................................................................................................................................. 17Processes................................................................................................................................. 17Shells ...................................................................................................................................... 18The ps command .................................................................................................................... 18

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

3. Examining the Filesystem ................................................................................................................... 21Discussion ........................................................................................................................................ 21

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

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

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

Questions.......................................................................................................................................... 25Multiple Choice Questions. .................................................................................................... 25

4. Running Commands............................................................................................................................ 27Discussion ........................................................................................................................................ 27

Command Line Grammar....................................................................................................... 27Commands.............................................................................................................................. 27Command Line Switches........................................................................................................ 28Arguments .............................................................................................................................. 30Getting Help: Usage ............................................................................................................... 30

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

iii

Page 4: rha030-workbook01-student-3.0-0

Questions.......................................................................................................................................... 33Command Line Syntax ........................................................................................................... 33

5. Managing Terminals............................................................................................................................ 37Discussion ........................................................................................................................................ 37

Controlling Terminals............................................................................................................. 37Resetting Terminals ................................................................................................................ 37Terminal control sequences .................................................................................................... 37Identifying terminals .............................................................................................................. 40Tab Completion ...................................................................................................................... 41

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

Online Exercises............................................................................................................................... 44Online Exercise 1. Suspending terminal output .....................................................................44Online Exercise 2. Sorting your socks.................................................................................... 45

Questions.......................................................................................................................................... 466. Getting Help ......................................................................................................................................... 49

Discussion ........................................................................................................................................ 49Getting Help ........................................................................................................................... 49Obtaining Usages with -h, -?, and --help ............................................................................... 49Man Pages .............................................................................................................................. 50Info Pages ............................................................................................................................... 51The /usr/share/doc Directory .......................................................................................... 52Red Hat Documentation Guides............................................................................................. 53The Linux Documentation Project ......................................................................................... 53yelp: The Gnome Help Browser ............................................................................................. 53

Questions.......................................................................................................................................... 54

rha030-3.0-0-en-2005-08-17T07:23:17-0400Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any other use is a violationof U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwise duplicated whether in electronic or printformat without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, or otherwise improperly distributed please [email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

iv

Page 5: rha030-workbook01-student-3.0-0

Chapter 1. Logging In

Key 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-F1 through CTRL-ALT-F6 key sequences switch between the six virtual consoles.

• The CTRL-ALT-F7 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 SessionsThe 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 themainframe computer with a serial line connection. In order to identify oneself to the Unix operatingsystem, a user would 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.This lesson will describe various ways to start an interactive session with a Linux system.

Virtual ConsolesRed 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-F1 through CTRL-ALT-F6 key sequences, with one virtual console mapped to each of thefirst 6 function keys. (If you are in a graphical environment, you should know that CTRL-ALT-F7 willreturn 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 ES release 4 (Nahant)Kernel 2.6.9-5.EL on an i686

5

Page 6: rha030-workbook01-student-3.0-0

Chapter 1. Logging In

station login:

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

Red Hat Enterprise Linux ES release 4 (Nahant)Kernel 2.6.9-5.EL on an i686

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 going tolearn how to end a session, by typing "exit", and hitting RETURN. The virtual console should return tothe 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 virtualconsoles might be all that are available. Even on modern machines, however, the virtual consoles areoften a much quicker and more efficient interface for experienced users. Because they are implementedby the Linux kernel directly, they are also useful in debugging systems where the graphics might not beworking. Lastly, for network servers that usually spend their lives in locked closets, administrators oftenwant to avoid the complexity that the graphical interface adds to the system.

The X Graphical EnvironmentWhen 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 serverdirectly, 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. Because there are generally 6 virtual consoles used for text terminals, the X serverusually grabs the 7th. If you are on a virtual console, and think that an X server is running on themachine, you can usually switch to it using the CTRL-ALT-F7 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.

rha030-3.0-0-en-2005-08-17T07:23:17-0400

Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any otheruse is a violation of U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwiseduplicated whether in electronic or print format without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, orotherwise improperly distributed please email [email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

6

Page 7: rha030-workbook01-student-3.0-0

Chapter 1. Logging In

Figure 1-1. Red Hat Enterprise Linux Login Manager

Again, a user logs on by typing their username, followed by RETURN, and their password, againfollowed by RETURN.

Terminals in the Graphical environmentThe Applications menu in the graphical environment is found in the upper left-hand corner and serves asyour 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 Terminal".

rha030-3.0-0-en-2005-08-17T07:23:17-0400

Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any otheruse is a violation of U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwiseduplicated whether in electronic or print format without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, orotherwise improperly distributed please email [email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

7

Page 8: rha030-workbook01-student-3.0-0

Chapter 1. Logging In

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 againwhen opening new terminal.

rha030-3.0-0-en-2005-08-17T07:23:17-0400

Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any otheruse is a violation of U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwiseduplicated whether in electronic or print format without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, orotherwise improperly distributed please email [email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

8

Page 9: rha030-workbook01-student-3.0-0

Chapter 1. Logging In

Figure 1-3. gnome-terminal

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

Logging out from the graphical environmentWhen a user is finished with the graphical environment, they can logout selecting the last item from theActions menu, found just to the right of the Applications menu. This will close all open windows, andreturn the graphics environment back to its original login screen, ready for the next user.

rha030-3.0-0-en-2005-08-17T07:23:17-0400

Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any otheruse is a violation of U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwiseduplicated whether in electronic or print format without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, orotherwise improperly distributed please email [email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

9

Page 10: rha030-workbook01-student-3.0-0

Chapter 1. Logging In

Figure 1-4. Logging out of the graphical environment

Using the who command to determine who’s on the system.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 tty1 May 3 07:50blondie :0 May 5 08:48blondie 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, tty1 and tty2 refers to virtual consoles number 1 and 2, respectively. The first entry forblondie, :0, refers to the X server itself, and pts/0 refers to the first terminal opened within the Xserver. Without getting too bogged down in the details, we can see that elvis is logged on the secondvirtual console, root on the first, and blondie has logged in using 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 the

rha030-3.0-0-en-2005-08-17T07:23:17-0400

Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any otheruse is a violation of U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwiseduplicated whether in electronic or print format without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, orotherwise improperly distributed please email [email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

10

Page 11: rha030-workbook01-student-3.0-0

Chapter 1. Logging In

user has an account on the machine, logging in to a remote machine can be as easy as logging in on avirtual console. In the following example, elvis will login to a virtual console on the local machine,called station.redhat.com. He will then use ssh to login to the remote machine nimbus.example.com,potentially halfway 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 userkeep straight what machine the shell is running on.

Red Hat Enterprise Linux ES release 4 (Nahant) (Taroon)Kernel 2.4.21-4.0.1-EL on an i686

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 helogged in 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 anywindows machine, and used to open a shell into a remote Linux server.

Examples

Example 1. Using virtual consolesIn the following example, a user logs on the first 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 second virtualconsole, and log in as the administrative user root and fix the problem. He will then exit, switch back tothe first virtual console, and be on his way.

Red Hat Enterprise Linux ES release 4 (Nahant)Kernel 2.6.9-5.EL on an i686

station login: elvisPassword:Last login: Mon May 5 15:07:16 on tty2

rha030-3.0-0-en-2005-08-17T07:23:17-0400Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any other use isa violation of U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwise duplicated whetherin electronic or print format without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, or otherwise improperly distributedplease email [email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

11

Page 12: rha030-workbook01-student-3.0-0

Chapter 1. Logging In

[elvis@station elvis]$ cat /tmp/READMEcat: /tmp/README: Permission denied[elvis@station elvis]$ whoelvis tty1 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 canfix the problem by switching to another virtual console (using the CTRL-ALT-F2 key sequence),logging in as root, and changing the file’s permissions.

Red Hat Enterprise Linux ES release 4 (Nahant) (Taroon)Kernel 2.4.21-4.0.1-EL on an i686

station login: rootPassword:Last login: Mon May 5 15:54:18 on tty6[root@station root]# whoroot tty2 May 5 15:55elvis tty1 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 first virtual console,and logged on as root on the second. The user now switches back to the first virtual console usingCTRL-ALT-F1, and picks up where he left off.

[elvis@station elvis]$ cat /tmp/README

Kudzu FAQ:----------

1) So, what is kudzu?

kudzu is the hardware autodetection & configuration tool, originallyintroduced in Red Hat Linux 6.1. It detects changes in the system’shardware configuration, and gives the option of configuring...

Online Exercises

Online Exercise 1. Using multiple virtual consoles

Lab ExerciseObjective: Learn to manage multiple virtual consoles

Estimated Time: 10 mins.

rha030-3.0-0-en-2005-08-17T07:23:17-0400

Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any otheruse is a violation of U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwiseduplicated whether in electronic or print format without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, orotherwise improperly distributed please email [email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

12

Page 13: rha030-workbook01-student-3.0-0

Chapter 1. Logging In

SpecificationYour 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 the first four virtual consoles, using each one of your accounts inorder.

Virtual Console Username1 username2 username_a3 username_b4 username_c

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 tty2 May 5 16:18elvis tty1 May 5 16:18elvis_b tty3 May 5 16:18elvis_c tty4 May 5 16:18

Deliverables

1. 4 active login sessions, one on each of the first 4 virtual consoles.

Questions

1. 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 connections and dumbterminals.

( ) 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.

rha030-3.0-0-en-2005-08-17T07:23:17-0400Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any other use is a violationof U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwise duplicated whether in electronic or printformat without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, or otherwise improperly distributed please [email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

13

Page 14: rha030-workbook01-student-3.0-0

Chapter 1. Logging In

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

( ) 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 when higher levelcomponents 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 to maintain.

3. From the first 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 virtual console?

( ) a. ALT-F2( ) b. CTRL-ALT-F2( ) c. Both a and b.

( ) d. None of the above.

5. If a user has logged into the X graphical environment, but desires to use a terminal command line interface, howmight 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 "New 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 remaining beforetheir session expires.

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

rha030-3.0-0-en-2005-08-17T07:23:17-0400Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any other use is aviolation of U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwise duplicated whether inelectronic or print format without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, or otherwise improperly distributedplease email [email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

14

Page 15: rha030-workbook01-student-3.0-0

Chapter 1. Logging In

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.

rha030-3.0-0-en-2005-08-17T07:23:17-0400

Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any otheruse is a violation of U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwiseduplicated whether in electronic or print format without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, orotherwise improperly distributed please email [email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

15

Page 16: rha030-workbook01-student-3.0-0

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 a 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 is aprogram 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 KernelThe 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 tointeract with the computer hardware. The kernel lets programs know when a keyboard key was struck,when the mouse moved, or when a packet destined for the program arrived over the network. The kernelallows programs 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.

16

Page 17: rha030-workbook01-student-3.0-0

Chapter 2. The Kernel, Programs, and Processes

Figure 2-1. The Kernel and Processes

Linux kernel

hardware

processes

bash

httpd

ls

mozilla

ProgramsPrograms are files that are stored on a computer’s harddrive. A program is a series of very basicinstructions, that tell the operating system what to do and when to do it in a very detailed and specificmanner. The following might be the instructions written down in the file /usr/X11R6/bin/xcalc, acommon calculator program.

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

Of course, the instructions are not written in English, or any other human readable language. Instead, acomputer, 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. Programsreally look 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 storeit 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.

rha030-3.0-0-en-2005-08-17T07:23:17-0400

Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any otheruse is a violation of U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwiseduplicated whether in electronic or print format without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, orotherwise improperly distributed please email [email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

17

Page 18: rha030-workbook01-student-3.0-0

Chapter 2. The Kernel, Programs, and Processes

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 of the same program.

Linux, like most modern operating systems, is a multitasking operating system. This means that thekernel gives the appearance of running multiple processes simultaneously. In reality, the kernel isrunning a single process for a brief amount of time, usually on the order of 50 milliseconds. It then swapsthat process out, and swaps in another one for its 50 milliseconds of action. Eventually, the kernel worksits way through all of the processes and starts over again. The rapid switching from process to processgives the users of the 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 torun a simple calendar program called cal. The shell dutifully executes the program, and reports theprogram’s output back to the terminal:

[elvis@station elvis]$ calMay 2003

Su Mo Tu We Th Fr Sa1 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 31

[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 in agraphical 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]$ psPID TTY TIME CMD

rha030-3.0-0-en-2005-08-17T07:23:17-0400Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any other use isa violation of U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwise duplicated whetherin electronic or print format without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, or otherwise improperly distributedplease email [email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

18

Page 19: rha030-workbook01-student-3.0-0

Chapter 2. The Kernel, Programs, and Processes

1378 pts/1 00:00:00 bash1418 pts/1 00:00:00 ps

The first column shows the process’s PID, or Process ID. Every process running on the system isidentified by a unique PID. The second column identifies elvis’s terminal, and the third column reportshow much CPU 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 bememorized. Neither will we give a detailed discussion of all of the following fields. All of this will beaddressed in a following Workbook. Simply realize that at any given moment, there are usually a largenumber of processes running on a Linux system. (Note that in the following output, many lines havebeen removed and replaced with "...").

[elvis@station elvis]$ ps auxUSER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMANDroot 1 0.0 0.1 1388 460 ? S 18:52 0:04 init [root 2 0.0 0.0 0 0 ? SW 18:52 0:00 [keventd]...root 548 0.0 0.2 1460 580 ? S 18:53 0:00 syslogd -m 0root 552 0.0 0.1 1384 428 ? S 18:53 0:00 klogd -xrpc 570 0.0 0.2 1560 552 ? S 18:53 0:00 portmaproot 622 0.0 0.2 1496 632 ? S 18:53 0:00 /sbin/cardmgrroot 628 0.0 0.0 0 0 ? SW 18:53 0:00 [kapmd]root 633 0.0 0.1 1380 484 ? S 18:53 0:00 /usr/sbin/apmd -proot 644 0.0 0.5 3524 1512 ? S 18:53 0:00 /usr/sbin/sshdroot 655 0.0 0.3 2040 860 ? S 18:53 0:00 xinetd -stayaliveroot 674 0.0 0.9 6204 2504 ? S 18:53 0:00 sendmail: acceptismmsp 683 0.0 0.8 6004 2256 ? S 18:53 0:00 sendmail: Queue rroot 693 0.0 0.1 1424 444 ? S 18:53 0:00 gpm -t ps/2 -m /droot 702 0.0 0.2 1580 672 ? S 18:53 0:00 crondxfs 781 0.0 1.5 5272 4004 ? S 18:53 0:00 xfs -droppriv -daroot 800 0.0 0.2 3416 544 ? S 18:53 0:00 rhnsd --intervalroot 807 0.0 0.1 1364 396 tty1 S 18:53 0:00 /sbin/mingetty tt...root 1375 0.0 0.3 4120 968 pts/1 S 20:11 0:00 su - elviselvis 1378 0.0 0.5 4324 1404 pts/1 S 20:11 0:00 -bashelvis 1438 0.0 0.2 2648 696 pts/1 R 20:30 0:00 ps aux

Questions

The kernel, programs, and processes

1. Which of the following is not considered an operating system?

( ) a. Red Hat Enterprise Linux

( ) b. Windows 2000

rha030-3.0-0-en-2005-08-17T07:23:17-0400Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any other use is aviolation of U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwise duplicated whether inelectronic or print format without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, or otherwise improperly distributedplease email [email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

19

Page 20: rha030-workbook01-student-3.0-0

Chapter 2. The Kernel, Programs, and Processes

( ) 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.

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

rha030-3.0-0-en-2005-08-17T07:23:17-0400

Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any otheruse is a violation of U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwiseduplicated whether in electronic or print format without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, orotherwise improperly distributed please email [email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

20

Page 21: rha030-workbook01-student-3.0-0

Chapter 3. Examining the Filesystem

Key Concepts• The base of the Linux directory tree is a directory called /, 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 in theroot 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 asdirname/filename, again without the leading slash. For example, if a process’s current workingdirectory were /etc, the network file referred to above could be referred to as sysconfig/network.If the working directory 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 directoryalways start with a leading /, and are called absolute references. File references relative to the currentworking directory start with something other than a /, and are referred to as relative references.

21

Page 22: rha030-workbook01-student-3.0-0

Chapter 3. Examining the Filesystem

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.

[elvis@station elvis]$ ls /etc/sysconfig/rhnrhn-applet systemid up2date-keyring.gpg up2date-uuidrhnsd up2date up2date.rpmnew

The ls command, when called without arguments (i.e., without specifying a directory), lists the contentsof the shell’s current working directory. If using a color terminal, the ls command also colorizes thefilenames to help distinguish which of the directory contents are regular files (white), and which aredirectories (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 of thefiles. 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 localhost192.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 theentire contents 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 >character to redirect standard out into a file.

rha030-3.0-0-en-2005-08-17T07:23:17-0400

Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any other use isa violation of U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwise duplicated whetherin electronic or print format without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, or otherwise improperly distributedplease email [email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

22

Page 23: rha030-workbook01-student-3.0-0

Chapter 3. Examining the Filesystem

In the following example, the user elvis is again going to list the contents of the /etc/sysconfig/rhndirectory, 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.txtrhn-appletrhnsdsystemidup2dateup2date-keyring.gpgup2date.rpmnewup2date-uuid

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 sees thenewly 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 into the file lsout.txt".

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 Linux 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 files inthe /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

Example 1. 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.

rha030-3.0-0-en-2005-08-17T07:23:17-0400Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any other use isa violation of U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwise duplicated whetherin electronic or print format without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, or otherwise improperly distributedplease email [email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

23

Page 24: rha030-workbook01-student-3.0-0

Chapter 3. Examining the Filesystem

[prince@station prince]$ cal Ê

May 2003Su Mo Tu We Th Fr Sa

1 2 34 5 6 7 8 9 10

11 12 13 14 15 16 1718 19 20 21 22 23 2425 26 27 28 29 30 31

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

[prince@station prince]$ ls Ì

calendar.txt[prince@station prince]$ cat calendar.txt Í

May 2003Su Mo Tu We Th Fr Sa

1 2 34 5 6 7 8 9 10

11 12 13 14 15 16 1718 19 20 21 22 23 2425 26 27 28 29 30 31

Ê prince first views the output of the cal command directly.

Ë prince runs the cal command again, redirecting the output to the file calendar.txt

Ì prince 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.

Online Exercises

Online Exercise 1. The ls Command

Lab ExerciseObjective: Redirect command output into a newly created file.Estimated Time: 5 mins.

SpecificationUse 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.

rha030-3.0-0-en-2005-08-17T07:23:17-0400Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any otheruse is a violation of U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwiseduplicated whether in electronic or print format without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, orotherwise improperly distributed please email [email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

24

Page 25: rha030-workbook01-student-3.0-0

Chapter 3. Examining the Filesystem

Deliverables

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

Possible SolutionThe 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 the following would refer tothe file received, which is in the directory Mail, which is in the home directory?

( ) 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?

( ) a. cat /usr/lib

( ) b. lsdir /usr/lib

( ) c. /usr/lib list

rha030-3.0-0-en-2005-08-17T07:23:17-0400Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any other use is a violationof U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwise duplicated whether in electronic or printformat without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, or otherwise improperly distributed please [email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

25

Page 26: rha030-workbook01-student-3.0-0

Chapter 3. Examining the Filesystem

( ) d. ls /usr/lib

4. Which of the following commands would successfully redirect the output of the cal to the file lsout.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 commands would succeed ona 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

rha030-3.0-0-en-2005-08-17T07:23:17-0400

Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any otheruse is a violation of U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwiseduplicated whether in electronic or print format without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, orotherwise improperly distributed please email [email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

26

Page 27: rha030-workbook01-student-3.0-0

Chapter 4. Running Commands

Key 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 ofhow to 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 knowwhich file contains these programs, there is a program called which which can help us. The whichcommand, 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

27

Page 28: rha030-workbook01-student-3.0-0

Chapter 4. Running Commands

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

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 tmp4 dict 8 include 4 libexec 8 share 4 X11R64 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, whichincludes the -s command line switch, gives the sizes of the contents as well. The third ls -l commandgives a "long" listing, including all kinds of details about the files, such as ownerships, permissions, andmodify times. For now, don’t worry about all of the detailed output. This will be covered in an upcomingworkbook on using the filesystem. Just note how command line switches are used to modify the basicbehavior of the ls command.

Short Command Line SwitchesNotice 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. Forexample, the ls command has a -w command line switch, which specifies how "wide" the output shouldbe, in characters. Consider the following example.

rha030-3.0-0-en-2005-08-17T07:23:17-0400Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any other use isa violation of U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwise duplicated whetherin electronic or print format without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, or otherwise improperly distributedplease email [email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

28

Page 29: rha030-workbook01-student-3.0-0

Chapter 4. Running Commands

[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 switchestake arguments and which don’t? The short answer is through experience, but we will soon mention waysto find help as well.

Multiple Short Command Line SwitchesMore than one command line switch can be used at a time. The multiple command line switches aresimply bunched together, squeezed between the command and any command arguments. The followingexample introduces a new -r switch for the ls command, which reverses the sorting order. Note how it isused along with the -s and -w switches.

[elvis@station elvis]$ ls -s -w 40 -r /usr/total 132

4 X11R6 0 local 4 games0 tmp 4 libexec 4 etc4 src 40 lib 4 dict8 share 4 kerberos 40 bin8 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 games0 tmp 4 libexec 4 etc4 src 40 lib 4 dict8 share 4 kerberos 40 bin8 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 itcomes last. That way, its argument can be specified next on the command line.

Long Command Line SwitchesIn 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/

rha030-3.0-0-en-2005-08-17T07:23:17-0400Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any other use isa violation of U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwise duplicated whetherin electronic or print format without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, or otherwise improperly distributedplease email [email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

29

Page 30: rha030-workbook01-student-3.0-0

Chapter 4. Running Commands

total 13240 bin 4 games 40 lib 8 sbin 0 tmp4 dict 8 include 4 libexec 8 share 4 X11R64 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 games0 tmp 4 libexec 4 etc4 src 40 lib 4 dict8 share 4 kerberos 40 bin8 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 thecommand. 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 belisted. The ps command expects no arguments. The cal command takes from zero to two, a possiblemonth and a possible year to generate the calendar for. Learning what arguments a program expects, andwhat it does with its arguments, is part of learning how to use that command.

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

[elvis@station elvis]$ ls --helpUsage: 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

rha030-3.0-0-en-2005-08-17T07:23:17-0400Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any other use isa violation of U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwise duplicated whetherin electronic or print format without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, or otherwise improperly distributedplease email [email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

30

Page 31: rha030-workbook01-student-3.0-0

Chapter 4. Running Commands

...

-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

Example 1. 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 --helpUsage: 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

rha030-3.0-0-en-2005-08-17T07:23:17-0400Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any other use isa violation of U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwise duplicated whetherin electronic or print format without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, or otherwise improperly distributedplease email [email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

31

Page 32: rha030-workbook01-student-3.0-0

Chapter 4. Running Commands

-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 andstandard output, but she can understand enough of the first line to understand that the cat commandexpects filenames 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 lineswitch numbers the output lines. She tries out this switch.

[madonna@station madonna]$ cat -n /etc/anacrontab1 # /etc/anacrontab: configuration file for anacron23 # See anacron(8) and anacrontab(5) for details.45 SHELL=/bin/sh6 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin78 1 65 cron.daily run-parts /etc/cron.daily9 7 70 cron.weekly run-parts /etc/cron.weekly10 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.

rha030-3.0-0-en-2005-08-17T07:23:17-0400Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any other use isa violation of U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwise duplicated whetherin electronic or print format without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, or otherwise improperly distributedplease email [email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

32

Page 33: rha030-workbook01-student-3.0-0

Chapter 4. Running Commands

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.weekly30^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 Syntax

The 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...

rha030-3.0-0-en-2005-08-17T07:23:17-0400Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any other use isa violation of U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwise duplicated whetherin electronic or print format without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, or otherwise improperly distributedplease email [email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

33

Page 34: rha030-workbook01-student-3.0-0

Chapter 4. Running Commands

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-B SEC, --backward=SEC date back SEC seconds-c, --no-create do not create any files-d, --date=STRING parse STRING and use it instead of current time-F SEC, --forward=SEC date forward SEC seconds-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

[madonna@station madonna]$ touch -r /etc/servicestouch: file arguments missingTry ‘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 running touch -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.

rha030-3.0-0-en-2005-08-17T07:23:17-0400Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any other use is a violationof U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwise duplicated whether in electronic or printformat without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, or otherwise improperly distributed please [email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

34

Page 35: rha030-workbook01-student-3.0-0

Chapter 4. Running Commands

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

4. Which best describes why madonna got the "command not found" error message when running tooch/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.

6. When madonna ran the command touch -r /etc/services /tmp/foo, what best describes the role of the 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 describes what happens?

( ) a. The shell asks the kernel to execute the contents of the file /usr/bin/who as a separate process,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, it replaces itselfwith a new shell process.

8. When long command line switches were introduced, which best describes why they were preceded with a doublehyphen (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 ofa 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.

rha030-3.0-0-en-2005-08-17T07:23:17-0400Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any otheruse is a violation of U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwiseduplicated whether in electronic or print format without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, orotherwise improperly distributed please email [email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

35

Page 36: rha030-workbook01-student-3.0-0

Chapter 4. Running Commands

Notes1. Exceptions to this rule include shell internals, shell aliases, and shell functions, which will be

handled in the bash shell workbook.

rha030-3.0-0-en-2005-08-17T07:23:17-0400Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any otheruse is a violation of U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwiseduplicated whether in electronic or print format without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, orotherwise improperly distributed please email [email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

36

Page 37: rha030-workbook01-student-3.0-0

Chapter 5. Managing Terminals

Key Concepts• Various control sequences, such as CTRL-C, CTRL-D, and CTRL-Z, can be helpful for managing

processes 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.

Discussion

Controlling TerminalsThe 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. Thislesson introduces some features shared by terminals in general, and one feature of the bash shell that istoo useful to delay until later, tab completion.

Resetting TerminalsWhen terminals display information, they 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 usedfor text characters and punctuation. The others are used to encode control sequences (see below) andother special conditions.

Sometimes, users accidentally (or intentionally) ask a terminal to display data that is not encoded asASCII text, such as an image or an executable. The terminal does the best job it can, but often displayswhat appears to be random garbage. Even worse, the terminal can end up in an alternate graphics mode,so that even what should be normal ASCII text looks unreadable.

In these situations, the reset command can restore the terminal to sane behavior. Usually, when you’dlike to use this command, you won’t even be able to see yourself type it. However, if at an unreadablebash prompt, blindly typing reset and followed by the RETURN key will usually restore the terminal tosane behavior.

37

Page 38: rha030-workbook01-student-3.0-0

Chapter 5. Managing Terminals

Terminal control sequencesLinux terminals share a lot in common with their primitive ancestors, teletypes and "dumb" or vt100-likeconsoles. 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 tosend these "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.

Table 5-1. Linux Terminal Control Sequences

Key Combination Symbolic Name Conventional UseCTRL-C SIGINT Abnormal Interrupt - terminate

the foreground processCTRL-D EOT Normal signaling of the end of

inputCTRL-G BEL Sound an audible terminal bellCTRL-H BS Backspace - erase the previous

characterCTRL-J LF Line feed - alternative for the

RETURN keyCTRL-L FF Form feed - causes bash to clear

screen, and other screen basedprograms to "refresh" the currentscreen.

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

CTRL-S Freeze the terminal display(thaw with CTRL-Q)

CTRL-U NAK Erase current lineCTRL-Z SIGSTOP Suspend the foreground process

CTRL-CCTRL-C is probably the most useful of the above sequences, coming to the rescue whenever a useris feeling "JUST MAKE IT STOP!" When using the bash shell, typing CTRL-C will terminate thecurrently running process, and return you to the bash prompt.

The /dev/zero device node is a pseudo device that, when read, returns an infinite number of(binary) zeros. The /dev/null device node is a pseudo device that throws away any informationwritten to it. The following command, therefore, would run forever, reading zeros and throwingthem away. Someone stuck in this situation could use CTRL-C to cancel the command.[elvis@station elvis]$ cat /dev/zero > /dev/null

rha030-3.0-0-en-2005-08-17T07:23:17-0400Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any otheruse is a violation of U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwise dupli-cated whether in electronic or print format without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, or oth-erwise improperly distributed please email [email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

38

Page 39: rha030-workbook01-student-3.0-0

Chapter 5. Managing Terminals

(... user types CTRL-C ...)[elvis@station elvis]$

CTRL-DAs will be discovered in a later Workbook, many Unix commands read their input directly from thekeyboard. Unfortunately for new Unix users, its not always obvious how to tell the command whento stop listening. The answer is CTRL-D. This control sequence is used to send an "End ofTransmission" (usually interpreted as "End of File") to the listening process.

The wc command is an example of a command that, when not given a filename as an argument, willcount the number of lines, words, and characters that a user types in from the keyboard. The usersignals 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 ...)

3 12 66[elvis@station elvis]$

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

CTRL-ZCTRL-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 determine his shell’s currentworking directory. He suspends the ftp session with CTRL-Z, runs the pwd command from theshell, 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 pub

rha030-3.0-0-en-2005-08-17T07:23:17-0400Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any otheruse is a violation of U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwise dupli-cated whether in electronic or print format without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, or oth-erwise improperly distributed please email [email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

39

Page 40: rha030-workbook01-student-3.0-0

Chapter 5. Managing Terminals

226 Directory send OK....

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

CTRL-UCTRL-U is commonly used to "wipe" the current line. If you have so mangled a bash commandline that you just want to start over, type CTRL-U. Also, CTRL-U is very helpful when you messup while entering a password. Because your characters are usually not echoed back to you, its oftenhard to know what you’ve type. Just type CTRL-U and start over.

CTRL-HCTRL-H serves the exact same role as the BACKSPACE key. On some terminals, however, theBACKSPACE key is incorrectly mapped, and doesn’t function correctly. CTRL-H will almostalways work in these situations.

CTRL-LCTRL-L was traditionally used to tell a line printer to eject the current page and start on the nextone. For online terminals, it has been repurposed for redrawing screens. For many screen basedprograms, including the vi and nano editors, if the screen ever becomes mangled because ofunexpected messages, a CTRL-L will cause the program to refresh the screen, redrawing itcorrectly.

For the bash shell, CTRL-L causes bash to clear the screen, but preserve the current command line.

CTRL-QCTRL-Q "thaws" a screen (causing it to become active again) after it has been "frozen" with aCTRL-S. Although it is only useful after a CTRL-S has been used, it is introduced first (as themore useful command) because almost no one intentionally uses CTRL-S. Instead, new Unix userswill sometimes accidentally type a CTRL-S, and not understand why their terminal has goneunresponsive. If your terminal ever seems dead, try typing a CTRL-Q and see if that fixes it.

CTRL-SSee CTRL-Q above.

CTRL-JAlmost never used. (People use the RETURN key instead.)

CTRL-GThe only real use is to make the terminal beep, impressing your friends with your vast reservoirs ofuseless Unix knowledge.

Identifying terminalsAs 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 device

rha030-3.0-0-en-2005-08-17T07:23:17-0400

Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any otheruse is a violation of U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwiseduplicated whether in electronic or print format without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, orotherwise improperly distributed please email [email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

40

Page 41: rha030-workbook01-student-3.0-0

Chapter 5. Managing Terminals

node /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 inthese situations, 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 :0 Jun 21 10:13blondie 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 CMD4384 tty3 00:00:00 bash4427 tty3 00:00:00 ps

Many different devices are treated by Linux as a terminal, including virtual consoles, serial lineconnected VT100 terminals, modems, etc. The following table lists some of the common terminal namesthat are conventionally used for some common terminal devices.

Table 5-2. Terminal Device Names

Name Device How usedttyn 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 windowsin the X graphical environment, or shells which originateover the network, such as with telnet or ssh.Pseudo-terminals cannot be related directly to a physicaldevice.

:0 X server The X server is not really a terminal. When a user logs inusing the Login Manager in the X graphical environment,their terminal is often listed as the X server itself.

Tab CompletionTab completion is not a feature of terminals, but of the bash shell that is usually run within them. Whentyping the names of commands and files, a lot of time and effort can be saved by learning how to makegood use of the TAB key.

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

rha030-3.0-0-en-2005-08-17T07:23:17-0400Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any otheruse is a violation of U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwiseduplicated whether in electronic or print format without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, orotherwise improperly distributed please email [email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

41

Page 42: rha030-workbook01-student-3.0-0

Chapter 5. Managing Terminals

One of three 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 havesome choices to make. In order to see the selection of commands that bash has narrowed it down to, hitthe TAB key a second time. bash will list all commands that start with what you have typed. Supplyenough of the remainder of the command to make it unique, and hit TAB again. bash will finish thecommand 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 calledunicode_start, and the command that disables it is called unicode_stop. He begins typing the command,and hits the TAB 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

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/prelink.conf. Rather than typing out the entire file name, she could type thefirst part, and hit TAB.

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

Because /etc/prelink.conf is the only file that starts out /etc/prel, bash is able to complete thefile.

rha030-3.0-0-en-2005-08-17T07:23:17-0400Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any other use isa violation of U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwise duplicated whetherin electronic or print format without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, or otherwise improperly distributedplease email [email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

42

Page 43: rha030-workbook01-student-3.0-0

Chapter 5. Managing Terminals

[madonna@station madonna]$ cat /etc/prelink.conf# This config file contains a list of directories both with binaries# and libraries prelink should consider by default.# If a directory name is prefixed with ‘-l ’, the directory hierarchy# will be walked as long as filesystem boundaries are not crossed.# If a directory name is prefixed with ‘-h ’, symbolic links in a# directory hierarchy are followed.-l /bin-l /usr/bin...

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

Example 1. 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 to asane condition.

[blondie@station blondie]$

Example 2. 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_start

rha030-3.0-0-en-2005-08-17T07:23:17-0400Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any other use isa violation of U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwise duplicated whetherin electronic or print format without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, or otherwise improperly distributedplease email [email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

43

Page 44: rha030-workbook01-student-3.0-0

Chapter 5. Managing Terminals

basename 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]$

Online Exercises

Online Exercise 1. Suspending terminal output

Lab ExerciseObjective: 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 freezeand thaw 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. A stopped (suspended) ls -R / command.

rha030-3.0-0-en-2005-08-17T07:23:17-0400Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any otheruse is a violation of U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwiseduplicated whether in electronic or print format without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, orotherwise improperly distributed please email [email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

44

Page 45: rha030-workbook01-student-3.0-0

Chapter 5. Managing Terminals

Cleaning UpAfter you have finished confirming your deliverable, restore the suspended process to the foregroundwith the fg command. Now cancel it with the CTRL-C control sequence.

Online Exercise 2. Sorting your socks.

Lab ExerciseObjective:Learn how to usefully terminate input for a command reading from thekeyboard.Estimated Time: 5 mins.

SpecificationYou 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.

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. 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.

rha030-3.0-0-en-2005-08-17T07:23:17-0400

Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any otheruse is a violation of U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwiseduplicated whether in electronic or print format without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, orotherwise improperly distributed please email [email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

45

Page 46: rha030-workbook01-student-3.0-0

Chapter 5. Managing Terminals

Questions

1. 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 might restore activity?

( ) a. CTRL-C( ) b. CTRL-D( ) c. CTRL-Q( ) d. CTRL-U( ) e. CTRL-Z

4. If you suspect that you have mistyped while entering a password, which control sequence would allow you to startover?

( ) a. CTRL-C( ) b. CTRL-D( ) c. CTRL-Q( ) d. CTRL-U( ) e. CTRL-Z

rha030-3.0-0-en-2005-08-17T07:23:17-0400Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any other use is a violationof U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwise duplicated whether in electronic or printformat without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, or otherwise improperly distributed please [email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

46

Page 47: rha030-workbook01-student-3.0-0

Chapter 5. Managing Terminals

5. If you want to cancel a command that is generating too much output, which control sequence would be mosthelpful?

( ) 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 sequence would be mosthelpful?

( ) 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 tty1 Apr 21 22:07elvis tty3 Apr 21 22:07root tty6 Apr 21 22:07prince :0 Apr 21 21:50prince 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)

rha030-3.0-0-en-2005-08-17T07:23:17-0400Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any other use is a violationof U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwise duplicated whether in electronic or printformat without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, or otherwise improperly distributed please [email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

47

Page 48: rha030-workbook01-student-3.0-0

Chapter 5. Managing Terminals

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.

rha030-3.0-0-en-2005-08-17T07:23:17-0400

Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any otheruse is a violation of U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwiseduplicated whether in electronic or print format without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, orotherwise improperly distributed please email [email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

48

Page 49: rha030-workbook01-student-3.0-0

Chapter 6. Getting Help

Key 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 theman command.

• 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 formost commands 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 commandoptions. This is particularly true of the more commonly used commands, such as mv, ps, and vi. Thischoice makes Unix 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 how toquickly 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 the

49

Page 50: rha030-workbook01-student-3.0-0

Chapter 6. Getting Help

command 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 informationof Unix systems. A documentation page for most commands, file formats, programming calls, andgeneral topics can be viewed using the man command. For example, man ls generates documentationfor the ls command.

The less PagerRed 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 Actionspace View next pageb View previous pageq Quit/ text RETURN Search for word text

n Find next occurrence of previously used searchterm

Man ChaptersMan 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,found in chapter one on user commands, but also the /etc/passwd file, found in chapter five on fileformats. Unfortunately for the user trying to find documentation on the /etc/passwd file format, manpasswd only displays the first page it finds, in this case the entry from chapter one. In order to view theman page from chapter five, the chapter must be explicitly specified, as in man 5 passwd.

Table 6-2. Man Chapters

Chapter Audience Topic1 standard users Commands2 developers System Calls3 developers Library Calls4 administrators Device Files

rha030-3.0-0-en-2005-08-17T07:23:17-0400Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any other use is a violation

of U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwise duplicated whether in electronic or print

format without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, or otherwise improperly distributed please email

[email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

50

Page 51: rha030-workbook01-student-3.0-0

Chapter 6. Getting Help

Chapter Audience Topic5 standard users File Formats6 standard users ??? (see questions)7 standard users General Information8 administrators Administrator Commands

In Unix, references to man pages customarily include the chapter number in parentheses after the nameof the page, such as passwd(1) or passwd(5). Each chapter contains an introductory page called intro, sothe command 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 onthe format for the /etc/passwd file. She has already discovered that man passwd only produces theman page for the passwd command, so she uses man -k to perform a keyword search on the wordpasswd.

[madonna@station madonna]$ man -k passwd...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.

rha030-3.0-0-en-2005-08-17T07:23:17-0400

Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any otheruse is a violation of U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwiseduplicated whether in electronic or print format without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, orotherwise improperly distributed please email [email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

51

Page 52: rha030-workbook01-student-3.0-0

Chapter 6. Getting Help

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 ActionSPACE Next pageb Previous pageq Quit/text RETURN Search for word text

RIGHT ARROW Follow LinkLEFT ARROW BackUP ARROW Previous LinkDOWN 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 welldocumented. By allowing users to use software early, they can help influence the ongoing design of thesoftware for the better.

Red Hat Enteprise 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 to usenewly developed products might be a simple text file called README hastily thrown together by thedeveloper. Red Hat Enteprise 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 PostScript viewer ggv is rather skimpy,consisting primarily of the developers’ unstructured ChangeLog. Hopefully, no NEWS is good news.

[elvis@station elvis]$ ls -s /usr/share/doc/ggv-1.99.97/total 144120 ChangeLog 20 COPYING 0 NEWS 4 TODO

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.

rha030-3.0-0-en-2005-08-17T07:23:17-0400Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any other use isa violation of U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwise duplicated whetherin electronic or print format without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, or otherwise improperly distributedplease email [email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

52

Page 53: rha030-workbook01-student-3.0-0

Chapter 6. Getting Help

[elvis@station elvis]$ ls /usr/share/doc/samba-2.2.7a/autofs LDAP misc README RoadmapCOPYING libsmbclient printer-accounting README.vfs-recycle WHATSNEW.txtdocs Manifest printing recycle.conf

Red Hat Documentation GuidesRed Hat Enterprise Linux includes documentation manuals, developed as a service provided by Red Hat,Inc. The following documentation manuals are available online (https://www.redhat.com/docs/manuals/),on the documentation CD in RPM format, or in the boxed set as printed books.

• x86 Installation Guide

• Getting Started Guide

• Customization Guide

• Reference Guide

• Security Guide

• System Administration Primer

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 thissite follows 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 particular facet ofLinux, such as the CD-Writing-HOWTO, or the ETHERNET-HOWTO.

GUIDES

Guides provide more in depth coverage of broad topics, such as System Administration, or evenLinux Kernel Module Programming.

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

rha030-3.0-0-en-2005-08-17T07:23:17-0400

Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any otheruse is a violation of U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwiseduplicated whether in electronic or print format without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, orotherwise improperly distributed please email [email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

53

Page 54: rha030-workbook01-student-3.0-0

Chapter 6. Getting Help

yelp: The Gnome Help BrowserLastly, we introduce yelp, the GNOME Help Browser, which can be started by choosing "Help" from theApplications menu. yelp provides the primary documentation for many GNOME specific graphicalapplications, including the Nautilus File Manager and GNOME applets.

Figure 6-1. yelp: The GNOME Help Browser

Questions

1. 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

rha030-3.0-0-en-2005-08-17T07:23:17-0400Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any other use is a violationof U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwise duplicated whether in electronic or printformat without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, or otherwise improperly distributed please [email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

54

Page 55: rha030-workbook01-student-3.0-0

Chapter 6. Getting Help

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

( ) 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 type of file that theyimply?

( ) a. 1

( ) b. 4

( ) c. 5

( ) d. 7

( ) e. 8

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

( ) a. Unix history

( ) b. hardware devices

( ) c. networking protocols

( ) d. graphical applications

( ) e. games

rha030-3.0-0-en-2005-08-17T07:23:17-0400Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any other use is a violationof U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwise duplicated whether in electronic or printformat without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, or otherwise improperly distributed please [email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

55

Page 56: rha030-workbook01-student-3.0-0

Chapter 6. Getting Help

7. Which of the following commands would generate a keyword search of the man pages for the word 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. If Red Hat Enterprise Linux documentation guides are not installed on your system, where can the documentationbe found?

( ) a. On a Red Hat Enterprise Linux documentation CD

( ) b. At the www.redhat.com website

( ) c. In printed guides shipped with the boxed distribution.

( ) d. A and C

( ) e. All of the above

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

( ) a. documentation for GNOME graphical applications

( ) b. man pages

( ) c. info pages

( ) d. A and C

( ) e. All of the above

rha030-3.0-0-en-2005-08-17T07:23:17-0400

Copyright (c) 2003-2005 Red Hat, Inc. All rights reserved. For use only by a student enrolled in a Red Hat Academy course taught at a Red Hat Academy. Any otheruse is a violation of U.S. and international copyrights. No part of this publication may be photocopied, duplicated, stored in a retrieval system, or otherwiseduplicated whether in electronic or print format without prior written consent of Red Hat, Inc. If you believe Red Hat course materials are being used, copied, orotherwise improperly distributed please email [email protected] or phone toll-free (USA) +1 866 626 2994 or +1 (919) 754 3700.

56