Skill
Linux Commands
linux-commands · current version v3
Reference and safe-usage guide for common Linux shell commands (files, processes, text, permissions, networking, disk/system info) with the gotchas that most often cause mistakes.
3 downloads · published 2026-08-10
Skill Card
- Owner: hidden -- sign in to view
- License or terms: check the skill's own repository for license details (linux-commands on GitHub).
Security Audits
- NanoInfra Scanner PASS no issues found
- VirusTotal PASS no engines flagged this file (full report)
Version history
| Version | Published | Status |
|---|---|---|
| v3 | 2026-08-10 | published |
| v2 | 2026-08-10 | published |
| v1 | 2026-08-10 | published |
Files
SKILL.md(4858 bytes)
SKILL.md
raw | preview
---
name: linux-commands
description: Reference and safe-usage guide for common Linux shell commands (files, processes, text, permissions, networking, disk/system info) with the gotchas that most often cause mistakes.
---
# Linux Commands
Practical reference for everyday Linux command-line work. Prefer the
safer/more explicit form of a command when one is listed.
## Files and directories
- `ls -la` -- list all files (including hidden) with permissions, owner, size.
- `cp -a src dst` -- copy preserving permissions/timestamps/symlinks.
- `mv src dst` -- move/rename.
- `rm -i file` -- remove with a confirmation prompt. Prefer `-i` over a bare
`rm` for anything destructive; **never** run `rm -rf` on a path built from
an unchecked variable (`rm -rf "$dir"/` when `$dir` is empty deletes `/`'s
contents relative to cwd).
- `mkdir -p a/b/c` -- create nested directories, no error if they exist.
- `find . -name "*.log" -mtime +7 -delete` -- find and delete files matching
a pattern older than 7 days. Run without `-delete` first to see what would
match.
- `du -sh *` -- size of each item in the current directory, human-readable.
- `df -h` -- disk space per mounted filesystem, human-readable.
## Text and files content
- `grep -rn "pattern" .` -- recursive search with line numbers.
- `grep -riE "pattern1|pattern2"` -- case-insensitive, extended regex, OR.
- `sed -i.bak 's/old/new/g' file` -- in-place replace, keeping a `.bak`
backup (drop `.bak` only once you've verified the result).
- `awk -F, '{print $2}' file.csv` -- print the 2nd comma-separated field.
- `head -n 50 file` / `tail -n 50 file` / `tail -f file` -- first/last
lines, or follow a growing file (logs).
- `wc -l file` -- count lines.
- `diff -u a b` -- unified diff between two files.
- `sort -u file` -- sort and remove duplicate lines.
## Processes
- `ps aux` -- every process, full listing.
- `ps aux | grep -i name` -- find a process by name (matches its own `grep`
too; add `| grep -v grep` or use `pgrep -f name` instead).
- `top` / `htop` -- live resource usage (htop is nicer if installed).
- `kill -TERM pid` -- ask a process to exit gracefully. Only use
`kill -KILL` (`-9`) if `-TERM` didn't work after a few seconds --
it skips cleanup.
- `pkill -f pattern` -- kill by command-line pattern match. Double-check the
pattern against `pgrep -f pattern` first; it's easy to match more than
intended.
- `nohup cmd &` or `setsid cmd &` -- run a command that survives the
terminal closing.
- `jobs`, `fg`, `bg` -- manage jobs in the current shell session.
## Permissions and ownership
- `chmod 644 file` -- owner read/write, group/other read-only (typical for
regular files). `755` is the equivalent for directories/executables.
- `chmod +x script.sh` -- make a file executable without touching other bits.
- `chown user:group file` -- change owner and group together.
- `sudo -n true` -- test whether passwordless sudo is available without
actually running a privileged command (useful before scripting `sudo`
into something that might otherwise hang on a password prompt).
## Networking
- `curl -sf URL` -- fetch quietly, fail (non-zero exit) on an HTTP error
instead of printing the error body as if it were the response.
- `curl -I URL` -- headers only, no body (quick status/content-type check).
- `ss -tlnp` -- listening TCP sockets with the owning process (modern
replacement for `netstat -tlnp`).
- `dig +short name` / `nslookup name` -- resolve a hostname.
- `scp file host:path` / `rsync -avz src/ host:dst/` -- copy files over
SSH; prefer `rsync` for anything resumable or repeated (only transfers
changed data).
## System info
- `uname -a` -- kernel/arch summary.
- `uptime` -- how long the system has been running, load averages.
- `free -h` -- memory usage, human-readable.
- `systemctl status name` / `journalctl -u name -f` -- a systemd service's
status, or follow its live logs.
## Gotchas worth remembering
- Always quote variables that hold paths: `"$var"`, not `$var` -- an
unquoted variable containing a space or being empty changes what a
command actually operates on.
- `cd` failing silently in a script (e.g. a typo'd path) means every
following command runs in the *wrong* directory, not that nothing
happens -- chain it as `cd "$dir" && rest-of-command`, or `set -e` in
scripts.
- Redirecting into a file you're also reading from in the same pipeline
(`sort file > file`) truncates the file before `sort` finishes reading
it, losing the data. Use a temp file or `sponge` instead.
- `sudo` re-reads `PATH` from the invoking user's environment by default
in most distros, but a script relying on `sudo some-alias` won't work --
aliases aren't inherited by non-interactive shells.