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+Cinterrupts the running command.Ctrl+Dends input (and logs out at an empty prompt).Ctrl+Zsuspends it (fgresumes).Ctrl+Rsearches the command history.Uprecalls the last command.Tabcompletes names.Ctrl+Lclears the screen.resetrepairs 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.
Related
- Keys and key codes
- Alternate screen and mouse
- Mosh or SSH?
- Leaving OMVS, the z/OS UNIX shell, from a 3270 session
- Check if a shell is running over SSH, inside tmux, or inside screen
- screen -r "There is no screen to be resumed": reattach an Attached or lost session
- tmux "sessions should be nested with care, unset $TMUX to force"
- Bash prompt wraps onto the same line: mark color codes in PS1
- Script fails with "/bin/bash^M: bad interpreter" or "$'\r': command not found": Windows line endings
- Ctrl+Z and "Stopped": get the program back with fg, bg and jobs
- Ctrl+D logs you out of the shell: IGNOREEOF and ignoreeof
- Bash history lost or missing commands after SSH disconnect, tmux or several terminals