home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Linux in a NutshellLinux in a NutshellSearch this book

7.5. Command History

bash lets you display or modify previous commands. Commands in the history list can be modified using:

  • Line-edit mode

  • The fc command

In addition, the command substitutions described in Chapter 8 also work in bash.

7.5.4. Variables in Prompt

Using the following variables, you can display information about the current state of the shell or the system in your bash prompt. Set the PS1 variable to a string including the desired variables. For instance, the following command sets PS1 to a string that includes the \w variable to display the current working directory, and the \! variable to display the number of the current command. The next line is the prompt displayed by the change.

$ PS1='\w: Command \!$ '
~/book/linux: Command 504$

Variable

Meaning

\a

Alarm (bell)

\d

Date in the format "Mon May 8"

\e

Escape character (terminal escape, not backslash)

\h

Hostname

\j

Number of background jobs (active or stopped)

\l

Current terminal name

\n

Newline inserted in the prompt

\r

Carriage return inserted in the prompt

\s

Current shell

\t

Time in 24-hour format, where 3:30 p.m. appears as 15:30:00

\u

User's account name

\v

Version and release of bash

\w

Current working directory

\A

Time in 24-hour format, where 3:30 p.m. appears as 15:30

\D{format}

Time in the specified format interpreted by strftime; an empty format displays the locale-specific current time

\H

Like \h

\T

Time in 12-hour format, where 3:30 p.m. appears as 03:30:00

\V

Version, release, and patch level of bash

\W

Last element (following last slash) of current working directory

\\

Single backslash inserted in the prompt

\!

Number of current command in the command history

\#

Number of current command, where numbers start at 1 when the shell starts

\@

Time in 12-hour format, where 3:30 p.m. appears as 03:30 p.m.

\$

Indicates whether you are root: displays # for root, $ for other users

\[

Starts a sequence of nonprinting characters, to be ended by \]

\]

Ends the sequence of nonprinting characters started by \[

\nnn

The character in the ASCII set corresponding to the octal number nnn inserted into the prompt



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.