4

I would like to remove the long listing of the current directory in the shell prompt.

Its sometimes annoying when you are using a small shell window and it occupies the whole space in the window

I would rather prefer the just the current directory at the prompt.

root@Kiran:~/Downloads/Director1/Director2/Director3/Director4# I would prefer something like : root@Kiran:..Directory4#

or Better even,

root:Directory4#

Thanks

1
  • 2
    The answers below can be found by executing man bash.
    – keith.layne
    Nov 18, 2011 at 1:28

4 Answers 4

7

Try this:

export PS1='\u:\W\$ '
3
  • Although, I like seeing the whole working directory, so I just put a \n# at the end of my PS1 line and that moves the cursor down a line.
    – Rob
    Nov 18, 2011 at 15:18
  • What does that Regular Expression do? @Rob: If you are the one that posted this answer and want to get your accounts merged, flag your post for moderator attention and type in the box that you would like to have your accounts migrated. In any case, welcome to Super User! :) Nov 19, 2011 at 19:35
  • No, that's not me. the \n just puts in a newline mark. I should've said PS1='\u:\w\n\$ ' That would make the prompt "user:fulldirectory{newline}$ "
    – Rob
    Nov 19, 2011 at 21:35
4

You want to use \W and not \w when you export/set your PS1 variable:

export PS1='\u:\h \W #'
3

With Bash version 4+ you can set

export PROMPT_DIRTRIM=1

in your .bashrc. The prompt for a non-root user:

user@host:~/.../dir>

and for root

host:.../dir #
0

Another trick in addition to the ones above is too put a newline near the end of your prompt (\n$) so that what you type has the full length of the terminal:

mattb@flat:~/.../work_notes/admin
$ 

From my ~/.bashrc:

if [ "$color_prompt" = yes ]; then
    # the \n\$ at the end puts the prompt on a newline
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;35m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\n\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi

# I don't want a huge path on display
PROMPT_DIRTRIM=2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .