When I change directories in the Ubuntu terminal the full path of the directory is displayed. How can I change it so that only the current directory I am working in is displayed?

username@computer:directory$ is what I want it to look like. I found elsewhere that I should edit the variable PS1 in the .bashrc file, but I have no idea to what.

  • Whats the output of echo "$PS1" ?
    – heemayl
    Sep 20 '15 at 20:15
  • [\e]0;\u@\h: \w\a]${debian_chroot:+($debian_chroot)}\u@\h:\w\$
    – dantastic
    Sep 20 '15 at 20:17
  • Comments are not chat. If someone asks for clarification, then edit the question to make it clearer. Sep 20 '15 at 21:25

Change \w to \W in your $PS1.

So, your ~/.bashrc should contain something like:

PS1='[\e]0;\u@\h: \W\a]${debian_chroot:+($debian_chroot)}\u@\h:\W\$'

See man bash, section PROMPTING, for list of all escape sequences supported by bash and their meaning.

  • If this answer works for you, then click the tick . Sep 20 '15 at 21:26

Change the last \w to \W of PS1 environment variable.

From man bash :

\w : the current working directory, with $HOME abbreviated with a tilde (uses the value of the PROMPT_DIRTRIM variable)

\W : the basename of the current working directory, with $HOME abbreviated with a tilde

So you need :

PS1='[\e]0;\u@\h: \w\a]${debian_chroot:+($debian_chroot)}\u@\h:\W\$ '

In ~/.bashrc, there is this snippet :

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"

you can basically change the \ws to \Ws or you can selectively change matching your needs. otherwise you can put your desired PS1 value at the end of the ~/.bashrc file to override them all. As upon starting of a login shell ~/.profile sources ~/.bashrc it will be available in all login and non-login interactive sessions.

If you want to make it applicable to all users you should look at /etc/bash.bashrc and remove the relevant PS1 snippets from individual ~/.bashrc files.

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.