Learn 🧠 All Concepts (20) 🤖 What is an LLM? 📚 RAG Explained ⚡ AI Agents 💻 Run AI Locally 🇮🇳 AI in India 📖 Learn Tracks 🔧 DevOps Track ⚙️ AI Ops Track 🗺️ AI Engineer Roadmap
Tools 🔧 AI Tools Directory 🔓 Open Source AI ⭐ Top GitHub Repos ✦ Claude Skill Repos 🚀 Ready-to-Deploy Projects
Build 🏗️ Build Hub 🎯 Master Prompts 🧩 RAG Agents 🚀 App Megaprompts
Workflows ⚡ All Workflows (22) 🎥 Text to Video 🎞️ Image to Video 🔊 Text to Speech ♻️ Automation
Resources 🧪 Colab Notebooks ⚙️ n8n Workflows 📈 Algo Trading 💰 Passive Income
🗂️ Browse All Topics About AItheGuru
Learn Linux for Production Support Sameer becomes twice as fast
Linux for Production Support Ch 20 / 32 Advanced

Sameer becomes twice as fast

Aliases, history tricks, tmux, watch — terminal productivity patterns that compound

⏱ 13 min 6 commands 5 takeaways
In this chapter
Sameer
Support engineer, 7 years experience
The story

Sameer had been a support engineer for 7 years. He could solve any incident. But his solutions took 20 minutes when they could take 5. Not because he was slow — because he was inefficient. He typed the same things over and over. He searched the same log patterns from memory. He opened multiple terminals for tasks he could do in one.

A senior engineer watched him work for one day and gave him 10 productivity patterns. Three months later, Sameer was the fastest engineer on the team.

PATTERN 1: CTRL+R — SEARCH COMMAND HISTORY

The most underused terminal shortcut. Press Ctrl+R and start typing any part of a previous command. It finds the most recent match. Press Ctrl+R again to see older matches.

Ctrl+R then type: df
# Shows: df -h
Ctrl+R again:
# Shows: df -h | awk '$5+0>=90'

Never type a long command twice. Ctrl+R finds it in 2 seconds.

history | grep "grep.*ERROR"     # see all your error-searching commands
history | grep systemctl         # see all your service commands
!!                               # run the last command again
!grep                            # run the last command that started with grep
!sudo                            # run the last sudo command

PATTERN 2: ALIASES — SHORT NAMES FOR LONG COMMANDS

nano ~/.bashrc
# Add these:
alias ll='ls -lhrt'
alias la='ls -la'
alias ..='cd ..'
alias ...='cd ../..'
alias grep='grep --color=auto'
alias df='df -h'
alias free='free -h'
alias ports='ss -tlnp'
alias myip='ip addr show eth0 | grep "inet "'
alias logs='tail -f /var/log/syslog'
alias applog='tail -f /opt/app/logs/app.log'
alias errgrep='grep -C 5 "ERROR"'
source ~/.bashrc   # apply changes immediately

Now instead of typing tail -f /opt/app/logs/app.log you type applog. Instead of ss -tlnp you type ports.

PATTERN 3: SCREEN AND TMUX — SESSIONS THAT SURVIVE DISCONNECTION

If you start a long process (database migration, big log scan) and your SSH connection drops, the process dies. screen and tmux keep processes running even after you disconnect.

# Start a named session:
screen -S incident-deploy
# Detach (go back to normal terminal, process keeps running):
Ctrl+A then D
# List sessions:
screen -ls
# Reattach to a session:
screen -r incident-deploy
# tmux (more powerful, more used today):
tmux new -s deploy              # new session named 'deploy'
Ctrl+B then D                   # detach
tmux ls                         # list sessions
tmux attach -t deploy           # reattach
# tmux splits your terminal into panes:
Ctrl+B then %                   # split vertically (two side-by-side terminals)
Ctrl+B then "                   # split horizontally
Ctrl+B then arrow keys          # move between panes
Ctrl+B then Z                   # zoom in/out of current pane

Run tail -f app.log in one pane and run diagnostic commands in the other — same SSH session.

PATTERN 4: WATCH — AUTOMATIC REFRESH

Instead of pressing the up arrow and Enter every few seconds to rerun a command:

watch -n 2 'df -h'                          # refresh df every 2 seconds
watch -n 3 'ss -tnp | grep 5432 | wc -l'    # watch connection count
watch -n 5 'ps aux --sort=-%cpu | head -10'  # watch top processes
watch -n 1 'tail -5 /var/log/app.log'        # watch last 5 log lines
watch -d 'free -h'                           # highlight what changed since last refresh

PATTERN 5: PIPES AND REDIRECTS EFFICIENTLY

# See output AND save to file at the same time (tee):
./deployment.sh | tee deploy_$(date +%Y%m%d_%H%M%S).log
# You watch the output AND have a log file
# Append to a log:
echo "$(date): restarted nginx" >> /var/log/ops.log
# Redirect errors to a file, keep normal output on screen:
command 2>errors.log
# Both stdout and stderr to file:
command > all_output.log 2>&1

PATTERN 6: FIND WITH EXEC — ACT ON FOUND FILES

# Find all logs over 1GB and show their sizes:
find /var/log -size +1G -exec ls -lh {} \;
# Find all .conf files modified in last 24 hours:
find /etc -name "*.conf" -mtime -1
# Find and delete old compressed logs older than 30 days:
find /opt/app/logs -name "*.gz" -mtime +30 -delete
# Find all files NOT owned by tomcat in the app directory:
find /opt/app -not -user tomcat -ls

PATTERN 7: SORT, UNIQ, AND CUT — INSTANT DATA ANALYSIS

# Top 10 most active IPs in nginx access log:
awk '{print $1}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head -10
# Count HTTP status codes:
awk '{print $9}' /var/log/nginx/access.log | sort | uniq -c | sort -rn
# Find the 5 largest files by any user on the system:
find / -type f -printf '%s %p\n' 2>/dev/null | sort -rn | head -5
# Count lines matching a pattern per day:
grep "ERROR" app.log | cut -d' ' -f1 | sort | uniq -c

PATTERN 8: ENVIRONMENT FUNCTIONS IN BASHRC

Put your most common tasks in ~/.bashrc as functions:

# Add to ~/.bashrc:
cdlog() { cd /opt/"$1"/logs && ls -lrt; }
# Usage: cdlog myapp  — goes to /opt/myapp/logs and lists files
errcheck() { grep -C 5 "ERROR" /opt/"$1"/logs/*.log | tail -50; }
# Usage: errcheck payment  — shows last 50 errors with context
svcrestart() { sudo systemctl restart "$1" && journalctl -u "$1" -f -n 20; }
# Usage: svcrestart nginx  — restart and immediately watch logs

Three months after learning these patterns, Sameer handled incidents in half the time. He never typed the same long command twice. His terminal did the work — he did the thinking.

Key takeaways

Ctrl+R searches command history — never type a long command twice, just search for it

Aliases in ~/.bashrc turn long commands into short ones — ll, ports, applog, errcheck

tmux keeps sessions running after SSH disconnects — essential for long-running deployments

watch -n 2 'command' auto-refreshes any command — never press up-arrow and Enter repeatedly

tee saves output to a file AND shows it on screen at the same time — perfect for deployment logs

Commands from this chapter
$ Ctrl+R
Search command history — type any part of a previous command
$ alias ports='ss -tlnp'
Create a short alias for a long command in ~/.bashrc
$ tmux new -s deploy
Start a named tmux session that survives SSH disconnection
$ watch -n 2 'df -h'
Auto-refresh any command every 2 seconds
$ command | tee output.log
Show output on screen AND save to file simultaneously
$ find /opt/app/logs -name '*.gz' -mtime +30 -delete
Find and delete compressed logs older than 30 days