Skip to content

Instantly share code, notes, and snippets.

@ntamvl
Last active February 21, 2024 11:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ntamvl/77dc8a895ccbd2f31f071cb581cb666f to your computer and use it in GitHub Desktop.
Save ntamvl/77dc8a895ccbd2f31f071cb581cb666f to your computer and use it in GitHub Desktop.
Remove full path from terminal

Remove full path from terminal

The part before the $ in a shell is called prompt. It can be configured by changing the variable $PS1. There are is a similar question with good answeres.

The man page (see "Bash" and there "PROMPTING") says:

      \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 have to change \w to \W. Probably the initial value for $PS1 is stored in your .bashrc, that means you have to edit the file ~/.bashrc and you will find lines similar to:

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

Change \w to \W in both lines and open a new terminal (or run source ~/.bashrc).

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

Ref: https://askubuntu.com/questions/232086/remove-full-path-from-terminal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment