How to make your Unix prompts more useful
A customized prompt can serve as a gentle reminder of what system you’re working on — especially helpful if you often find yourself logged into 3-4 systems at a time, window hopping to get several things done at the same time. or if you log in with different accounts. A customized prompt can help if you like to be reminded where you are sitting in the file system or prefer *not* to be reminded where you are in the file system (a full path can take up quite a bit of screen space when you’re seven levels deep into /home/username/apps/docs/…).
All you need to do to define your PS1 variable and save it in your .bashrc or .bash_profile file. As it turns out, however, you have a lot of flexibility on what you put into that prompt.
[…] Set your prompt to the current time. […]
$ PS1="\A> " 20:52> PS1="\t> " 20:50:13>NOTE: The > at the end of these prompts and the blank that follows are optional, but my preference. I like these characters separating my prompts from my commands.
Have trouble remembering what system you’re logged into?
$ PS1='\h> ' boson>[…] If you can’t remember where you are, the w setting will show your path relative to your home directory. The ~, of course, is your home itself.
PS1='\w ' ~When you need some cheering up:
$ PS1=':-) ' :-)When you have amnesia or just want to be reminded what account you’re logged into:
PS1="\u> " lmoore>You can expand this to show both the username and system name like this:
PS1=“\u@\h “
$ PS1="\u@\h> " lmoore@boson>Any of the following can be use din your prompt, though I suspect that few of us will hear the bell even if we use that character string in our prompts.
\a an ASCII bell character (07) \d the date in "Weekday Month Date" format (e.g., "Tue May 26") \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 \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 \W the basename of the current working directory \! 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
Discussion Area - Leave a Comment