Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to remove the tilde from displaying within the PS1 variable.

My current PS1 string:


And the prompt looks like this:


I don't like that the $HOME directory is displayed as tilde. Can this be avoided?

It causes problems, example:


Documentation says:

\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

Is there any possibility to avoid $HOME being abbreviated with a tilde?

I have found one way around but I feel like it's overcomplicated:

PROMPT_COMMAND='echo -ne "\e[4;35m$(date +%T)\e[24m$(whoami)@$(hostname):$(pwd)\e[m\n"'

Can anyone propose a better solution? I have a feeling it's not quite OK to run so many commands just to get prompt. (date,whoami,hostname,pwd).

share|improve this question
up vote 7 down vote accepted

bash runs expansions in the prompt; just make sure to escape them.

share|improve this answer
That answers my question. I didn't know there is such possibility. Thanks a lot, Ignacio! – Jirka Jan 13 '11 at 14:28
@Jirka: You can also use: `PS1='\h:$PWD\n$'. – Dennis Williamson Jan 13 '11 at 16:04
Jirka's solution executes pwd on every prompt. Dennis' solution does not, just fetches environment variable PWD, which is much cheaper. – Stéphane Gourichon Nov 16 '13 at 20:57
pwd is a bash builtin. The assertion that ${PWD} is "much cheaper" than $(pwd) is without evidence. – Vineet Aug 19 '14 at 22:10
For some reasons with $(pwd) my prompt is not getting updated on cd (so stuck in /home/username). Any ideas? – anxieux Jul 21 '15 at 9:04

You don't need to run as many commands as you showed in your example. bash provides shortcuts for most of the things you mentioned.

Your example:

PROMPT_COMMAND='echo -ne "\e[4;35m$(date +%T)\e[24m$(whoami)@$(hostname):$(pwd)\e[m\n"'

can be rewritten as :


Where \t shows the time (in 24 hour format), \u shows the current username, '\h' shows the hostname -- the bash man page discusses these and the rest of the escapes available for your prompt.

Even if you expand the ~ to the full path, if you don't know which user is running the command and you're switching users regularly, you can create problems with file permissions or executable permissions.

share|improve this answer
Hi, my intention was to replace \w with the full path including FULL $HOME path. Thanks to Ignacio I'm now using PS1='\e[4;35m\t\e[24m\u@\h:$(pwd)\e[m\n$' which has solved my problem:-) – Jirka Jan 13 '11 at 14:36
Perfect -- I like including \u so that I know who I am. Don't forget to accept Ignacio's answer -- click the check box to the left of the question. – Doug Harris Jan 13 '11 at 15:05
Thanks for the hint. I'm new to this forum. It's a great place. – Jirka Jan 13 '11 at 15:14
\u@\h:$PWD (note the colon) can be used as input for scp – weberjn Feb 16 at 10:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.