Go to: LING2050 home page   Lab pages index   Command reference sheet

How to Configure Your Terminal Environment: OS-X

Customizing your terminal's looks

  1. Currently, your terminal looks something like this:
    Perfectly functional, but not very easy on the eye. It quickly gets cluttered, and it's difficult to discern commands from output display. Luckily, there are ways to customize your terminals looks. To do this, you need to edit your .bash_profile file.

  2. From your home directory, type the following command in your terminal: (note that period '.' in the file name!)
    pico .bash_profile
    A text editor window will open up in your terminal:
    Copy and paste the following two lines:
    export PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u@ \[\e[33m\]\w\[\e[0m\]\n\$ '
    alias ls='ls -GF'
    Now press Ctrl+x (Control key and x key pressed simultaneously) to close the editor. It prompts to save; press y, which puts you back on your command prompt.

  3. Now execute source .bash_profile for the change to take immediate effect (or you can log out and log back in). Your terminal now should look like:
    What the first line in .bash_profile does is changing the commandline prompt to the current one: user name (green), current working directory (yellow), followed by a new line and the $ sign. The second line sets ls to be translated to ls -FG, which produces color-coded and detailed (e.g., "/" gets appended to directory names) listings.

  4. A word of caution: user definition files such as .bash_profile and .bashrc should be handled with care. When broken, they can leave you unable to operate in terminal environment. In such occasions, the file should be deleted by issuing this command: rm .bash_profile. This should be simple, in theory, but can be impossible if the file is mangled enough that you cannot even log into your terminal. And the problem is, the file is hidden within Mac Finder and therefore is not accessible this way! If this happens, try following the methods described here and here to first unhide the file, and then delete it from within Finder.

Defining your own command shortcuts in .bash_profile

  • .bash_profile lives in your home directory, and it determines the behavior of your command-line environment. This file can be modified to better suit your computing routines and habits. For example, to always display your grep results in color without having to type in --color switch, open the .bash_profile file again, and add this line:
    alias grep='grep --color'
    Save and close the editor window, and then execute source .bash_profile for the change to take immediate effect. Thanks to this alias definition, you can now simply type grep and get color-coded results.

Setting your locale

  1. Locale is a set of parameters that defines the user's language, character encoding, region and other special variant preferences. In your OS-X, the default locale is likely set to en_US.UTF-8, which roughly means "US English, UTF-8 (unicode) encoding". You can verify this by typing:
    $ echo $LANG

  2. Yes, unicode is the present (almost) and future (most definitely) standard of character encoding, but it is not yet perfectly integrated into all aspects of computing. For the purpose of this class, in order for our various unix commands to work flawlessly, we will need to fall back to the more venerable encoding standard: ISO-8859-1.

  3. So how to set locale? You again edit the .bash_profile file in your home directory and place these lines (preferrably towards the beginning):
    export LANG=en_US.ISO-8859-1
    export LC_ALL=en_US.ISO-8859-1
    This sets your locale as en_US.ISO-8859-1: US English in ISO-8859-1 encoding.

  4. Now either execute source .bash_profile or log out and log back in. Type echo $LC_ALL and echo $LANG to verify that your locale has been successfully changed. As always, if something goes wrong with the file and you find yourself unable to log in, you should remove .bash_profile and start over by following the directions above.