Level Up Your Command Line Game

The Linux terminal is one of the most powerful tools on any operating system. Whether you're managing files, automating tasks, or administering servers, knowing a handful of clever tricks can save you hours every week. Here are fifteen tips that will make you faster and more effective in the shell.

1. Use !! to Repeat the Last Command

Forgot to run something as root? Just type sudo !! and the shell will repeat your last command with elevated privileges.

2. Jump to the Beginning or End of a Line

Press Ctrl+A to jump to the start of a line and Ctrl+E to jump to the end. Far faster than hammering the arrow keys.

3. Search Command History with Ctrl+R

Press Ctrl+R and start typing to do a reverse search through your command history. Press Ctrl+R again to cycle through matches.

4. Run Multiple Commands in Sequence

  • cmd1 ; cmd2 — Run cmd2 regardless of whether cmd1 succeeds
  • cmd1 && cmd2 — Run cmd2 only if cmd1 succeeds
  • cmd1 || cmd2 — Run cmd2 only if cmd1 fails

5. Use watch to Monitor Command Output

The watch command re-runs a command every two seconds and displays the output. Great for monitoring logs or system resources:

watch -n 1 df -h

6. Redirect Output to a File

Use > to overwrite a file and >> to append. Send errors to a separate file with 2>:

command > output.log 2> errors.log

7. Use alias for Frequently Typed Commands

Add aliases to your ~/.bashrc or ~/.zshrc:

alias ll='ls -alh --color=auto'
alias gs='git status'

8. Quickly Edit Long Commands with Ctrl+X E

This opens the current command in your default text editor (set with $EDITOR), letting you edit complex commands comfortably.

9. Use tmux for Persistent Sessions

tmux lets you split your terminal into panes, run multiple sessions, and keep processes alive even if you disconnect from SSH. Essential for remote work.

10. Find Files Quickly with fd or find

find /home -name "*.conf" -type f
fd '\.conf$' /home   # faster, friendlier alternative

11. Use grep with Colour and Context

grep -rn --color=auto "search_term" /path/to/dir

12. Quickly Navigate with cd -

Type cd - to jump back to the previous directory. Think of it as an "undo" for navigation.

13. Kill a Background Process by Name

pkill firefox

14. Check Disk Usage with du and ncdu

ncdu is an interactive, visual disk usage analyzer — much friendlier than raw du output.

15. Schedule Tasks with cron

Use crontab -e to schedule recurring scripts. Example — run a backup every day at 2am:

0 2 * * * /home/user/backup.sh

Keep Practising

The terminal rewards habit. Incorporate a few of these tricks into your daily workflow and they'll become second nature in no time.