CHAPTER 1

image

Getting Started

Database administrators (DBAs) are crucial members of every information technology team. They are responsible for mission-critical tasks such as the following:

  • Installing software and creating databases
  • Providing a highly scalable and well-behaving database environment
  • Monitoring and maintaining company databases
  • Ensuring that corporate data is backed up, secured, and protected
  • Troubleshooting system performance and availability issues
  • Being the holistic source of database engineering information

These responsibilities require that a DBA possess a combination of database and operating system (OS) expertise. It’s a fact that you (the DBA) cannot architect, implement, or maintain a large, high-transaction database environment without being an expert on the underlying OS. In many situations, the OS is your only conduit to the database. Therefore, it’s imperative that you be particularly knowledgeable about the OS to competently perform your database administration duties.

When first building a database, DBAs should be able to specify solid, reliable, and scalable system configurations. Furthermore, DBAs are often the cog between system administrators, users, network administrators, managers, and corporate executives. If you’re working (after the fact) on a poorly designed system, you have to possess the tools to diagnose and resolve bottlenecks in the entire technology stack. Regardless of the source of the issues, team members often look to the seasoned DBA to resolve systemic performance, security, and availability concerns. We know this to be true because we live it every day (including nights and weekends).

Oracle software runs on a variety of OSs, including many Linux/UNIX variants and Windows. A large number of Oracle installations are on Oracle Linux or Oracle Solaris. Oracle Linux is Oracle’s version of Linux based on Red Hat Enterprise Linux (RHEL). Oracle Solaris is a UNIX OS originally created by Sun Microsystems and now owned by Oracle Corporation since Oracle’s acquisition of Sun in 2010.

The Linux and Solaris OSs are widely recognized as reliable 24/7, mission-critical, enterprise server platforms. Employers specifically seek out DBAs with Linux/Solaris expertise. In fact, as a DBA, it’s inevitable that you’ll someday use Linux or Solaris servers to store your data. You will be responsible for ensuring that your database is working seamlessly with the underlying OS. Managers will look to you to guarantee that corporate databases are competently implemented and maintained.

This book focuses on helping you understand how to efficiently manage Oracle software on Linux and Solaris servers. On the surface, you’ll find Linux and Solaris are mostly identical in commands and syntax (the same can be said for Linux and any UNIX variant). Having said that, there are occasional differences between the OSs that you have to be aware of. We’ll strive to point out these subtle differences where they exist. When there are no differences, we’ll simply refer to the OS as “Linux/Solaris,” meaning that the concept applies equally to both.

The information in this book will enable you to function as an expert DBA when performing key responsibilities. We provide direct answers to specific problems regarding Oracle database technology running on Linux/Solaris OSs. The recipes in this first chapter assume that you know nothing about Linux/Solaris and cover situations that you’ll be presented with when you first connect to a server and use OS commands. If you are already fairly experienced with the Linux/Solaris OS, feel free to skip this chapter.

In this chapter, we start by walking you through some of the most common methods for logging on to a Linux/Solaris server. We then cover the basics of running Linux/Solaris commands and detail how to use the built-in help and online documentation. We finish the chapter by showing techniques for correcting command-line mistakes and resetting a terminal screen.

1-1. Connecting Securely to a Remote Server

Problem

You’re using a Windows–based laptop or workstation and want to securely connect to a remote Linux/Solaris database server over the network.

Solution

This solution shows how to download and use the PuTTY application to initiate secure remote connections over the network:

  1. To get started, download PuTTY from an Internet site such as www.putty.org or www.chiark.greenend.org.uk/~sgtatham/putty/download.html.
  2. Once on the PuTTY download site, you’ll find links that enable you to download the PuTTY application. You can download just the putty.exe file or all utilities available via the putty.zip file.
  3. After you download the desired files, navigate on your personal computer to the directory in which you downloaded the PuTTY utility. You should see a screen similar to Figure 1-1. Double-click the PuTTY icon to start the connection utility.

    9781484212554_Fig01-01.jpg

    Figure 1-1. PuTTY application icon

  4. Figure 1-2 shows a partial screenshot of what you see next. From this screen, you can enter the hostname or IP address and connection port of the remote server to which you want to connect. Enter the connection details of your Linux/Solaris database server and click the Open button to initiate a remote connection. If you aren’t sure about the connection information, contact your system administrator for details.

    9781484212554_Fig01-02.jpg

    Figure 1-2. PuTTY connection details

  5. After you connect to your database server, you should see the screen shown in Figure 1-3. Enter your username and password (contact your system administrator if you don’t know them). Once logged on, you can run shell commands to perform tasks on your database server. (Chapter 2 provides more detail about shells.)

    9781484212554_Fig01-03.jpg

    Figure 1-3. Linux/Solaris server logon screen

How It Works

PuTTY is a free open source utility that allows you to create a secure shell (SSH) connection to a remote database server. This utility is popular because it is a free, easy-to-use application that enables you to connect securely from a Windows client over the network to remote Linux/Solaris database servers. With this tool, you can store your server preferences and connection information, which eliminates the need to retype lengthy hostnames or IP addresses.

Image Note  Other utilities also allow you to initiate remote connections via an SSH. For example, the Cygwin/X application is a popular Windows-based implementation of the X Window System. This Cygwin/X utility allows you to run X applications on your Windows desktop and start remote SSH connections to your database server.

You can also use PuTTY to connect via proxy servers and SSH tunneling. Examples are explained briefly in the next sections.

Connecting via a Proxy Server

Many companies require all their Internet connections to pass through a proxy server for security and performance reasons. To use PuTTY to connect via a proxy server, open the PuTTY Configuration dialog box and click the Proxy node under the Connection category, as shown in Figure 1-4.

9781484212554_Fig01-04.jpg

Figure 1-4. PuTTY—proxy server configuration

Select HTTP for the proxy type, provide the hostname or IP address of the proxy server, and provide the corresponding port number. Save the changes to your PuTTY configuration for future use.

Connecting via SSH Tunneling

You can also use PuTTY for tunneling (also called port forwarding) to a remote server. To use tunneling, open the PuTTY Configuration dialog box and then choose the SSH as the connection type. Next, provide the hostname or IP address of the designated SSH server as well as the SSH port number (the default is 22). Afterward, click the Connection node, then the SSH node, and finally the Tunnels node, as shown in Figure 1-5.

9781484212554_Fig01-05.jpg

Figure 1-5. PuTTY—SSH tunneling configuration

In the “Source port” field under the “Add new forwarded port” section, provide the port number you will connect to at your Windows client. In the Destination field, provide the hostname or IP address of the Linux/Solaris database server, as well as the port number. Save the changes to your PuTTY configuration for future use.

1-2. Logging on Remotely via the Command Line

Problem

Your system administrator has provided you with a username and password for your database server. You now want to log on to the server via a command-line utility such as telnet or ssh.

Solution

This example assumes that you can access a terminal from which you can initiate an ssh command. Depending on your environment, your “terminal” could be a PuTTY session (see recipe 1-1) on your home PC or workstation. Ask your system administrator for help if you’re not sure how to start a terminal session (this can vary quite a bit, depending on your working environment).

In this line of code, the username is oracle and the hostname is rmoug1:

$ ssh -l oracle rmoug1

If ssh successfully locates the database server, you should be prompted for a password (the prompt can vary depending on the OS version):

Password:

For security purposes, your password does not display as you type it. After typing your password, press Enter or Return to complete the logon process.

Image Tip  If you think you made a mistake while entering your password, press Ctrl+U to erase all invisible text from the password line. This technique will save you time and prevent many accidental failed logins. Alternatively, you can try to use Backspace or Delete to erase any text you’ve entered.

How It Works

The ssh utility is widely used in Linux/Solaris environments for establishing secure connections to remote servers. By default, most SSH servers listen on port 22. You can verify the port by viewing the contents of the /etc/ssh/sshd_config file. Here’s an example:

$ cat /etc/ssh/sshd_config

Here’s a partial listing of the output:

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented. Uncommented options change a
# default value.
#Port 22

If your system administrator has set up the server to listen on a port other than 22, you have to explicitly specify it with the -p (port) option. This example connects the oracle user to the rmoug1 server on port 71:

$ ssh -p 71 -l oracle rmoug1

After a valid username and password are entered, your system might display information such as the last time you logged on, from what machine you initiated the connection, whether your account has unread mail, and so on. Additionally, if your system administrator has entered any text within the /etc/motd (message of the day) file, that information also displays. The following text is a typical login message:

Last login: Wed Mar 28 14:12:50 2015 from from hlrn.rmoug.net

After your username and password have been successfully authenticated by the Linux/Solaris server, you should see a $ (dollar sign) prompt:

$

The $ character signifies that you are at the shell command-line prompt. The $ character is the default command-line prompt for most Linux/Solaris systems.

Image Note  All command-line examples in this book show the $ prompt. You don’t have to type the $ prompt as part of any of the example commands in this book.

Your system administrator might have configured your account to display a different prompt from the $ character. DBAs sometimes configure the prompt to include information such as the server name and database name. See recipe 2-6 for changing your command-line prompt from something other than the default.

Image Note  If you are logged in with the root account (sometimes called superuser), the default command-line prompt is the # character.

Some servers accept remote connections from telnet clients. For security reasons, we recommend that you do not use telnet to initiate a logon to a server over the network. The telnet utility does not use encryption and is vulnerable to hackers snooping on the network. Whenever possible, you should use the secure ssh tool for remote connections. However, you might occasionally have to use telnet because ssh isn’t available. The following example uses telnet to log on to a remote server over the network:

$ telnet -l oracle dbsrver

1-3. Logging off the Server

Problem

You want to log off the server.

Solution

Three methods for logging out of the database server are covered in this solution:

  • Pressing Ctrl+D
  • Typing exit
  • Typing logout

The quickest way to log off is to press Ctrl+D, which immediately logs you off your server. In this example, the Ctrl and D keys are pressed at the same time:

$ Ctrl+D

You should now see a message like this:

Connection to <your server> closed.

You can also type the exit command to log off your database server:

$ exit

You should now see a message like this:

Connection to <your server> closed.

You can also type the logout command to log off the system:

$ logout

You should now see a message like this:

Connection to <your server> closed.

How It Works

If you start a subshell within an existing shell session, the logout techniques described in the “Solution” section exit you from only the innermost shell. For example, suppose that you have logged on to your server and then issued the following command:

$ bash

You now have started a subshell. If you want to exit the subshell, use one of the techniques described in the “Solution” section:

$ exit

Similarly, if you issue the su command to switch to another user, when you exit that session, you are returned to the shell from which you initiated the su command.

It’s a good security practice to log out of your OS session if you plan to be away from your terminal. As a DBA, you’ll typically find yourself logged on to the server as the user who owns the database binaries (usually the oracle OS account). The oracle account is like a database superuser account.

The database OS account can do potentially damaging operations such as drop databases, remove database files, and so on. Logging out ensures that your database OS account isn’t compromised.

Image Tip  Set the TMOUT variable to limit the amount of idle time a session can have before it is automatically logged off. This parameter can be set globally in the /etc/bashrc file. See recipe 2-5 for how to automatically set variables when logging on to a server.

1-4. Running a Command

Problem

You’re new to Linux/Solaris, and you want to run a shell command from the OS prompt.

Solution

Linux/Solaris commands are run from the command line by typing them and pressing the Enter or Return key. This example uses the df (disk-free) command to display the amount of unused disk space on the database server:

$ df

There might be some differences in the output of df, depending on your OS version. On a Linux system, you should see output similar to this:

Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/xvda2           200095024 123528852  66237984  66% /
/dev/xvda1             1019208    138748    827852  15% /boot

On a Solaris system, the output of the df command might look different:

$ df

/                  (rpool/ROOT/solaris-1):104676373 blocks  104676373 files
/devices           (/devices            ):        0 blocks          0 files
/dev               (/dev                ):        0 blocks          0 files
/system/contract   (ctfs                ):        0 blocks 2147483592 files

Sometimes the output of various OS commands is formatted differently from Linux to Solaris. Usually this is important only if you’re trying to write a program (e.g., a shell script) that expects information to consistently be located in certain columns (see Chapter 7 for details on shell scripting). You have to adjust your scripts based on the format of the output for each OS.

How It Works

When you log on to a Linux or Solaris box, by default you are placed at the command line. (The command line is where you type shell commands to accomplish a given DBA task.) The default command-line prompt for most systems is the $ character.

You can modify the default behavior of a command by running it with one or more options (sometimes called flags or switches). This example shows uses the df command with the -h option to display the output in a more human-readable format:

$ df -h

Filesystem            Size  Used Avail Use% Mounted on
/dev/xvda2            191G  118G   64G  66% /
/dev/xvda1            996M  136M  809M  15% /boot

Commands can also take arguments, which typically designate a file or text that the command should use. When running a command, arguments are usually placed after the options. This example uses the df command with the -h option and uses the argument of /dev/sda2 (which is a particular filesystem):

$ df -h /dev/xvda2

Filesystem            Size  Used Avail Use% Mounted on
/dev/xvda2            191G  118G   64G  66% /

This book does not detail the use of various graphical user interfaces (GUIs), which are helpful when you don’t know the actual command. As useful as these graphical tools are, we strongly recommend that you explore using commands from the command-line prompt. As a DBA, you will encounter situations in which the GUI tool doesn’t do everything you need to accomplish a task. For some problems, you need access to the command line to debug and troubleshoot issues. Many complicated or custom DBA tasks require that you be proficient with command–line programming techniques. Although some sites have useful GUIs, some do not. All sites have the command line. If you get dependent on a specific GUI to do your work, you might be lost when you get to a site with no GUIs.

If you don’t know the appropriate shell commands and their features, you might waste time and effort solving a problem when it could have easily been resolved if you knew which tools and options were available.

GOLDEN HAMMER RULE

The Golden Hammer Rule can be stated this way: “When the only tool you have is a hammer, everything looks like a nail.” What does that mean? When people find a tool that solves a problem, they have a natural tendency to use that tool again and again to solve other problems. This dependence can occur because after you’re familiar with a given tool or technique, you’ll continue to use it because it’s available; you’ve had training with the tool; and you’ve developed a skill set.

Nothing is wrong with that approach per se. However, if you want to be a more marketable DBA, you should expand your horizons from time to time by learning new skills and investigating up-to-date methods for solving problems. In today’s ever-changing technology environment, the DBA with the most current skills is often the one who survives the longest.

It’s getting harder and harder to find database environments that don’t use Linux/Solaris. As a DBA, you should take the initiative to learn about Linux/Solaris and how this technology is used by companies around the world to provide cost-effective information technology solutions.

1-5. Getting Help

Problem

You want to find more information about how to use a shell command.

Solution

One extremely nice feature of Linux/Solaris is that there are several options for quickly obtaining more information regarding shell commands. Table 1-1 contains descriptions of command-line help features readily available on most systems:

Table 1-1. Common Help Features

Help Feature

Description

man

Read the online manual for a command.

whatis

View a brief description of a command.

which

Find a tool.

--help

Show help.

apropos

Display man page documentation.

info

List extensive documentation.

Tab key

Show available commands.

Each of the help methods in Table 1-1 is described in the following sections.

Reading Manual Pages

The man (manual) page for a command displays online documentation for almost every shell command. The following command displays information about man:

$ man man

Here’s a partial listing of the output:

man(1)

NAME
       man - format and display the on-line manual pages

SYNOPSIS
       man  [-acdfFhkKtwW]  [--path]  [-m  system]  [-p string] [-C config_file]
[-M pathlist] [-P pager] [-B browser] [-H htmlpager]...

The man command uses a screen pager—usually the less command—to display the help page. The less utility displays a : (colon) prompt at the bottom-left corner of the screen. You can use the spacebar to go to the next page and use the up and down arrows to scroll through the documentation line by line.

Table 1-2 lists the less command options available to you while viewing man pages. Press the Q key to exit the man utility.

Table 1-2. The less Command Options Available While Viewing man Pages

Keystroke

Action

J, E, or Down arrow

Move down one line.

K, Y, or up arrow

Move up one line.

Up arrow

Move up one line.

Down arrow

Move down one line.

/<string>

Search for <string>.

n

Repeat the previous search forward.

Shift+N

Repeat the previous search backward.

H

Display the help page.

F, spacebar, or Page Down

Move down one page.

B or Page Up

Move up one page.

Q

Exit the man page.

The man pages are usually divided into ten sections. The man command displays the first man page match it finds for a specified command. Sometimes a Linux/Solaris utility is documented in more than one man section. To view all man documentation available for a tool, use the -f option (this is equivalent to running the whatis command). This example views all man pages available with the cd command:

$ man -f cd

From the output, you can see that cd is documented in several different man sections:

cd                  (1p)  - change the working directory
cd                   (n)  - Change working directory
cd [builtins]        (1)  - bash built-in commands, see bash(1)

To view the man documentation specific to the cd utility, specify the 1p page:

$ man 1p cd

To scroll through all man sections associated with a command, use the -a option. Here is an example:

$ man -a cd

When in this mode, press the Q key to advance to the next man section of information.

CAPTURING MAN PAGES IN A TEXT FILE

It can sometimes be helpful to capture the output of a man command in a file that can be used later to search and scroll through with a text editor. The following command writes the output of the man page for the find command to a file named find.txt:

$ man find >find.txt

However, if you inspect the output file, you might notice that it contains unreadable characters that are produced from the man page output. Run the following command to clean up the output of the man page:

$ man find | col -b >find.txt

The previous command takes the output from the man command and sends it to the col -b (postprocessing filter) command. This filtering command removes the unreadable backspace characters from the man page output and makes them human-readable.

Viewing a Brief Description of a Command

If you’re new to Linux/Solaris (or if you have forgotten the material), use the aptly named whatis command to answer this question: “What is a command’s basic information?” The whatis command lists the first line of text from the man page. This example shows how to use the whatis command to find more information about the pwd command:

$ whatis pwd
pwd                  (1)  - print name of current/working directory
pwd                 (1p)  - return working directory name
pwd                  (n)  - return the absolute path of the current working directory
pwd [builtins]       (1)  - bash built-in commands, see bash(1)
pwd.h [pwd]         (0p)  - password structure

The number/letter (enclosed in parentheses) specifies the section of the man page in which you can find the command. When you see multiple lines listed by whatis, the command is documented in more than one location in the man pages. The output also indicates that there is a built-in Bash version of the command (see Chapter 2 for more details about built-in commands).

Another interesting use of the whatis command is to view a one-line description of commands in the /bin directory. This example uses whatis with ls, xargs, and less to view the descriptions of all commands in the /bin directory one page at a time:

$ cd /bin
$ ls | xargs whatis | less

arch                 (1)  - print machine architecture
awk                 (1p)  - pattern scanning and processing language
basename             (1)  - strip directory and suffix from filenames
...

The previous code first lists the files in the /bin directory; its output is then piped to the xargs command. The xargs command takes the output of ls and sends it to the whatis utility. The less command displays the output one page at a time. To exit from the documentation (displayed by less), press the Q key (to quit).

Image Note  The whatis command is identical to the man -f command.

Locating a Command

Use the which command to locate the executable binary file of a command. This line of code locates the binary man executable file:

$ which man
/usr/bin/man

The which command is extremely useful for determining whether binary files or utilities are available on a server and where they are located. You might find that many commands and utilities are not consistently available, depending on which Linux/Solaris packages have been installed. Talk to your system administrator if you need a utility that is not available.

Showing Help

On Linux systems, use the --help option to quickly display basic information about a tool’s use and syntax. This example demonstrates how to get help for the df command:

$ df --help

Here’s a partial listing of the output:

Usage: df [OPTION]... [FILE]...
Show information about the filesystem on which each FILE resides,
or all filesystems by default. Mandatory arguments to long options are mandatory
for short options too.
  -a, --all             include filesystems having 0 blocks
  -B, --block-size=SIZE use SIZE-byte blocks
  -h, --human-readable  print sizes in human readable format (e.g., 1K 234M 2G)

Depending on the version of the OS, there might not be a --help option for shell commands. To that point, there is no --help option for Solaris shell commands. If this is the case, you have to use one of the other documentation sources (e.g., man) listed in this recipe.

Finding Manual Page Documentation

If you can remember only part of the name of the utility you seek, use the apropos command to find more documentation. The apropos command is similar to whatis, except that it searches for any string that matches your input. The following example searches the whatis command for the string find:

$ apropos find

Here’s a partial snippet of the output:

find               (1)    - search for files in a directory hierarchy
find              (1p)    - find files
find2perl          (1)    - translate find command lines to Perl code
findchip           (8)    - checks the FIR chipset
findfs             (8)    - find a filesystem by label or UUID

The previous output shows that many different types of find commands are available. Use the man command (previously discussed in this recipe) to view more information about a particular find command. The number in the second column (in parentheses) lists the section of the man page in which the documentation is contained.

Image Note  The apropos command is equivalent to the man -k command.

Listing Extensive Documentation

The info utility often contains extensive documentation for many Linux/Solaris commands. To view all documents available, type info with no parameters, as shown here:

$ info

Here’s a small snippet of the output:

File: dir       Node: Top       This is the top of the INFO tree

  This (the Directory node) gives a menu of major topics.
  Typing "q" exits, "?" lists all Info commands, "d" returns here,
  "h" gives a primer for first-timers,
  "mEmacs<Return>" visits the Emacs topic, etc.

  In Emacs, you can click mouse button 2 on a menu item or cross reference
  to select it.

* Menu:

Texinfo documentation system
* Pinfo: (pinfo).           curses based lynx-style info browser.
* Texi2HTML: (texi2html).  Texinfo to HTML Converter.
...

Once within the utility, use the N key to go to the next section. The P key takes you to a previous section. Any line that starts with an asterisk (*) is a link to other sections (nodes) in the document. To go to a linked document, navigate to the line containing the asterisk and press Enter or Return. Press the Q key to exit the info page.

Table 1-3 lists some of the commonly used navigational info commands.

Table 1-3. Commonly Used Navigation Keystrokes Within the info Utility

Keystroke

Action

N

Move to the next section.

P

Move to the previous section.

Enter/Return

Move to a linked document.

Q

Exit.

?

List all commands.

D

Return to the introduction page.

H

Go to the tutorial.

You can also view information regarding specific commands. This example starts the info utility to display help for the cpio command:

$ info cpio

To view a tutorial on info, type $ info.

Showing Available Commands

If you’re using the Bash shell (see Chapter 2 for details on using a shell), you can use the Tab key to show all executable files that start with a certain string. For example, if you want to view all commands that start with the string ls, type ls and press the Tab key twice (with no space between the ls command and pressing the Tab key):

$ ls<Tab><Tab>
ls            lsb_release  lsnrctl       lspgpot
lsattr        lshal        lsnrctl0      lss16toppm

After Tab is pressed twice, the Bash shell attempts to find all commands that start with ls that are located in any directories contained in the PATH variable. This feature of automatically looking for files is known as command completion. (See recipe 2-2 for more details on command completion.)

How It Works

The “Solution” section of this recipe contains some of the most useful information you’ll need to elevate your Linux/Solaris skills. You should take some time to become familiar with all the helpful techniques described in this recipe.

Linux/Solaris has extensive utilities for easily viewing command documentation. Using these built-in help features allows you to quickly find basic syntax and use of a given shell command. In particular, we suggest that you become familiar with man and info; you’ll use these informational tools on a regular basis.

1-6. Correcting Command-Line Mistakes

Problem

You’re a typical DBA, so you often mistype things on the command line. You wonder whether there are command-line tools to correct your typing mistakes.

Solution

If you’re using the Bash shell (see Chapter 2 for details on using a shell), press Ctrl+_ (underscore) at the same time to undo what you just typed at the command line. Notice that you have to use the Shift key to get the underscore (_) character. If you type a long command string, pressing Ctrl+_ erases everything to the left of the prompt. If you have backspaced over a command, pressing Ctrl+_ undoes what you have backspaced over.

How It Works

Other keystrokes are available to help you undo what you just typed. For example, you can use Ctrl+T to transpose two characters just to the left of the prompt (ensure that there is no space between the command characters and Ctrl+T). This next bit of code uses Ctrl+T to transpose the last two characters of the letters pdw:

$ pdw Ctrl+T

You should now see the following:

$ pwd

Table 1-4 summarizes the commands available for correcting typing mistakes at the command line.

Table 1-4. Command-Line Keystrokes to Correct Typing Errors

Keystroke

Action

Ctrl+_

Undo what was just typed in.

Ctrl+U

Clear out everything to the left of the prompt.

Ctrl+T

Transpose two characters that are immediately to the left of the prompt.

Alt+T

Transpose two words that are on the left of the prompt.

1-7. Clearing the Screen

Problem

Your screen has become cluttered with command output. You want to clear the screen of any previously displayed text or command output.

Solution

Either use the clear command or press Ctrl+L to clear your terminal screen. The clear command does what you would expect: it clears the screen. Simply type the command as shown with no options or arguments:

$ clear

If you’re using the Bash shell (see Chapter 2 for details on shells), another method for clearing the screen is to press Ctrl+L:

$ Ctrl+L

One nice feature about Ctrl+L is that you can enter this command while typing other commands on the command line. Pressing Ctrl+L clears the screen and retains any current commands you have entered on the command line. For example, suppose that you are in the middle of typing a find command; you can enter Ctrl+L as shown here:

$ find . -name *.sql Ctrl+L

When you press Ctrl+L, it clears the screen and places the command you are currently typing at the top of the screen. In this example, the find command appears at the top of the screen:

$ find . -name *.sql

How It Works

The clear command removes all output visible on your screen and retrieves environment information from the terminfo database to determine how to clear the screen (use man terminfo for details regarding your environment).

The Ctrl+L keystroke works with the Bash shell and it can work with other shells, depending on your version of the OS. Unlike the clear command, Ctrl+L retains whatever command you are currently typing and displays it at the top of the cleared-out screen.

1-8. Resetting the Screen

Problem

Your screen has become cluttered with strange, unreadable characters. Using the clear command and Ctrl+L doesn’t have any effect.

Solution

Try to use the reset command to restore the screen to a sane state:

$ reset

If the reset command doesn’t work, try the stty sane command:

$ stty sane

If that doesn’t work, try exiting your terminal session and restarting it. Although it is not the ideal solution, sometimes it is the only thing that does work.

How It Works

Sometimes your screen can become cluttered with unreadable characters. For example, it can happen if you accidentally use the cat command to display the contents of a binary file. Use either the reset or stty sane command to restore your screen to a normal state.

The reset command is actually a symbolic link (see recipe 5-33 for more details on links) to the tset (terminal initialization) command. (View the man pages for tset for more details on this utility.) The reset command is particularly useful for clearing your screen when a program abnormally aborts and leaves the terminal in an unusual state.

The stty (set terminal type) command displays or changes terminal characteristics. If you type stty without any options, it displays the settings that are different from those set by issuing the stty sane command.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset