Strovent SystemsSign in
Reference

Shell and tmux basics

A short list of Unix shell commands and tmux, which keeps your work running when a connection drops.

Commands you meet most on a Linux or Unix host.

Moving and looking

pwd                  where am I
ls -la               list with details, including hidden files
cd dir, cd .., cd    change folder, up, home
cat file             print a file
less file            page through a file (q to quit, / to search)
tail -f file         follow a log as it grows (Ctrl+C to stop)
head -n 20 file

Finding and changing

grep -rn "text" .    search file contents
find . -name "*.log" find files by name
cp, mv, rm, mkdir    copy, move, delete, make a folder
chmod 600 file       change permissions
chown user file      change owner

Processes

ps aux | grep name   find a process
top, htop            watch the busiest processes
kill pid             ask a process to stop (kill -9 forces it)
df -h, du -sh *      disk space

Shell keys

  • Ctrl+C interrupts the running command. Ctrl+D ends input (and logs out at an empty prompt). Ctrl+Z suspends it (fg resumes).
  • Ctrl+R searches the command history. Up recalls the last command. Tab completes names.
  • Ctrl+L clears the screen. reset repairs a garbled terminal.

tmux: keep work running

tmux runs programs inside a session on the host. If your connection drops, the programs keep running and you reattach later.

tmux new -s work       start a session called work
Ctrl+B then D          detach
tmux ls                list sessions
tmux attach -t work    reattach
Ctrl+B then C          new window
Ctrl+B then N / P      next / previous window
Ctrl+B then %          split side by side      "   split top and bottom
Ctrl+B then [          scroll and copy mode (q to leave)

screen does the same job with Ctrl+A as the prefix. If screen -r says "There is no screen to be resumed", see screen -r "There is no screen to be resumed": reattach an Attached or lost session. Over Mosh or SSH, tmux gives you a session you can resume from any device.

Spotted a mistake? Email [email protected].