Questions tagged [ps1]

PS1 is the environment variable in the Bourne shell and variants which specifies the command prompt.

When you launch terminal you see something like

[user@host]:$

The string above can be changed using the the by setting params to the $PS1 variable for example:

export PS1="[\u@\h \t]:" 

will show

[user@host 13:56:33]:

another example

export PS1="[\u@\h \w]:" 

will show

[user@host /etc/somedirectory]

possible parameters are:

\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 part
\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 character
61 questions
240
votes
6 answers

How can I shorten my command line (bash) prompt?

Currently it is: michael@Castle2012-Ubuntu-laptop01:~/Dropnot/webs/rails_v3/linker/spec/controllers$ Outside of renaming my machine and directory structure... How could I make it be something more like: michael:controllers$
29
votes
3 answers

Where can I find a complete reference for the $PS1 variable?

The default PS1 variable on my machine (Kubuntu 13.10) is this: \[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$ I'm looking for a reference for how the $PS1 variable works that, at a minimum, allows me to understand the above PS1…
27
votes
2 answers

Why is my function not re-evaluated in PS1?

I'm trying to have a part of my prompt set dynamically by a function, so in my .bashrc I have: asdf () { echo -n $(pwd) } PS1="\u@\h:\w $(asdf)\$ " Opening a shell gives me what I expect at first: $ bash darthbith@server:~/test…
darthbith
  • 384
  • 3
  • 13
21
votes
4 answers

Prepend current git branch in terminal

How can I configure the terminal to display the current git branch? I'd like to see the second line rather than the first: andy@bob:~/my_projects/project_x$ (master)~/my_projects/project_x$ I don't want to have to run git status to see which…
hayd
  • 2,397
18
votes
1 answer

PS1 problem, messing up CLI

I did a simple PS1 assignment PS1="\e[0;31m[\W]\$ \e[m " All I wanted to do was to change the prompt color and display only the relative path. However this messes up the CLI. For example, when browsing history with the ↑ it crops and overlaps the…
yayu
  • 3,421
15
votes
3 answers

Long lines overlap in Bash PS1 customized prompt

I have configured a fancy two-line PS1 bash prompt, with server name, time, user name and other useful variables. PS1="\n\[\033[1;34m\]\342\226\210\342\226\210 \u @ $SERVER_NAME""$BBlue"" \w""$Color_Off \n\[\033[0;36m\]\342\226\210\342\226\210 \d…
Adam Matan
  • 12,919
14
votes
6 answers

What does the name after '@' at terminal prompt mean?

I noticed that when in terminal the prompt is generally in the format username@users: or I have even seen username@(none):. I get that the first part is the logged in person's user name, but what is the part after the @ symbol?
Jacob Schoen
  • 5,285
10
votes
2 answers

Why aren't variables like $PS1 in printenv?

From what I can tell printenv displays environment variables, but why don't I see other variables like PS1 for customizing the shell prompt? What exactly is printenv outputting and why doesn't it pick up PS1? Is there a more comprehensive output…
AJJ
  • 902
10
votes
1 answer

How do I remove computer name from the command line prompt?

Is any way to remove my computer name from command line prompt? I want the prompt to look like this: αғsнιη:~$ Instead of this: αғsнιη@αғsнιη-pc:~$
αғsнιη
  • 36,350
10
votes
2 answers

Reverse-search in CLI: messed up output afterwards

See my edit below, this is not totally a duplicate of Shell prompt customization and cmd behavior My reverse-search function in the CLI is broken and I don't know how to fix it back... When I hit ctrl+r and search a command I did earlier, find it…
MrYoshiji
  • 203
9
votes
2 answers

How to keep the coloring in bash when using `sudo -i`?

I have changed PS1 variable in /etc/bash.bashrc to PS1="\n\[\033[0;37m\]\342\224\214\342\224\200\$(if [[ \$? == 0 ]]; then echo \"[\[\033[0;32m\]\[\033[01;32m\]\342\234\223\[\033[0;37m\]]\342\224\200\"; else echo…
9
votes
1 answer

Change colour of a specific letter in the username in bash's PS1

I want to change the colour of a specific letter in my username being displayed by PS1 in bash. Eg: If my \u is rahul, I would like the letter h to be in blue colour and rest to be white. I do know that \u refers to username and adding a colour to…
8
votes
1 answer

Displaying colors in the prompt

How to display my prompt in color? I see a lot of text go up my screen, and a lot of crud. Something like (red)myName(red)@(blue)myMachine:~$(blue) would help simplify things a lot.
theTuxRacer
  • 16,533
8
votes
1 answer

How can I change the prompt of the terminal permanently

How can I change prompt name seen at terminal? my prompt : @-MEGA-BOOK-VR320:~$ It is too long. I want to change it to: gcc : However, I should see the path when I go from one directory to another. gcc :~$ cd X_directory gcc…
user8324
6
votes
3 answers

Replace $ in terminal prompt with user@host when using SSH

I'm using Ubuntu Server over SSH, and I see $ instead of the name of the user (let's say test@desktop, for example). How can I make the terminal display test@desktop instead of $?
1
2 3 4 5