Setting up Linux

Customizing shell

  1. .bashrc is a login file that the Bash shell reads whenever it starts. This is where you can put configurations (environment variables, aliases, path amendments, etc.) to customize your Terminal experience. An example of a .bashrc file is included here. As you become more comfortable with Linux/Unix, you may find you modify this file frequently.
  2. The file should be located in your home directory (~/), and you need to create it if it does not yet exist. Open and save the file with the editor of your choice. You will not need the sudo command since this file is now in your home directory and you have write permission. If you use vi, just type vi ~/.bashrc at the prompt.
  3. Use the copy and paste commands to put the following lines into your .bashrc file.
    # Amend environment variables
    export PATH="$PATH:."
    # Set prompt
    PS1='\[\e]2;\w\a\]\u@\h:\[\e[1m\]\w\[\e[0m\]\$ '
    # User Specific Aliases
    umask 077
    export CLICOLOR=1
    alias edm='emacs --daemon'
    alias ecl='emacsclient --create-frame'
    alias enw='emacsclient -nw'
    alias grep='grep --color'
    alias less='less -Ri'
    alias la='ls -ahlF'
    alias lh='ls -hlF'
    alias rbak='\rsync -rltDzP --delete --delete-excluded --force'
    alias rsync='rsync -azP'
    alias ssh='ssh -Y'
    if [ $os_name == 'Darwin' ]; then
      alias top='top -ocpu -Otime -F -R'
    elif [ $os_name == 'FreeBSD' ]; then
      alias vi='vim -c "syntax on"';
      alias qm='qstat -u $USER'
      alias qI='qsub -I -X -V -l nodes=1:ppn=8,walltime=1:00:00 -q devel'
      alias sm='showq -u $USER'
      alias sq='squeue -o "%.18i %.9P %.30j %.8u %.2t %.10M %.6D %R"'
      alias sqm='sq -u $USER'
    alias itasca='ssh'

    The first section is where modifications to the environment variables go. An example of this is addition to the PATH used to search for executable commands. In this example, the . adds the working directory to the existing path ($PATH), so any executables you create in whatever directory you are working in can be referenced directly.

    The next section is the specification for the style of the prompt. This prompt is set to display username@hostname:/working/directory$ in bold font. It also sends the same information into the title bar of the terminal window (either Terminal or X-terminal). This is default behavior on Unix machines, but needs to be specifically configured on Mac machines. Writing information about the hostname and working directory into the title bar helps keep track of multiple windows logged in to multiple machines. For more information on setting prompts in the bash shell, search online for the bash prompt HOWTO.

    The last section contains user-specified command shortcuts. The long command, shown in quotes, is linked to whatever series of key strokes (preceding the equal sign) you specify in this file. This example includes two list commands, lh, and la. The hlF flag list files with information about their size and when they were created. The a option lists hidden files (all files that start with .). An aliased SSH connection is created to the MSI machine Itasca. When you paste these lines into your own file, be sure to change ‘username’ to your specific username. You can add your own aliases as they become more useful to you over the course of your research.

  4. Save the file and exit (:wq or :x for vi).
  5. Tell the computer to begin reading your new ~/.bashrc settings
    source ~/.bashrc


Comments powered by Disqus