I lose too many columns in my terminal because of the credentials ( Victor-Rodriguess-MacBook-Pro:~ victorrodrigues$ ). Could I shrink this?

The only information I see as really needed sometimes for me is the folder name, nothing else.


What you're after is a custom bash prompt.

For just displaying the folder name, add this to your ~/.bashrc file:

export PS1="[\w]$"

This is what it will look like (your home directory is shortened to tilde):

[~]$cd /
[/]$cd /usr/bin/

For an excellent overview and a list of the other available escape sequences, check out the following article: How to: Change / Setup bash custom prompt (PS1). It is a Linux tutorial but it works in bash on Mac as well.

  • Thank you for the answer, man. But as I am a recent ex-Windows user, I'm very dummy with some problems. I've opened the .bashrc file through Mate (mate ˜/.bashrc), it showed me an empty file, I've pasted that line above. When I tried saving it, it just couldn't, even with my password entered. It seems it doesn't accept me for saving system files. But my sudo capabilities at terminal exists. =/ – user1088 Feb 14 '10 at 9:20
  • Maybe the editor didn't recognize the tilde for whatever reason. In your home directory just make the file .bashrc and add that line to it. I believe you can also edit /etc/bashrc for system-wide changes. – John T Feb 14 '10 at 9:22
  • I've made a .bashrc in my home folder, and this didn't work either. But making changes to /etc/bashrc made things happen, thanks! – user1088 Feb 14 '10 at 9:27
  • You're more than welcome! – John T Feb 14 '10 at 9:50
  • While generally correct, the Linux tutorial has some problems with conventions in OS X. See my answer. – Debilski Feb 15 '10 at 1:47

As a general note:

The bash session started by Terminal.app is usually a login session. (You will see the difference as the login session will tell you about your last login on startup.) This can be changed in the preferences where you can choose between /usr/bin/login and a custom command.

Login sessions don’t usually execute the scripts in ~/.bashrc but look for /etc/profile, ~/.bash_profile, ~/.bash_login, and ~/.profile. (See man bash.) However, /etc/profile will also call /etc/bashrc, so that the changing this file gave the appropriate results.

To get consistency over login and non-login shells, one usually changes ~/.profile to also execute the ~/.bashrc file and includes all changes for login and non-login shells to the latter.

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.