Shell cheat sheet

Modern DevOps for Systems Biologists

Author

Jun Allard

Every command here is shown, never run. Type them yourself — a cheat sheet you have not typed is a cheat sheet you cannot use under pressure.

Where am I

Command What it does
pwd print the working directory
ls -la list everything, including dotfiles, with permissions
cd - go back to the directory you were just in

TODO: add the two or three you actually use every day.

Moving things around

cp -r source/ destination/
mv old_name new_name
rm -i unwanted.txt

TODO: a sentence on why rm has no undo, and what to do instead.

Looking inside files

Command What it does
less file.txt page through a file; q quits
head -20 file.csv the first twenty lines
wc -l file.csv count the lines
grep -n "pattern" file.py find a pattern, with line numbers

TODO

Pipes and redirection

ls *.csv | wc -l
python analysis.py > results.txt 2> errors.txt
grep "ERROR" log.txt | head

TODO: the one idea — a program reads a stream and writes a stream, and the shell is what connects them.

Talking to another machine

ssh user@hpc3.rcic.uci.edu
scp results.csv user@hpc3.rcic.uci.edu:~/project/
rsync -av --progress local_dir/ user@hpc3.rcic.uci.edu:~/project/

TODO: when to reach for rsync instead of scp.

On the cluster

squeue -u $USER
sbatch job.sh
scancel JOBID

TODO: the minimum viable batch script.

Getting yourself unstuck

Situation What to type
a command is running away Ctrl-C
you want the manual man command, or command --help
you do not know where a program is which command

TODO