The 12 Linux commands that cover 90%
Stage 1 · Lesson 1 · 20 minutes · Requires Stage 0
The one-line answer
You do not need to "learn Linux." You need about twelve commands, and you will pick up the rest as you need them.
Why you should care
Almost every server on the internet runs Linux. Every security tool assumes you can use a terminal. Every CTF challenge, every SOC console, every cloud instance — terminal.
Beginners treat this as a mountain and spend months on tutorials before touching security. That is backwards. Learn the twelve commands below, then learn the rest by needing them.
How it actually works
The mental model
A Linux system is a tree of directories starting at /. You are always standing somewhere in that tree, and commands act relative to where you stand.
/ root of everything
├── home/ user directories
│ └── priya/
├── etc/ configuration files
├── var/ logs, changing data
│ └── log/
├── tmp/ temporary files, world-writable
└── root/ the root user's homeThree of these matter enormously in security: /etc holds configuration including user accounts, /var/log holds the logs that record what happened, and /tmp is writable by everyone which makes it an attacker's favourite landing spot.
The twelve
1. pwd — where am I?
pwd
/home/priya2. ls — what is here?
ls # names only
ls -l # long format: permissions, owner, size, date
ls -la # include hidden files (those starting with .)ls -la is the one you will type most. Hidden files are where secrets live — .env, .ssh, .bash_history, .git.
3. cd — move
cd /var/log # absolute path
cd logs # relative to here
cd .. # up one level
cd ~ # your home directory
cd - # back to previous directory4. cat — print a file
cat /etc/passwdFine for short files. For long ones use less (arrow keys to scroll, q to quit).
5. grep — find text
This is the most important command in the list.
grep "error" app.log # lines containing "error"
grep -i "error" app.log # case-insensitive
grep -r "password" /etc/ # search recursively through a directory
grep -n "failed" auth.log # show line numbers
grep -v "healthcheck" app.log # invert: lines NOT matchingA SOC analyst's day is substantially grep against log files.
6. find — locate files
find / -name "*.conf" 2>/dev/null # by name, hide errors
find /home -type f -mtime -1 # modified in last 24 hours
find / -perm -4000 -type f 2>/dev/null # SUID binariesThat last one is a privilege escalation staple — Lesson 2 explains exactly why.
The 2>/dev/null discards permission-denied noise so you can read the results.
7. cp, mv, rm — copy, move, delete
cp file.txt backup.txt
mv old.txt new.txt # also how you rename
rm file.txt
rm -r directory/ # recursiverm does not ask and does not use a recycle bin. Be careful.
8. mkdir and touch — create
mkdir -p projects/labs/stage1 # -p creates parent directories
touch notes.md # create empty file9. chmod and chown — permissions and ownership
Covered properly in Lesson 2. For now:
chmod +x script.sh # make executable
chmod 644 file.txt # rw-r--r--10. ps and kill — processes
ps aux # all running processes
ps aux | grep nginx # find a specific one
kill 4821 # terminate by PID
kill -9 4821 # forceps aux on a compromised machine tells you what is actually running — including things that should not be.
11. curl and wget — talk to the network
curl https://example.com # fetch a page
curl -I https://example.com # headers only
curl -v https://example.com # verbose: full exchange
curl -X POST -d "user=admin" https://... # send a POSTYou met curl in Stage 0. It is your primary tool for interacting with web applications outside the browser.
12. man — read the manual
man grepEvery command documents itself. Press q to exit. Knowing man exists means you never need to memorise flags.
The pipe — the idea that ties it together
| sends the output of one command into the next.
cat auth.log | grep "Failed password" | wc -lRead that left to right: print the log, keep only failed-password lines, count them. That is a real security query — how many failed logins are in this file.
More examples:
ps aux | grep ssh # find ssh processes
ls -la /var/log | grep -i error # error files in log dir
cat access.log | grep "404" | head -20 # first 20 not-found requestsOther pieces you will meet constantly:
| Command | Does |
|---|---|
head -n 20 | first 20 lines |
tail -n 20 | last 20 lines |
tail -f app.log | follow a log live |
wc -l | count lines |
sort | sort lines |
uniq -c | count duplicates (needs sorted input) |
awk '{print $1}' | print the first field of each line |
cut -d: -f1 | split on : and take field 1 |
The classic log analysis one-liner:
cat access.log | awk '{print $1}' | sort | uniq -c | sort -rn | headThat prints the top IP addresses by request count. If one address has 40,000 requests and everyone else has 12, you have found something.
Redirection
command > file.txt # write output to file (overwrites)
command >> file.txt # append
command 2>/dev/null # discard errors
command &> all.txt # capture output and errorsSee it yourself
If you are on Windows, install WSL — open PowerShell as administrator and run wsl --install. Mac and Linux users already have a terminal.
Run these in order:
pwd
ls -la
cd /etc
ls -la | head -20
cat /etc/passwd
cat /etc/passwd | cut -d: -f1
cat /etc/passwd | wc -lThat last sequence listed every user account on the system and counted them. /etc/passwd is readable by everyone — that is by design, and it is the first file an attacker reads after gaining any access, because it enumerates the users worth targeting.
Then try:
history # commands you have run
cat ~/.bash_history | tail # the same, stored on diskAttackers read .bash_history on compromised machines for exactly this reason. People type passwords into commands.
How attackers abuse this
Enumeration after a foothold. The first commands run after breaking into a machine are almost always whoami, id, uname -a, ls -la /home, cat /etc/passwd. It is reconnaissance, using nothing but built-in tools.
Living off the land. No malware needs uploading if curl, bash and python are already installed. Defenders call this LOTL, and it is difficult to detect because the tools are legitimate.
Reading what was left behind. .bash_history, .env files, config files with credentials, SSH keys in ~/.ssh/. Enormous numbers of real compromises escalate purely by reading files the previous admin forgot about.
Log tampering. An attacker with write access to /var/log deletes or edits the record of their entry. This is why serious environments ship logs off the machine immediately.
/tmp as a workspace. World-writable, often executable, frequently excluded from monitoring. Payloads land there.
Common mistakes
"I need to master Linux before starting security." No. You need these twelve commands. Depth comes from use, not from a course you finish first.
"sudo for everything." Running as root hides permission problems you should be learning from, and one typo becomes unrecoverable.
Not reading the error. Linux errors are usually precise. Permission denied and No such file or directory are different problems with different fixes. Lesson 10 of Stage 0 applies here.
Fearing the terminal. Nothing you type in a lab VM cannot be rebuilt. Break things deliberately.
Check yourself
- What does
cat auth.log | grep "Failed" | wc -ltell you, and why would a defender run it? - Why is
/etc/passwdreadable by all users, and why do attackers read it immediately? - What does
find / -perm -4000 -type f 2>/dev/nulllook for, and why does the2>/dev/nullmatter?
Answers
- It counts the lines in
auth.logcontaining "Failed" — in practice, the number of failed login attempts. A defender runs it to spot brute-force activity: a handful of failures is normal, several thousand is an attack.
- Many programs need to map user IDs to usernames, so the file is world-readable by design. Passwords are not stored there — they are in
/etc/shadow, which is not world-readable. Attackers read/etc/passwdbecause it enumerates every account on the system, revealing which users exist, which have shells, and therefore which are worth targeting.
- It searches the whole filesystem for files with the SUID bit set — binaries that run with their owner's privileges rather than the caller's. Misconfigured SUID binaries are a classic privilege escalation route.
2>/dev/nulldiscards the flood of "permission denied" errors from directories you cannot read, leaving only usable results.
Your lab
Challenge 09 — Log file investigation
An alert fired overnight. Use grep on a real-looking auth.log to find which account was brute-forced, and from where. This is the core loop of a SOC analyst's day.
When you finish Lesson 2, come back for Challenge 06 — Navigate a Linux filesystem.
→ Open Stage 1 labs
Summary in your language
தமிழ் சுருக்கம் (Tamil summary)
Linux-ஐ முழுவதும் கற்க வேண்டாம் — 12 commands போதும்
இணையத்தில் உள்ள பெரும்பாலான server-கள் Linux-ல் தான் இயங்குகின்றன. எனவே terminal பயன்படுத்தத் தெரிந்திருக்க வேண்டும். ஆனால் மாதக்கணக்கில் Linux course படிக்க வேண்டிய அவசியமில்லை.
முக்கியமான directory-கள்:
/etc— configuration files, user accounts/var/log— logs (என்ன நடந்தது என்ற பதிவு)/tmp— அனைவரும் எழுதக்கூடியது (attacker-கள் விரும்பும் இடம்)
12 commands:
pwd— நான் எங்கே இருக்கிறேன்?ls -la— இங்கே என்ன இருக்கிறது (மறைந்த files உட்பட)cd— இடம் மாறுதல்cat— file-ஐ படித்தல்grep— உரையைத் தேடுதல் ← மிக முக்கியம்find— file-களைக் கண்டுபிடித்தல்cpmvrm— நகலெடு, நகர்த்து, அழிmkdirtouch— உருவாக்குதல்chmodchown— அனுமதிகள்ps auxkill— இயங்கும் processescurl— network-உடன் பேசுதல்man— கையேடு படித்தல்
Pipe (|) — இதுதான் முக்கிய யோசனை
ஒரு command-ன் output-ஐ அடுத்த command-க்கு அனுப்புவது:
cat auth.log | grep "Failed password" | wc -lஇதன் பொருள்: log-ஐ படி → தோல்வியடைந்த login-களை மட்டும் எடு → எத்தனை என்று எண்ணு.
இது ஒரு உண்மையான security query — brute force தாக்குதல் நடந்ததா என்று கண்டறிய இதைத்தான் பயன்படுத்துவார்கள்.
பாதுகாப்பில் ஏன் முக்கியம்?
ஒரு system-க்குள் நுழைந்த attacker முதலில் செய்வது: whoami, id, cat /etc/passwd, ls -la /home. இவை எல்லாம் ஏற்கனவே இருக்கும் commands — தனியாக எந்த tool-ம் தேவையில்லை. இதை living off the land என்பார்கள்.
.bash_history file-ஐ படித்தால் முந்தைய user எந்தெந்த commands ஓட்டினார் என்று தெரியும் — சில நேரங்களில் password உட்பட.
முக்கிய அறிவுரை: lab VM-ல் எதையும் உடைக்க பயப்படாதீர்கள். மீண்டும் உருவாக்கிக்கொள்ளலாம்.
हिंदी सारांश (Hindi summary)
पूरा Linux सीखने की ज़रूरत नहीं — 12 commands काफ़ी हैं
इंटरनेट के ज़्यादातर server Linux पर चलते हैं। इसलिए terminal आना ज़रूरी है। लेकिन महीनों तक Linux course करने की ज़रूरत नहीं है।
ज़रूरी directories:
/etc— configuration files, user accounts/var/log— logs (क्या हुआ इसका रिकॉर्ड)/tmp— सब लिख सकते हैं (attackers की पसंदीदा जगह)
12 commands:
pwd— मैं कहाँ हूँ?ls -la— यहाँ क्या है (छिपी files सहित)cd— जगह बदलनाcat— file पढ़नाgrep— text खोजना ← सबसे महत्वपूर्णfind— files ढूँढनाcpmvrm— कॉपी, move, deletemkdirtouch— बनानाchmodchown— अनुमतियाँps auxkill— चल रही processescurl— network से बात करनाman— manual पढ़ना
Pipe (|) — यही मुख्य विचार है
एक command का output अगली command को भेजना:
cat auth.log | grep "Failed password" | wc -lमतलब: log पढ़ो → सिर्फ़ failed logins छाँटो → गिनो कितने हैं।
यह एक असली security query है — brute force हमला हुआ या नहीं, यह जानने के लिए यही इस्तेमाल होता है।
सुरक्षा में क्यों ज़रूरी है?
किसी system में घुसने के बाद attacker सबसे पहले यही चलाता है: whoami, id, cat /etc/passwd, ls -la /home। ये सब पहले से मौजूद commands हैं — कोई अलग tool चाहिए ही नहीं। इसे living off the land कहते हैं।
.bash_history पढ़ने से पता चलता है कि पिछले user ने कौन-कौन सी commands चलाईं — कभी-कभी password भी उसमें मिल जाता है।
ज़रूरी सलाह: lab VM में कुछ भी तोड़ने से मत डरिए। दोबारा बना सकते हैं।
Want this summary in Malayalam, Telugu, Kannada or another language? Tell us — the most requested languages get added next.
What's next
You can move around a system. Now: who is allowed to do what, and how that goes wrong.
→ Lesson 2: Files, permissions and users