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).

  • what "problems" does the tilde cause in the example? – JBallin Feb 1 '18 at 22:39

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

| 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
  • 2
    @Jirka: You can also use: `PS1='\h:$PWD\n$'. – Paused until further notice. Jan 13 '11 at 16:04
  • 1
    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
  • 2
    pwd is a bash builtin. The assertion that ${PWD} is "much cheaper" than $(pwd) is without evidence. – Vineet Aug 19 '14 at 22:10
  • 2
    @anxieux: you have to quote with single quotes, not double quotes – weberjn Feb 16 '16 at 10:30

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.

| 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 '16 at 10:34

I am using below setting in my .bash_profile file

$ export PS1='\e[1;34m\D{%T %d.%m.%Y} \[\033[00;39m\]\u\[\033[00;32m\]@$IP:\[\033[00;33m\]$(pwd)/\n\\$\[\033[00m\] '

21:40:08 14.12.2017 vmware@
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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