Introduction
Iβm Ahmed Khalil, a DevOps Engineering Manager with 11 years of hands-on experience in Docker, Kubernetes, Terraform, Jenkins, GitLab CI, AWS, and monitoring. This guide focuses on the practical Linux command line skills I use daily to manage servers, automate tasks, and troubleshoot production issues. Examples assume a typical GNU/Linux environment (Bash 5.x and GNU coreutils 8.x+), but the commands shown are broadly applicable across distributions.
Below youβll find clear, actionable examples for the commands most beginners need, plus slightly deeper DevOps-oriented use cases: scripted backups, safe file operations, permission hardening, and quick troubleshooting commands. Each new section maps to commands mentioned later in the Key Takeaways and FAQ, so you wonβt see any disconnected references.
ls: List directory contents
ls is the first tool youβll use to inspect directories. Useful flags you should know:
-l: long listing (permissions, owner, size, timestamp)-a: show hidden files (dotfiles)-h: human-readable sizes (with-l)--color=auto: colorize output (common in GNU coreutils)
Examples:
# detailed listing with human-readable sizes
ls -lah --color=auto
# view a specific directory sorted by modification time
ls -lt /var/log | head -n 20
Practical DevOps tip: when inspecting a package deploy folder (e.g., /var/www/html), combine ls -lt to find the most recently modified files and detect unexpected changes after deployment.
mkdir: Create directories
mkdir creates directories. Common options:
-pβ create parent directories as needed
# create nested directories in one command
mkdir -p /srv/backups/daily/2025-12-01
DevOps use-case: create structured backup paths and ensure scripts don't fail when parent folders are missing.
Managing files: cp, mv, rm, rmdir
cp (copy)
Common flags:
-rβ recursive (directories)-aβ archive; preserves attributes and is equivalent to-dR --preserve=allin GNU cp-vβ verbose
# copy a directory preserving metadata
cp -a /etc/nginx /backup/nginx-$(date +%F)
Tip: use cp -a when backing up configuration files to keep permissions intact.
mv (move / rename)
Common flags:
-iβ interactive prompt before overwrite
# rename a file or move it into a directory
mv -i release.tar.gz /srv/releases/
Use -i in scripts run interactively to avoid accidental overwrites.
rm and rmdir (remove)
Be cautious: rm is destructive. Useful options:
-rβ recursive-fβ force (no prompts)--preserve-rootβ (GNU rm default behavior) protects/
# remove an empty directory
rmdir tmpdir
# remove a directory tree interactively
rm -rI build/
Security tip: avoid running sudo rm -rf unless youβve double-checked the path. In automation, prefer safe deletion patterns (move to a quarantine directory first, then delete after verification).
Viewing and editing files: cat, less, and editors
cat and less
cat prints file contents; less is for paging large files. Combine with grep and tailing tools:
# quick view
cat /etc/hostname
# interactive paging
less /var/log/syslog
# follow a log file and highlight matches
tail -F /var/log/nginx/error.log | grep --line-buffered "ERROR"
Editing: vim, nano
Common editors on servers are vim and nano. If you must modify config files in production, use vim -R for read-only preview, then update with proper backups and reload services (e.g., systemctl reload nginx).
grep: Searching and filtering
grep is essential for finding text in files and pipelines. Useful flags:
-Rβ recursive-nβ show line numbers--color=autoβ highlight matches-Eβ extended regular expressions
# find occurrences of ERROR in logs recursively
grep -R --color=auto -n "ERROR" /var/log/
# search inside a git repo for TODO comments
grep -R --line-number -E "TODO|FIXME" src/
DevOps example: when a deployment fails, search recent logs across multiple services to find the root cause quickly. Combine grep with xargs or find -exec for powerful automated searches.
File permissions: chmod and chown (practical guide)
Understanding permissions prevents accidental exposure of secrets and avoids permission-related outages.
Permission basics
Three classes: user (u), group (g), others (o). Three permissions: read (r), write (w), execute (x).
# human-readable view
ls -l /etc/nginx/nginx.conf
# -rw-r----- 1 root www-data 1234 Jan 1 12:00 nginx.conf
In this example, owner is root, group www-data. Only owner and group have read access.
chmod numeric examples
# give owner read/write, group read, others none
chmod 640 /etc/nginx/nginx.conf
# make a script executable by owner
chmod 700 /usr/local/bin/deploy.sh
chown usage
# change owner to deploy user and group to deploy
chown deploy:deploy /srv/releases/current
# change ownership recursively
chown -R deploy:deploy /srv/releases/
Best practice for sensitive config files: set ownership to a dedicated user (not root when possible), restrict mode to 640 or 600, and keep secrets out of world-readable files. In CI/CD pipelines, avoid committing credentials; instead use secret managers (e.g., Vault, AWS Secrets Manager) and mount them at runtime.
man pages and inline help
Use man to read manual pages; many commands also support --help for a quick summary.
# full manual
man ls
# quick help
ls --help
When you need authoritative documentation for shell builtins, refer to the Bash manual or project pages for tools (search the project root domain such as https://www.gnu.org/ or https://www.linux.org/).
System info & process management: top, ps, htop
top
top shows live resource usage. Use it to spot CPU or memory hogs quickly.
top
# press M to sort by memory, P to sort by CPU
ps + grep
Use ps with grep to locate processes in automation or scripts.
# find Java processes
ps aux | grep java | grep -v grep
htop
htop provides a friendlier UI (if available). On minimal servers you may prefer ps and top to avoid installing extra packages.
Troubleshooting example
When a service consumes excessive memory, inspect running processes, note the PID, and collect a stack or logs. Example workflow:
# identify top memory consumer
ps aux --sort=-%mem | head -n 10
# sample logs for that service
journalctl -u my-service -n 200 --no-pager
Tips for mastering the command line: shortcuts & resources
Shortcuts that save time
- Ctrl + R β reverse-i-search through history
- Ctrl + A / Ctrl + E β move to start/end of line
- Tab β autocomplete filenames/commands
- !! β repeat last command;
sudo !!runs last command with sudo
# edit crontab for current user
crontab -e
# sample daily backup at 02:00
0 2 * * * /usr/local/bin/daily-backup.sh
Recommended resources
- Interactive learning platforms (e.g., Codecademy) for foundational practice
- Project and reference pages: https://www.gnu.org/ and https://www.linux.org/
- Cheat sheets (local copies in your dotfiles) β keep one for quick reference in servers
Key Takeaways
ls,cd, andmkdirare fundamental for navigating and organizing files; learn useful flags likels -lahandmkdir -p.- Use
cp -aandmv -ifor safe file operations; avoidrm -rfwithout safeguards. - Understand and correctly set file permissions with
chmodand ownership withchownto protect secrets and prevent outages. grepandlesslet you find and inspect relevant data in logs and codebases quickly.- Use
manand--helpfor command-specific details and keep a local cheat sheet for environments without external access.
Frequently Asked Questions
- What are the essential Linux commands for beginners?
- Start with
ls,cd,pwd,mkdir,cp,mv,rm,cat,less,grep,chmod,chown, andman. This guide includes dedicated sections for each. - How do I check file permissions?
- Use
ls -lto view permissions and ownership. Adjust withchmod(numeric or symbolic) andchownto set correct owner/group. For sensitive configs, usechmod 600or640depending on access needs. - Can I automate tasks with the command line?
- Yes. Create shell scripts and schedule them with
cronor run them from CI pipelines (e.g., GitLab CI). Example backup script included below for a safe automated workflow.
Example: safe daily backup script
#!/bin/bash
# /usr/local/bin/daily-backup.sh
set -euo pipefail
BACKUP_DIR="/srv/backups/$(date +%F)"
mkdir -p "$BACKUP_DIR"
# archive /etc/nginx safely preserving attributes
tar -czf "$BACKUP_DIR/nginx-$(date +%F).tar.gz" -C / etc/nginx
# optional: upload to remote storage with AWS CLI v2 (ensure CLI is configured)
# aws s3 cp "$BACKUP_DIR/nginx-$(date +%F).tar.gz" s3://my-backups/nginx/
Note: ensure scripts run under a dedicated user with minimal privileges and that credentials for remote uploads are managed securely (avoid hardcoding).
Conclusion
These commands form the practical toolkit youβll use every day. Beyond basic usage, focus on safe defaults (verify paths, preserve metadata when copying, limit permissions on config files), automation best practices (idempotent scripts, scheduled jobs), and troubleshooting workflows (logs + grep + process inspection). With these skills youβll be able to manage services, debug incidents, and automate routine tasks reliably.
For further reading and authoritative references, consult project root documentation such as https://www.gnu.org/ and https://www.linux.org/. Start small: implement one scripted backup, and iterate from there.