Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialLeslie Wiesman
9,581 PointsHow to change the command line prompt permanently on my personal Mac?
My personal computer came with a very long command line prompt. Example:
Toms-MacBook-Pro:~ TomandSara$
I wanted to change this prompt to:
TomandSara ~ $
I tried to do this using the export function like this:
export PS1="\u \w $ "
This works perfectly in the current bash session that I am in (changing the prompt to my desired output) but as soon as I open up another another terminal session, it goes back to the old long prompt.
Would love to know what I am doing incorrectly. Thanks a lot!
ps - I also tried using the echo version to change it as well ($ PS1="\u \w $ ") and this also only changed it for the current session. Which made sense...
3 Answers
William Li
Courses Plus Student 26,868 PointsHi, Leslie
In the Terminal, if you do a ls -a
on your home folder, you should be able to see a file named .bash_profile , this is the Command Line's init file, which gets loaded each time a new bash session is started; if you wanna modify certain default behaviors of Command Line for all future sessions, .bash_profile is where you want to make the change.
echo 'export PS1="\u \w $ "' >> ~/.bash_profile
Execute the above one line in your Terminal should append the export PS1
onto the end of your .bash_profile.
Rifqi Fahmi
23,164 Pointswhy there is no file named .bash_profile in my home directory ??? there are only .bash_histort and .bash_sessions
Sam Hall
Courses Plus Student 8,636 PointsHi Rifqi,
I found the same.
By default, the file does not exist on Mac OSX. So if you have a new Mac or have recently reinstalled OSX, it might not be there.
But you can create it yourself.
In fact, William's neat command above also creates the file if it doesn't exist. So just run that and it should sort things out.
Alternatively you could create an empty one, in your home directory, if it does not exist already, using:
touch ~/.bash_profile
fredyrosales
10,572 PointsGuys it worked for me by inserting the string but i have one question. when i type ls -a /home all i get is ". .." right below the command line? Or i'm i doing this wrong?
Leslie Wiesman
9,581 PointsLeslie Wiesman
9,581 PointsWell understood and it worked great. Thank you William!!