Chapter 4. Issuing Linux Commands

This chapter shows you how to begin using your Linux system. It shows you how to boot your system, log in, issue commands, log out, and shut down your system. It also explains how to use the man command, which provides help on using other commands. The chapter describes how Linux organizes data as filesystems, directories, and files and how you can work with removable media, such as diskettes. It describes how to query the status of your system. And, finally, it explains how to use pico, a simple text editor.

The System Use Cycle

This section introduces you to the cycle of Linux system use. If you’re a user of Microsoft Windows, you’re accustomed to a pattern of system use that forms a cycle:

  • Boot the system

  • Identify yourself to the system

  • Use the system

  • Shutdown the system

The cycle of Linux system use is similar, even though you perform the tasks somewhat differently.

Booting the System

Most Linux users boot their system from its hard drive. Of course, if you made a boot diskette during system installation, you can use it to boot your system.

First, you must prepare your system for booting. If your system is running, you must shut it down by following the proper procedure for shutting down the operating system that’s active. For example, if you’re running Microsoft Windows, click Start Shut Down and select the Shut Down option in the Shut Down dialog box. Press OK to begin the system shutdown. After a few seconds, Windows displays a screen telling you that it’s safe to turn off power to your system. Turn off the power or, if your system automatically powers down, wait a few seconds until the system powers itself down.

Next, you must set your system to boot from the desired device. To boot your system from its hard drive, remove any floppy diskette from your system’s floppy drive. To boot your system from a floppy diskette, insert your Linux boot diskette into your system’s floppy drive.

Now, you’re ready to boot your system. Switch your system on (or press your system’s reset button, if your system is powered on) and watch as it performs its self test. Shortly thereafter, you should see a boot: prompt on the system’s monitor. If you like, you can list the available boot configurations stored on the boot device by pressing Tab. To boot the system, type the name of the desired configuration and press Enter, or simply press Enter to boot using the default configuration.

Once it loads, Linux begins probing your system and its devices, printing status information on your system’s monitor. This status information is helpful if your system fails to boot properly, because it discloses the point in the boot process where the problem occurred.

When Linux has completed its boot process, your system’s monitor will display a login prompt similar to this:

Red Hat Linux release 6.0 (Hedwig)
Kernel 2.2.5 on an i586
login:

Logging In

Before you can use the system, you must identify yourself by logging in. The install program created a special user named root; by identifying yourself as the root user, you can gain access to the system. Normally, you use the root userid only when performing system administration tasks, because the root user has special capabilities that other users lack. However, because root is currently the only userid that has access to your system, you must log in as root. Later, you’ll add one or more userids.

To log on, type root and press Enter. The system prompts you for the password associated with the root userid. Type the password you established during the installation process and press Enter. To prevent anyone nearby from learning your password, Linux does not display it as you type. If you suspect you’ve typed it incorrectly, simply press Enter and start over; or press Backspace once (or more) for each character you’ve entered and then re-enter it. If you type the userid or password incorrectly, Linux displays the message “login incorrect” and prompts you to try again.

Tip

Like other members of the Unix family, the Linux operating system is case sensitive. Be sure to type the userid root just as it appears, using all lowercase characters. Similarly, you must type the password in exactly the same way you entered it in the Root Password dialog box during system installation.

When you’ve successfully logged in, you’ll see a command prompt that looks something like this:

[root@desktop /root]#

This prompt tells you that the Linux bash shell is ready to accept your commands.

Issuing Commands

The component of Linux that interprets and executes commands is called the shell. Linux supports a variety of different shells, but the most popular is the bash shell. This chapter presents the basics of using the bash shell; you’ll learn more about the shell in Chapter 13.

The Linux bash shell presents the user with a command-line interface (CLI). CLIs are familiar to Windows users who have worked in the MS-DOS window, and indeed the Microsoft Windows MS-DOS Prompt window is a kind of command-line shell for Windows. The Linux bash shell works much like the MS-DOS Prompt window. You type text commands and the system responds by displaying text replies. As your first Linux command, type w and press Enter. Your screen should look something like this:

[root@desktop /root]# w
11:12am  up 6 min,  1 user,  load average: 0.00, 0.08, 0.05
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU  WHAT
root     tty1                      11:13am  0.00s  0.20s  0.11s  -bash

The w command tells Linux to display the system status and a list of all system users. In the example, the output of the command tells you that it’s now 11:12 a.m., that the system has been up for 6 minutes, and that only one user—root—is currently logged in. Notice that the command output is very terse, packing much information into a few lines. Such output is typical of Linux commands. At first, you may find Linux output cryptic and difficult to read, but over time you’ll grow to appreciate the efficiency with which Linux communicates information.

Linux provides many commands besides the w command; so many that you may despair of learning and recalling them. Actually, the number of commands you’ll use regularly is fairly small. Soon, these will become second nature to you.

Now try a second command, the date command:

[root@desktop /root]# date
Tue Feb 23 11:15:20 PST 1999

The date command displays the current date and time.

Tip

If you find working with MS-DOS distasteful or intimidating, you may not immediately enjoy working with the Linux command line. However, give yourself some time to adjust. The Linux command line has several features that make it easier to use, and more powerful, than MS-DOS. If, after working with the Linux command line for several days, you don’t find yourself at home, don’t despair. Linux provides a graphical user interface in addition to its command-line interface. You’ll learn about the graphical user interface in Chapter 6.

Correcting Commands

Sometimes you may type a command incorrectly, causing Linux to display an error message. For example, suppose you typed dat instead of date:

[root@desktop /root]# dat
bash: dat: command not found

In such a case, carefully check the spelling of the command and try again. If you notice an error before pressing Enter, you can use the Backspace key to return to the point of the error and then type the correct characters.

Just as a web browser keeps track of recently visited sites, Linux’s BASH shell keeps track of recently issued commands. This list is called the history list, and you can scroll back through it using the Up arrow key, or back down using the Down arrow key, just as you would with the Back and Forward buttons on a web browser. In fact, the history list provides several powerful ways to remember and reuse frequently issued commands, as we’ll see in Chapter 13.

The Up and Down arrow keys let you scroll through a list of commands recently issued. This feature is handy when you want to repeat a command. Simply use the Up arrow key to find the command and press Enter to re-execute it. You can also use this feature when you want to issue a command similar to one you recently issued. Use the Up arrow key to find the original command. Then, use the Left and Right arrow keys to position the cursor and make whatever changes to the command you like. Finally, press Enter to execute the command.

Using Virtual Consoles

In Microsoft Windows, you can have several MS-DOS Prompt windows simultaneously active. Although the bash shell doesn’t have a graphical user interface, you can nevertheless work with several instances of the shell, by using Linux virtual consoles. Linux provides six virtual consoles; you can use special keystrokes to switch between them. The keystroke Alt-F n, where n is the number of a virtual console (1-6), causes Linux to display virtual console n. For example, you can display virtual console 2 by typing Alt-F2. You can view only a single console at a time, but you can switch rapidly between consoles by using the appropriate keystroke.

Virtual consoles are handy when you’ve started a time-consuming task and want to be able to perform an unrelated task while the original task is working. You’ll also find them useful after you’ve established several userids on your system, because you can log on as one userid on one virtual console while you’re logged on as another userid on a different console.

Virtual consoles have a screen saver feature like that found on Microsoft Windows. If a virtual console is inactive for an extended period, Linux blanks the monitor screen. To restore the screen without disturbing its contents, simply press the Shift key.

Logging Out

When you’re done using a virtual console, you should log out by typing the command exit and pressing Enter. When you log out, the system frees memory and other resources that were allocated when you logged in, making those resources available to other users.

When the system logs you out, it immediately displays a login prompt. If you change your mind and want to access the system, you can login simply by supplying your userid and password.

Shutting Down the System

You shouldn’t turn off power to a computer while it’s running Linux; instead, you should shut down the operating system and then turn off power. To shut down a Linux system, you use the shutdown command, which resides in a directory named /sbin:

[root@desktop /root]# /sbin/shutdown -h now

Don’t type the prompt, which automatically appears on the command line. Only the root user can issue the shutdown command. If you want to restart a Linux system, you can use an alternative form of the shutdown command:

[root@desktop /root]# /sbin/shutdown -r now

Or, even more conveniently, you can use the familiar MS-DOS “three-finger salute”: Ctrl-Alt-Del, which simply issues a shutdown command on your behalf.

When you shut down a system, Linux automatically logs off all users, terminates all running programs, and closes all open files. Before shutting down a system, you should check each virtual console to determine if an important operation is in progress. If so, you should delay shutting the system down until the operation completes.

Get Learning Red Hat Linux now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.