The secret language shared only between you & your terminal
This is the fun part. alias is the bash functionality that allows you to create your own "keyboard shortcuts." (Just like how you can set "tm" to be replaced by "tomorrow" when texting on your phone.) Your only limit here is your imagination. Setting convenient aliases is your chance to prove how truly lazy you and how powerful of commands you can execute with as few keys as possible. My mantra for aliases is: "if you have to type it several times in one day, you should consider making a script or alias for it."
First off, I have some examples of several ssh shortcuts in case you work on multiple computers:
alias razor="ssh trr007@sample.computer.edu"
alias trestles="ssh trr007@dummy.hpc.edu"
alias pinnacle="ssh trr007@another.example.edu"
alias newcluster="ssh trr007@more.ddns.examples.edu"
If you don't use ssh, feel free to delete these commands.
Similarly, these commands are for folks who work on multiple computers/HPCs as well:
if [[ $HOSTNAME = razor-l[123] ]] || [[ $HOSTNAME = compute???? ]]; then # WORKS FOR razor-l1 -l2 -l3 & HPC NODES.
alias qi_raz12="qsub -I -l walltime=00:30:00 -q tiny12core -l nodes=1:ppn=12"
alias qi_raz16="qsub -I -l walltime=00:30:00 -q tiny16core -l nodes=1:ppn=16"
alias qi_raz01="qsub -I -l walltime=00:30:00 -q tiny16core -l nodes=1:ppn=1"
alias qi_block12='read arg; qsub -I -q tiny12core -l nodes=$arg:ppn=12'
alias qi_block16='read arg; qsub -I -q tiny16core -l nodes=$arg:ppn=16'
elif [[ $HOSTNAME = pinnacle-l? || $HOSTNAME = c???? ]]; then # IF ON PINNACLE HPC. REQUIRES DOUBLE BRACKETS.
alias qi_comp04="srun -N 1 -n 4 --pty bash"
alias qi_comp16="srun -N 1 -n 16 --pty bash"
alias qi_comp32="srun -N 1 -n 32 --pty bash"
alias qi_condo32="srun -N 1 -n 32 --constraint fwang --pty bash"
alias qi_condo04="srun -N 1 -n 4 --constraint fwang --pty bash"
alias qi_condo01="srun -N 1 -n 1 --constraint fwang --pty bash"
alias pjob="~/scripts/ahpcc_slurmjob_watcher.sh"
else # IF NOT ON A RAZOR OR PINNACLE, USE TRESTLES SCRIPTS.
alias qi_tres01="qsub -I -l walltime=00:30:00 -q q30m32c -l nodes=1:ppn=1"
alias qi_tres32="qsub -I -l walltime=00:30:00 -q q30m32c -l nodes=1:ppn=32"
alias qi_block="read arg; qsub -I -l nodes=$arg:ppn=32"
fi
Those commands are defining different shortcuts depending on which computer you ssh-ed onto. If you really want to know, the qsub and srun commands are examples of my frequently-used interactive-job-generation requests for PBS and SLURM, respectively. (At my grad school, we had HPCs named "razor", "pinnacle", and "trestles".)
These commands modify or improve the behavior of the bash commands you type 1,000 times per day:
alias clear='clear; ls'
alias ~='cd ~; clear'
alias cls='clear'
alias mv='mv -i'
alias ll='ls -lrth'
alias la='ls -aF'
I particularly like the alias for clear. Just try it.
These are a few custom commands to create:
alias p='cd ../'
alias blank="for ((i=0;i<60;i++)); do echo ; done"
alias diffy='diff -y -W 200'
Full credit for the p alias goes to Prof. Charles Edwin Webster. I've never met anyone else who knew this alias, but I've introduced it to several people. Changing cd ../ into the single key p saves you more time than you'll ever know. You're welcome.
blank just artificially cleans up your screen. Sometimes this is needed to help clean up your reasoning powers too.
diffy will never be used alone, but along with two other arguments, e.g. diffy file1 file2. Learn to use diff first, but diffy will save you all the extra typing. The diffy alias also has a superpower in conjunction with another script I wrote.
A very cool set of commands for selective printing I found somewhere on the internet, which each mean "print column #N":
alias pcol1="awk '{print \$1}'"
alias pcol2="awk '{print \$2}'"
alias pcol3="awk '{print \$3}'"
alias pcol4="awk '{print \$4}'"
alias pcol5="awk '{print \$5}'"
alias pcol6="awk '{print \$6}'"
alias pcol7="awk '{print \$7}'"
alias pcol8="awk '{print \$8}'"
alias pcol9="awk '{print \$9}'"
alias pcol10="awk '{print \$10}'"
alias pcol11="awk '{print \$11}'"
alias pcol12="awk '{print \$12}'"
Maybe pcol 1-12 is overkill; just define however many you use. Here's an example of what these lines do.
I often find that I'd like to do some basic calculations right in my terminal. And remember, I'm lazy. I've found a valuable way to carry out some very simple (floating point) math (addition, subtraction, multiplication) without needing to reach for my handheld calculator, phone, or (heaven forbid) load python:
alias math='read arg; echo "$arg" | bc -l'
Just entering math will then await your simple math input. E.g. try 2*3.14 or 10 - 3 - 5.2 - 12.7.
This is my command for "log this directory to my to-do list reminder file." Depending on your shell/OS/computer, one of the two of these commands may/may not work for you:
alias logdir='echo `pwd` >> ~/CHECK_THESE.log' #IF COMMAND BREAKS, TRY DOUBLE QUOTES; MAY DEPEND ON SHELL TYPE.
#alias logdir="dir=`pwd`; echo \$dir >> ~/CHECK_THESE.log"
This command turned out to be a lifesaver for me in grad school while I was working on several projects at once. I often found myself doing science in several different directories at very different places on the computer; and it can be hard to remember the exact locations of each. Before going home each day, simply type logdir wherever you're working, and that directory location gets written to your ~/CHECK_THESE.log file (even if you don't have that file yet.) This .log file then becomes a helpful list of all the places you need to resuming working in tomorrow!
These two lines are designed to work with a very special set of scripts I wrote to help you with notetaking (scientists, read "lab notebook"):
#alias lastnote='last=`ls -1rt | grep note_ | tail -n 1`; emacs $last'
#alias lastnotecat='last=`ls -1rt | grep note_ | tail -n 1`; cat $last'
They're commented out here, because they won't behave properly unless you're using my notetaking scripts and workflow, described here.