Keyboard
| Key | Action |
Tab | complete commands and file names; press twice for the list of candidates |
↑ / ↓ | previous / next command |
Ctrl-C | stop the running command |
Ctrl-D | end of input; at an empty prompt, exit the shell (logs you out of ssh) |
Ctrl-Z | pause the running command; fg resumes it, bg continues it in the background |
Ctrl-R | search command history; press again for older matches |
Ctrl-L | clear the screen (clear) |
Ctrl-A / Ctrl-E | start / end of line |
Ctrl-U | delete everything before the cursor |
!! | repeat the last command, as in sudo !! |
!$ | last argument of the previous command |
history | list past commands; !NUMBER reruns one |
Navigation and files
| Command | Action |
pwd | current directory |
ls -lh | long listing with readable sizes; -a includes hidden files, -t sorts by modification time |
cd PATH | change directory; cd alone goes home, cd .. up, cd - back to the previous one |
mkdir -p a/b/c | create nested directories in one go |
cp a b, cp -r dir1 dir2 | copy; directories need -r |
mv a b | move or rename |
rm FILE, rm -r dir | delete; there is no recycle bin |
*.out, h2o_?.xyz | wildcards: * any number of characters, ? exactly one |
find . -name '*.out' | find by name, including subdirectories |
du -sh * | size of each item |
df -h | size and free space per file system |
tar czf a.tar.gz dir / tar xzf a.tar.gz | bundle and compress / extract; tar tzf lists |
Viewing and searching
| Command | Action |
less h2o.out | page through a file; /word searches, n next match, G end, q quit |
head -n 20 / tail -n 20 | first / last 20 lines |
tail -f h2o.out | follow a growing output; Ctrl-C stops |
grep 'FINAL SINGLE POINT' *.out | lines matching a pattern; -n line numbers, -i ignore case, -r recursive, -c count |
wc -l | count lines |
cmd | less | send output to another command (pipe) |
cmd > f, cmd >> f | write output to a file (overwrite / append) |
cmd 2>&1 | send errors to the same place |
nano f | edit; Ctrl-O saves, Ctrl-X exits |
vim f | edit; i to insert, then Esc and :wq to save and quit, :q! to quit without saving |
Permissions
| Command | Action |
ls -l | -rwxr-xr--: read, write, execute for owner / group / others |
chmod +x run.sh | make executable |
chmod 600 f | only you can read and write (private key, ~/.ssh/config) |
chmod 700 dir | only you can enter (~/.ssh) |
chmod -R g+r dir | give the group read access, recursively |
Processes and environment
| Command | Action |
top, htop | running processes, CPU and memory; q quits |
ps ux | your processes |
kill PID, kill -9 PID | ask to terminate / force kill |
cmd & | run in the background; jobs lists them |
nohup cmd > log 2>&1 & | keep running after you log out |
echo $PATH | show a variable |
export OMP_NUM_THREADS=4 | set an environment variable (current shell and its children) |
which orca | which file a command runs |
source ~/.bashrc | reload your shell config |
ssh and transfer
| Command | Action |
ssh user@host, ssh vanda | log in (aliases live in ~/.ssh/config) |
ssh-keygen -t ed25519 | create a key pair |
ssh-copy-id vanda | install your public key on the server |
ssh-add, ssh-add -l | add a key to the agent / list keys |
ssh-keygen -R host | remove an old host key from known_hosts |
ssh -v vanda | verbose 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 / keys | Action |
tmux new -s NAME | new session |
tmux ls | list sessions |
tmux attach -t NAME | reattach |
tmux kill-session -t NAME | end a session |
Ctrl-b d | detach |
Ctrl-b c / n / p | new / next / previous window |
Ctrl-b % / " | split left-right / top-bottom |
Ctrl-b arrow | move between panes |
Ctrl-b z | zoom a pane / restore |
Ctrl-b [ | scroll (copy mode); q leaves |
PBS and Slurm
| Task | PBS Pro | Slurm |
| modules | module avail · module load NAME · module list · module purge |
| submit | qsub run.pbs | sbatch run.sh |
| my jobs | qstat -u $USER | squeue -u $USER |
| details | qstat -f ID | scontrol show job ID |
| cancel | qdel ID | scancel ID |
| interactive | qsub -I -l select=1:ncpus=4 -l walltime=1:00:00 | srun --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 directory | cd $PBS_O_WORKDIR | $SLURM_SUBMIT_DIR (jobs start there by default) |
| output file | name.o<ID> | slurm-<ID>.out |
Script syntax has its own page: the shell scripting cheat sheet.