Customising your bash profile for ease and efficiency - TGAC/knowledge_base GitHub Wiki

A customised bash profile can help make your personal experience of using the HPC easier and more efficient.

It is controlled by a hidden file in your home directory named ~/.bash_profile. The . at the beginning of the filename makes it invisible to a normal ls, but ls -al will show you all invisible files in a directory. ~/.bash_profile is automatically loaded when you log into the HPC and any preferences you set within it are applied to your shell environment.

One of the most useful applications of a bash profile is to set shortcuts for commands you commonly use. This can be done with alias, which allows you to attribute some command to a single word of your choosing. For instance, if you are frequently navigating to a specific project area, you can add the following line to ~/.bash_profile to avoid having to type out the whole path every time:

alias myproject='cd /ei/projects/pathtoyourprojectarea/'

Then you only have to type myproject to navigate to that directory.

If your desired functionality is more complex, involving multiple commands and running over multiple lines, instead of alias you can add this to ~/.bash_profile via a function:

function function_name {
  command1
  command2
}

Similar to an alias, you then only have to type the function name into the terminal to run the commands.

Setting up your ~/.bash_profile file

If you don't already have a ~/.bash_profile file, you can create one with nano ~/.bash_profile. Here's a basic starter template you might want to use:

alias data='cd /ei/projects/pathtoyourprojectarea/'
alias scratch='cd /ei/.project-scratch/pathtoyourscratcharea/'

Then you can simply add a new line for each feature you add.

There are endless customisations you can make. For instance, you can set up a quick shortcut to viewing what jobs you personally have running on the queue:

alias jobs='squeue -u username'

Another useful addition is a function which prints the stats for your last completed job (within the last month), which can help you optimise future jobs:

function jobstat() {
    echo "---------------------------------------"
    sacct -nXP --state CD --start now-30days --endtime now -o JobName | tail -n 1
    echo "---------------------------------------"
    sacct -nXP --state CD --start now-30days --endtime now -o jobid | tail -n 1 | xargs -n1 seff
    echo "---------------------------------------"
}

Have a search online for inspiration to optimise your ~/.bash_profile. After editing ~/.bash_profile always remember to either log out and back in to the HPC for the changes to take effect, or you can use source .bash_profile to trigger the changes.