Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question

migrated from stackoverflow.com Nov 18 '11 at 12:24

This question came from our site for professional and enthusiast programmers.

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

3 Answers 3

Try this:

export PS1='\u:\W\$ '
share|improve this answer
    
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 '11 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! :) –  Tom Wijsman Nov 19 '11 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 '11 at 21:35

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

export PS1='\u:\h \W #'
share|improve this answer

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 #
share|improve this answer

Your Answer

 
discard

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.