Customizing Your OS Command Prompt- Configuring an Efficient Environment
Typically, DBAs work with multiple servers and multiple databases. In these situations, you may have numerous terminals’ sessions open on your screen. You can run the following types of commands to identify your current working environment:
To avoid confusion about which server you’re working on, it’s often desirable to configure your command prompt to display information regarding its environment, such as the machine name and database SID. In this example, the command prompt name is customized to include the hostname, user, and Oracle SID:
The \h specifies the hostname. The \u specifies the current OS user. $ORACLE_SID contains the current setting for your Oracle instance identifier. Here is the command prompt for this example:
The command prompt contains three pieces of important information about the environment: server name, OS username, and database name. When you’re navigating among multiple environments, setting the command prompt can be an invaluable tool for keeping track of where you are and what environment you’re in.
If you want the OS prompt automatically configured when you log in, then you need to set it in a startup file. In a Bash shell environment, you typically use the .bashrc file. This file is normally located in your HOME directory. Place the following line of code in .bashrc:
When you place this line of code in the startup file, then any time you log in to the server, your OS prompt is set automatically for you. In other shells, such as the Korn shell, the .profile file is the startup file.
Depending on your personal preference, you may want to modify the command prompt for your particular needs. For example, many DBAs like the current working directory displayed in the command prompt. To display the current working directory information, add the \w variable:
As you can imagine, a wide variety of options are available for the information shown in the command prompt. Here is another popular format:
Table 3-1 lists a few useful Bash shell variables you can use to customize the OS command prompt.
Table 3-1. Bash Shell Backslash-Escaped Variables for Command Prompt
The variables available for use with your command prompt vary somewhat by OS and shell. For example, in a Korn shell environment, the hostname variable displays the server name in the OS prompt:
If you want to include the ORACLE_SID variable within that string, then set it as follows:
Try not to go overboard in terms of how much information you display in the OS prompt. Too much information limits your ability to type in and view commands on one line. As a rule of thumb, minimally you should include the server name and database name displayed in the OS prompt. Having that information readily available will save you from making the mistake of thinking that you’re in one environment when you’re really in another.