Caltech Home > Caltech HPC Homepage > Documentation > FAQ > How do I modify my shell environment?
Search

# How do I modify my bash environment?

You may want to change the way things look and  act when you log into the system.  You can make all sorts of changes to make things easier for you to use the cluster

#### What can I change?

Pretty much anything!  Many people will change their prompts, the colors things display in, their paths to make launching things easier, aliases to make commands easier to run, default editors, etc.

Here we will discuss things that many people prefer to change

##### Making It look the way i want
colorize "ls"

One popular setting is to colorize the output of the "ls" command so that different file types show up differently.  Luckily the authors of ls have already thought of it and have an option to do just that:

ls --color=auto

To make this happen whenever you run it, you can make it an alias:

alias ls="ls --color=auto"

Setting the prompt

Many people like to change there shell prompt to give them useful information.  Most common choices are showing the hostname, username, or directory you are in, which is default on the central cluster.  This can be changed by setting the "PS1" variable to whatever you want.  To set it to  "[username@hostname directory]$" you would set it as follows: export PS1="[\u@\h \W]\$"

Here are the most common things people put into there prompt:

• \d    The date, in "Weekday Month Date" format (e.g., "Tue May 26").
• \h    The hostname, up to the first ‘.’.
• \H   The hostname.
• \t   The time, in 24-hour HH:MM:SS format.
• \T  The time, in 12-hour HH:MM:SS format.
• \A  The time, in 24-hour HH:MM format.
• \u  The username of the current user.

export PATH=/home/user/bin:$PATH #### How do i make them permanent? Everything mentioned so far takes place in the shell you are running in. This is a good way to test things. For example, if you change you path in shell and can no longer run commands, just close the shell and open a new one. You probably, however, want these changes to take place in all shells you open. To do this, you will add the commands to one of 2 files. Either the ".bash_profile" or ".bashrc". These files are in you home directory. Notice that they both have a "." in front of them. This hides the files in a normal listing. ##### Which one? Depends on what kind of shell you want it for. There are login shells which are typically used interactively, and non login shells which get called from scripts and the like. A good sign it is a login shell is if you had to provide a password to get it. Typically, when you login into the cluster, you will be in a login shell. These shell use the .bash_profile. This is a great place to put prompt changes and colorization options. When not logging in and authenticating, you would usually get a non login shell. These read the .bashrc file. This can be confusing when running scripts, using screen, or in your jobs. In addition, non-login shells occur any time you run a script that uses bash. Non-login shells read from the .bashrc file. For most users You will want to have the .bash_profile read in the .bashrc. When doing this, paths set in .bashrc should also be set in a login shell. The default files you get when first logging in are set to do just that. If for some reason you delete it, you can add the following to the top of your .bash_profile to get the behaviour back if [ -f ~/.bashrc ]; then source ~/.bashrc fi #### Putting is all together .bash_profile:  # .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/.local/bin:$HOME/bin
PS1="[\u@\h \W]\\$"
EDITOR=nano
export PATH PS1

.bashrc

# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi

# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=

# User specific aliases and functions
# colorize ls"
alias ls="ls --color=auto"
# long listing in ls
alias ll="ls -l --color=auto"