How To Use Linux Operating System

How To Use Linux Operating System

Reading time1 min
#Linux#OperatingSystem#Technology#CommandLine#LinuxTips#ShellScripting

Mastering Linux Command Line: Unlocking Power Beyond the GUI

Shell proficiency is fundamental for anyone tasked with maintaining, securing, or scaling Linux systems—particularly under real operational pressure. Most GUIs, while reference-friendly, quickly become a bottleneck for anything beyond the most trivial administration. Commands typed in the terminal can manipulate thousands of files, traverse directories in milliseconds, and automate entire workflows with a single script.


The Imperative: Why Does the Terminal Matter?

Any system administrator facing an outage or running a multi-node Kubernetes cluster has learned—painfully, perhaps—that point-and-click tools do not scale. The CLI reduces latency between intent and action. Autocomplete (try tab) can sprint you through directory trees. Piping (|) and redirection (>, >>) enable data flows that would take hours in a GUI.

Key use cases:

  • Automating backup jobs across environments with shell scripts and cron.
  • Live troubleshooting—diagnosing processes that hang, fill up RAM, or flood /var/log with cryptic errors.
  • Remote orchestration via SSH, often with simultaneous connections (see tmux or parallel-ssh).

Practical Baseline: Navigation and File Operations

Routine file manipulations? Second nature. Below: essentials, always with flags you’ll need in prod.

pwd                 # Absolute path of working directory
ls -lhA             # List files incl. hidden, human sizes
cd /tmp/logs        # Move to specific path
cd -                # Toggle between last two locations
cd ~/..             # Home, then up one level
tree -L 2           # ASCII directory structure, 2 levels deep

Trade-off: tree may not be installed. Use apt install tree (Debian/Ubuntu) or dnf install tree (Fedora/RHEL) if necessary.
Known issue: cd .. in an NFS mount with broken parent directory can yield EACCES.

File edits and moves, explicit and atomic—avoid wildcards in scripts unless confident.

mv file.yaml file.yaml.bak            # Inline backup before edit
cp -av Projects/Archive/ ./Archive/   # Archive with mode+timestamp preserved
rm -i important_file.cfg              # Prompts before deletion

Gotcha: rm -rf is irreversible. Users have overwritten root directories with a misplaced slash—check commands before hitting Enter.


Inspecting Files: Don’t Guess, Examine

Why is a config not loading? Is a process writing junk to logs? Direct observation trumps assumptions.

less /etc/passwd                 # Scroll, search, never edit (q to quit)
head -20 /var/log/dmesg          # Initial boot logs
tail -F /tmp/app.log             # Real-time with file rotation awareness
grep ERROR /var/log/nginx/error.log | tail -n 10   # Recent application errors

Note: tail -F stays on rotated logs—tail -f does not.


Efficiency: Combining Commands and Output

Unix’s core advantage is composability. Example: Find your five largest files consuming disk in /var/tmp:

du -ah /var/tmp | sort -rh | head -n 5
  • du -ah: Disk usage, all units, human-readable
  • sort -rh: reverse, human units
  • head: restrict to desired result set

Another: Copy only .log files modified in the last 24h.

find /srv/logs -name "*.log" -mtime -1 -exec cp --parents {} /mnt/log-backup/ \;

Non-obvious tip: --parents retains directory structure—crucial for collating logs from diverse locations.


Scripting For Predictable Automation

Shell scripts codify your operational patterns. Even a minimal script improves reliability over one-off commands. A daily archive job:

~/bin/rotate-logs.sh

#!/bin/bash
SRC="/var/log/nginx"
DEST="/srv/nginx-archive/$(date +%F)"
mkdir -p "$DEST"
find "$SRC" -maxdepth 1 -name '*.log' -size +500k -exec mv {} "$DEST"/ \;
gzip "$DEST"/*.log
echo "$(date)" "Rotation complete" >> /srv/nginx-archive/rotation.log

Make executable:

chmod 750 ~/bin/rotate-logs.sh

Schedule:

# In crontab -e, 2:15am nightly
15 2 * * * /home/alex/bin/rotate-logs.sh

Note: Scripts lacking error checks (set -euo pipefail) can lead to silent failures. Add sanity checks for production use.


Remote Operations: SSH and File Transfers

Configuration drift or patching fleets—do it all from your terminal. Password-based SSH will get flagged by auditors; transition to keyed authentication early.

Connect:

ssh -p 2202 sysadmin@192.168.122.10

Key management:

ssh-copy-id -i ~/.ssh/id_ed25519.pub user@host

File transfer:

scp -C -P 2202 /local/data.iso user@host:/mnt/offsite/

Tip: -C compresses in transit.
For entire directories recurring, consider rsync -aAXHv --progress --delete instead of scp—handles deltas, permissions, and sparse files.


Diagnosis: Real-Time System Monitoring

Incident response always starts at the terminal. Realistically, you need both basic and advanced process inspection:

UtilityPurposePro tip / Limitation
topLive CPU/RAM/process viewPress M to sort by memory usage
htopEnhanced, interactiveMust install (apt install htop)
vmstat 1Memory/swapping!Rough historical view, 1s interval
iostatIO bottlenecksapt install sysstat
journalctl -xeSystemd error logsUse -u <unit> for service scope
df -x tmpfs -hIgnore tmpfs, readableDetect disk full, avoid noise

Error diagnosis:
Did a process fail?

ps -ef | grep docker
journalctl -u docker.service --since "1 hour ago"

Subtle tip: journalctl filters by time, PID, or system boot. Use --no-pager to print all.


Building Muscle Memory

Keyboard usage trumps recall lists or cheat sheets over time. Use Ctrl+R for reverse-search in history. Scripts reduce complex tasks to single commands, but be wary—opaque scripts left by previous admins are a known operational hazard.

Whenever possible:

  • Use man <command> for live references—don’t rely solely on web searches.
  • Test in a non-production VM before running destructive operations.
  • Comment your scripts with intent and required environment.

No point-and-click manager can rival the auditable, reproducible control granted by the Linux terminal. It pays dividends in reliability and scale.


Further:

  • Always keep a recovery shell open (e.g., tmux session) when operating on remote production hosts.
  • For high-scale tasks, tools such as Ansible can multiply effect—though understanding the individual commands under the hood remains critical.

The GUI is not going away, but it won't save you when the network is down, X11 crashes, or you need to reimage a host over serial. The terminal remains the backbone.