Extending the Bash Prompt

Terminal and xterm prompts can be created incorporating standard escape sequences to give user name, current working directory, time and more.


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

you can use the tput utility

norpan's picture

you can use the tput utility to avoid typing escape sequences and have it work on any terminal. Just use for instance $(tput setaf 1) instead of \e[31m.


Anonymous's picture

how about the title prompt in tthe bar up top? what is the code for that? I have:

function combo {
PS1="\[\033[01;34;01m\]\333\262\261\260\[\033[01;37;44m\]\u@\h\[\033[00;34;40m\]\260\261\262\333\[\033[00;34;40m\]\333\262\261\260\[\033[01;37;40m\] \d \$(date +%I:%M:%S%P)\n\[\033[01;33;40m\]$PWD>\[\033[00m\] "
PS2="\[\033[01;34;01m\]\333\262\261\260\[\033[00;34;40m\]\260\261\262\333\[\033[00;34;40m\]\260\261\262\333\[\033[00;34;40m\]\333\262\261\260\[\033[01;01;34m\]>\[\033[00m\] "

and it just says "xterm" at the top title of the xterm--not the screen prompt, that is correct. Am I making sense? I have code for it, but i get my old hostname there, but the correct hostname at the screen prompt. I hope this makes sense...

USA bash prompt

s7even's picture

patriot or pirate....latter or former.

here's the fruit of some wasted productivity.
USA the _______.


PS1="\033[44m*****\033[41m \033[0m\n\033[44m*****\033[47m \033[0m\n\033[44m*****\033[41m \033[0m\n\033[47m \033[0m\n\033[41m \033[0m \$ "

ps,,, BSD rules =P

BSD ruled

humbletech99's picture

BSD did rule, but now is the time of GNU/Linux where newer, younger, stronger challengers are here, bring on Gentoo...

Also, death to 1000 distros, let's concentrate on 3 good ones...
(take note Mr Shuttleworth - you should be working for Debian, not seeking personal glory riding their coattails...)

Oh, and thanks for the article, LINUX Journal.

One Click, Universal Protection: Implementing Centralized Security Policies on Linux Systems

As Linux continues to play an ever increasing role in corporate data centers and institutions, ensuring the integrity and protection of these systems must be a priority. With 60% of the world's websites and an increasing share of organization's mission-critical workloads running on Linux, failing to stop malware and other advanced threats on Linux can increasingly impact an organization's reputation and bottom line.

Learn More

Sponsored by Bit9

Linux Backup and Recovery Webinar

Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.

In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.

Learn More

Sponsored by Storix