Keyboard

KeyAction
Tabcomplete commands and file names; press twice for the list of candidates
↑ / ↓previous / next command
Ctrl-Cstop the running command
Ctrl-Dend of input; at an empty prompt, exit the shell (logs you out of ssh)
Ctrl-Zpause the running command; fg resumes it, bg continues it in the background
Ctrl-Rsearch command history; press again for older matches
Ctrl-Lclear the screen (clear)
Ctrl-A / Ctrl-Estart / end of line
Ctrl-Udelete everything before the cursor
!!repeat the last command, as in sudo !!
!$last argument of the previous command
historylist past commands; !NUMBER reruns one
CommandAction
pwdcurrent directory
ls -lhlong listing with readable sizes; -a includes hidden files, -t sorts by modification time
cd PATHchange directory; cd alone goes home, cd .. up, cd - back to the previous one
mkdir -p a/b/ccreate nested directories in one go
cp a b, cp -r dir1 dir2copy; directories need -r
mv a bmove or rename
rm FILE, rm -r dirdelete; there is no recycle bin
*.out, h2o_?.xyzwildcards: * any number of characters, ? exactly one
find . -name '*.out'find by name, including subdirectories
du -sh *size of each item
df -hsize and free space per file system
tar czf a.tar.gz dir / tar xzf a.tar.gzbundle and compress / extract; tar tzf lists

Viewing and searching

CommandAction
less h2o.outpage through a file; /word searches, n next match, G end, q quit
head -n 20 / tail -n 20first / last 20 lines
tail -f h2o.outfollow a growing output; Ctrl-C stops
grep 'FINAL SINGLE POINT' *.outlines matching a pattern; -n line numbers, -i ignore case, -r recursive, -c count
wc -lcount lines
cmd | lesssend output to another command (pipe)
cmd > f, cmd >> fwrite output to a file (overwrite / append)
cmd 2>&1send errors to the same place
nano fedit; Ctrl-O saves, Ctrl-X exits
vim fedit; i to insert, then Esc and :wq to save and quit, :q! to quit without saving

Permissions

CommandAction
ls -l-rwxr-xr--: read, write, execute for owner / group / others
chmod +x run.shmake executable
chmod 600 fonly you can read and write (private key, ~/.ssh/config)
chmod 700 dironly you can enter (~/.ssh)
chmod -R g+r dirgive the group read access, recursively

Processes and environment

CommandAction
top, htoprunning processes, CPU and memory; q quits
ps uxyour processes
kill PID, kill -9 PIDask to terminate / force kill
cmd &run in the background; jobs lists them
nohup cmd > log 2>&1 &keep running after you log out
echo $PATHshow a variable
export OMP_NUM_THREADS=4set an environment variable (current shell and its children)
which orcawhich file a command runs
source ~/.bashrcreload your shell config

ssh and transfer

CommandAction
ssh user@host, ssh vandalog in (aliases live in ~/.ssh/config)
ssh-keygen -t ed25519create a key pair
ssh-copy-id vandainstall your public key on the server
ssh-add, ssh-add -ladd a key to the agent / list keys
ssh-keygen -R hostremove an old host key from known_hosts
ssh -v vandaverbose connection log, for troubleshooting
scp f vanda:~/dir/upload
scp vanda:~/dir/f .download; -r for directories
rsync -avhP src/ dst/sync only what changed; a trailing / on the source means "its contents"
rsync -n ...dry run: show what would be transferred
--include='*/' --include='*.out' --exclude='*'only certain extensions
--exclude='*.gbw'skip certain files

tmux

Command / keysAction
tmux new -s NAMEnew session
tmux lslist sessions
tmux attach -t NAMEreattach
tmux kill-session -t NAMEend a session
Ctrl-b ddetach
Ctrl-b c / n / pnew / next / previous window
Ctrl-b % / "split left-right / top-bottom
Ctrl-b arrowmove between panes
Ctrl-b zzoom a pane / restore
Ctrl-b [scroll (copy mode); q leaves

PBS and Slurm

TaskPBS ProSlurm
modulesmodule avail · module load NAME · module list · module purge
submitqsub run.pbssbatch run.sh
my jobsqstat -u $USERsqueue -u $USER
detailsqstat -f IDscontrol show job ID
cancelqdel IDscancel ID
interactiveqsub -I -l select=1:ncpus=4 -l walltime=1:00:00srun --cpus-per-task=4 --time=1:00:00 --pty bash
resources#PBS -l select=1:ncpus=8:mem=16gb#SBATCH --ntasks=8 --mem=16G
time#PBS -l walltime=02:00:00#SBATCH --time=02:00:00
name#PBS -N name#SBATCH --job-name=name
submission directorycd $PBS_O_WORKDIR$SLURM_SUBMIT_DIR (jobs start there by default)
output filename.o<ID>slurm-<ID>.out

Script syntax has its own page: the shell scripting cheat sheet.