My bash aliases

This post was originally published here

If you find yourself using some commands always with the same flags, then it would make sense to define them as alieses, by putting them into your .bashrc file like this (log out and back in for it to take effect):

# .bashrc

# Put user specific aliases and functions here
alias ls='ls -al --color=auto'
alias qstat='qstat -a'
alias qsub='qsub -m abe -M'

alias disk="du * -sh | sort -h"

-a for ls shows hidden files (files that start with a dot, like .bashrc) and -l displays more information than just the file/folder names (permissions for example).

_–color=auto _colours folders, executables and symbolic links.

-a for qstat displays more information.

Both -m and -M for qsub mean messages. For -m:

b – Mail is sent at the beginning of the job.

e – Mail is sent at the end of the job.

a – Mail is sent when the job is aborted or rescheduled.

And -M is the flag before the email address(es).

The last one (I call it disk) displays the sizes of one level of subfolders and orders them too (correct ordering is done by the really cool -h option, as apposed to the numeric sort -n, which would think that 1.4GB>1.4TB).

Add up two variables of a netCDF file

This post was originally published here

NCO:ncap2 is the function to do it:

ncap2 -s 'new_var=var1+var2'

The output file will have all of the variables that exist in the input file as well as the new_var. Add -O if your input and output files are the same (overwrite).

I do not know what the -s stands for.

BUT the new_var will have the same long_name as the first variable used for summing (i.e. it could make some things a bit confusing). To change it, use a very complicated (but allegedly also very powerful) NCO:ncatted. Fortunately, its documentation has just the right example:

Change the value of the long_name attribute for variable T from whatever it currently is to “temperature”:

ncatted -a long_name,T,o,c,temperature