Unix Prompts for the Masses

By Sandra Henry-Stocker  Add a new comment

One of the first things new users might want to know is how to change their prompts. It's a small change, but one that might make them feel more at home in their new working environment. Besides, it's so easy to do. Why not indulge them? I have worked on numerous systems that include both the system name and current working directory in the prompt -- and sometimes a command number too! If your prompt ends up looking like this, you might see why a new user might be a little frustrated with it:

armageddon:/export/home/willis/movies/scripts/part2 #117>

Maybe your user doesn't need to be reminded for every command that he types just where he is sitting in the file system and how many commands he has typed already without getting all that much accomplished. The proper prompt can help the new user to feel at home or, at least, give him the feeling that he has some control over his new environment. The wrong prompt can get on his nerves. Depending on the task at hand, some prompts can be considerably more useful than others!

In some situations, being reminded of where you are currently sitting in the file system is very useful. If you're working in a single directory, on the other hand, the constant reminders can be distracting and annoying and maybe some other piece of information or a single character prompt would be so much better.

Bash users will find that their options for prompt customization are quite generous. Here are some sample commands for prompt customizations:

PS1='> '		A simple and non-distracting >
PS1='$PWD $ '		Where am I?
PS1='$PWD : $LOGNAME >'	Where and who am I (lest they forget)?
PS1="\T> "		How time flies!
PS1="\d \h $ "		What's the date and what system am I logged into?
PS1='$USER@\h > '	Who am I and what system am I logged into?
PS1='what now?> '	The impatient system
PS1="try that again> "  The encouraging system
PS1="\#> "		I've already tried # commands?
PS1='\a> '		Making an audible sound

The variety of things you can insert into a command prompt when using bash is impressive. Any mix of these options can be plugged into the system prompt as shown in the examples above.

\a : an ASCII bell character (07)
\d : the date in "Weekday Month Date" format (e.g., "Tue May 26")
\D{format} : the format is passed to strftime(3) and the result is inserted into the prompt
     string; an empty format results in a locale-specific time representation. The braces are
     required
\e : an ASCII escape character (033)
\h : the hostname up to the first '.'
\H : the hostname
\j : the number of jobs currently managed by the shell
\l : the basename of the shell’s terminal device name
\n : newline
\r : carriage return
\s : the name of the shell, the basename of $0 (the portion following the final slash)
\t : the current time in 24-hour HH:MM:SS format
\T : the current time in 12-hour HH:MM:SS format
\@ : the current time in 12-hour am/pm format
\A : the current time in 24-hour HH:MM format
\u : the username of the current user
\v : the version of bash (e.g., 2.00)
\V : the release of bash, version + patch level (e.g., 2.00.0)
\w : the current working directory, with $HOME abbreviated with a tilde
\W : the basename of the current working directory, with $HOME abbreviated with a tilde
\! : the history number of this command
\# : the command number of this command
\$ : if the effective UID is 0, a #, otherwise a $
\nnn : the character corresponding to the octal number nnn
\\ : a backslash
\[ : begin a sequence of non-printing characters, which could be used to embed a terminal
     control sequence into the prompt
\] : end a sequence of non-printing characters

For your Korn shell users, you can easily stick environment variables and command output into their prompts as shown in the examples below.

PS1='$PWD> '				Where am I?
PS1="$LOGNAME@`uname -n` \$PWD ! $ "	Who and where am I?
PS1='${PGHOST} > '			What psql server am I using?
PS1='${TZ}> '				What timezone am I in?
PS1='!$ '				How many commands have I typed?
PS1="`date`> "				What date and time is it?

The PS1 prompt is the most obvious prompt to change, but you can also redefine PS2, PS3 and so on if you're so inclined. Most users are unlikely to get past PS1 and PS2, however, and are unlikely to care much about their prompts beyond PS1.

ITworld LIVE

IT Management/StrategyWhite Papers & Webcasts

White Paper

The Cloud: Reinventing Enterprise Collaboration

Collaboration and content sharing are not, of course, new concepts. But cloud computing has changed the nature of collaboration, content sharing, document storage and project management to enable more efficient, faster-acting and cost-effective enterprises. According to a new study by IDG Research, the vast majority of knowledge workers (86%) placed a very high level of importance on collaborating with internal coworkers and external stakeholders, and having access to the most up-to-date corporate information. Read how organizations are realizing massive productivity gains by transitioning their content management solutions to cloud-based models.

White Paper

Empowering Your Mobile Worker

Today's most productive employees are mobile, and your company's IT strategy must be ready to support them with 24/7 access to the business information they need across a range of mobile devices.See how corporations are meeting the many needs of their mobile workers with the help of Box.

White Paper

Market Landscape Report: Online File Sharing and Collaboration in the Enterprise

The trend toward "consumerization" marches onward in IT; more and more end-users are choosing their own hardware plaforms and software applications in lieu of the IT-sanctioned business tools provided by their companies. These end-users are looking to tackle issues like data sharing, portability, and access from multiple intelligent endpoint devices, creating a conundrum for IT as it needs to balance business enablement, ease of access, and collaborative capacity with the need to maintain control and security of information assets. This need for balance is one of the drivers of the fast growing online file sharing and collaboration segment of the SaaS market. This paper examines the market drivers, inhibitors, and top vendors in this segment, including Box, Citrix Sharefile, Dropbox, Egnyte, Nomadesk, Sugarsync, Syncplicity and YouSendIt.

White Paper

Sharing Simplified - Consolidating File-sharing Technologies

Employees need to share content with colleagues within their organization and outside. Yet, ECMs make it hard to share content within a business and impossible between organizations. Read how one company consolidated multiple file sharing technologies to increase productivity and reduce complexity.

White Paper

Content Sharing 2.0: The Road Ahead

A growing number of companies are taking advantage of the natural synergies that exist between cloud-based IT services and content access and sharing. Legacy content management and collaboration systems simply weren't designed to meet the evolving requirements of today's IT and business managers, as well as the needs of content users. Box provides cloud-based content storage, access and collaboration services that require virtually no user training and supports file access and delivery on almost all popular PC and mobile devices. Read how Box let companies rapidly implement a cost-effective and secure content storage and sharing system that can easily expand to accommodate any size and number of files.

See more White Papers | Webcasts

Ask a question

Ask a Question