LESSON 09 · BEGINNER10 min read

Your First 30 Terminal Commands

Learn the commands that cover navigation, files, text, permissions, packages, services, and networking, and build the habit of reading output before acting.

OWASP Top 10 · MITRE ATT&CK · NIST CSF 2.0Free to readModule 3 of 14
YOUR NEXT SMALL WINS

By the end, you’ll be able to…

  • Navigate the filesystem and read the information in ls output.
  • Create, copy, move, search, and read files without losing data.
  • Explain permissions, sudo, package management, and service control.
  • Inspect addresses, sockets, processes, and web requests from the terminal.

01A Terminal Is a Conversation

A terminal is a text interface. The program that reads your commands is the shell; on Ubuntu and Kali the default is usually Bash. The prompt shows your user, host, and current directory, but it is only a hint. Run whoami and pwd when identity or location matters.

A command has a program name, options, and arguments. In ls -la /var/log, ls is the program, -la combines two options (all and long), and /var/log is the argument. Options change behaviour; arguments say what to act on. Linux is case-sensitive: Logs, logs, and LOGS are different names.

Paths are either absolute, starting at /, or relative, starting at your current directory. The tilde means your home directory, a single dot means here, and two dots mean the parent directory. cd /var/log is absolute; cd log is relative. cd - returns to the previous directory.

Read the output. ls -la prints permissions, link count, owner, group, size, modification time, and name. A leading d means directory, a leading hyphen means regular file, and l means symbolic link. The entries named . and .. are the current and parent directories.

Use man and --help before guessing. man ls opens the manual; press q to quit and / to search. ls --help prints a shorter summary. Manual pages are divided into sections: section 1 is user commands, section 5 is file formats, and section 8 is administration. man 5 passwd explains the file, not the command. history shows previous commands, Ctrl-R searches them, and the up arrow recalls the last one. Tab completion reduces typing errors.

02Files and Text: Create, Copy, Read, Search

Create and move with intent. mkdir -p lab/notes/2026 creates parent directories as needed. touch notes.md creates an empty file or updates its timestamp. cp notes.md backup/ copies a file; cp -r folder backup/ copies a directory recursively. mv old.md new.md renames a file; mv file folder/ moves it. rm deletes. rm -i asks first, rm -r removes a directory, and rm -rf removes without asking. There is no recycle bin in the terminal, and a wildcard in the wrong place can erase more than you intended.

Read files without flooding the screen. cat prints a whole file, which is fine for short notes and bad for a 50,000-line log. less pages through a file; use the arrow keys, / to search, and q to quit. head -n 20 shows the first 20 lines; tail -n 20 shows the last 20; tail -f follows a growing log until you press Ctrl-C. These commands are read-only and safe in almost any situation.

Search with the right tool. grep finds lines that match a pattern: grep -n adds line numbers, grep -i ignores case, grep -r searches directories, and grep -F treats the pattern as literal text instead of a regular expression. find searches for files by name, type, size, or permission. find . -type f -name '*.log' finds log files under the current directory; find /var/log -type f -size +10M finds large logs.

Combine commands with pipes and redirection. A pipe sends the output of one command into another: grep 'Failed password' /var/log/auth.log | wc -l counts matching lines. Add sort and uniq -c to group repeated values, then sort -nr to put the largest count first. Redirection writes output to a file: > overwrites, >> appends, 2> redirects errors, and 2>&1 sends errors to the same place as normal output. Test redirection with harmless commands before using it on evidence.

Archives keep evidence and notes together. tar -czf notes.tar.gz notes/ creates a compressed archive, tar -xzf notes.tar.gz extracts it, and tar -tzf notes.tar.gz lists the contents without extracting. List an archive before extracting it when you did not create it; a tar file can contain absolute paths or unexpected files.

03Permissions, Packages, and Services

Every file has an owner, a group, and permission bits for the owner, group, and everyone else. chmod changes permissions. Numeric mode is easiest to read: 600 means read and write for the owner only, 644 means read for everyone and write for the owner, and 755 adds execute for directories and programs. Symbolic mode is clearer for small changes: chmod u+x script.sh adds execute for the owner. chown changes ownership and usually needs sudo, as in sudo chown analyst:analyst notes.md.

sudo runs one command with elevated privileges. It is not a magic prefix to add when a command fails. Use it for package installation, service management, and files you genuinely cannot access. Running a whole shell as root increases the damage from a typo. Read the command, confirm the path, and use the least privilege that works.

apt manages packages on Debian and Ubuntu. sudo apt update refreshes the list of available packages; it does not upgrade anything. sudo apt install nmap installs a package and its dependencies. sudo apt upgrade installs available updates. apt search and apt show help you find the right package name and read its description before installing. Read the list of packages apt proposes to remove before you type Y.

Services are long-running programs managed by systemd. systemctl status ssh shows whether the service is active, its main PID, and recent log lines. sudo systemctl start ssh starts it now; sudo systemctl enable --now ssh starts it and makes it start at boot. systemctl list-units --type=service --state=running shows what is running. A service that is enabled is not necessarily running, and a service that is running is not necessarily healthy.

Processes: ps aux lists every process with user, PID, CPU, memory, start time, and command. top gives a live view; press q to quit. kill sends a signal. kill -TERM PID asks a process to shut down cleanly; kill -9 PID forces it and should be a last resort. Check the PID from ps or top before killing anything; a wrong PID can end a critical service. sudo ss -tulpn lists listening TCP and UDP sockets with the owning process.

first-commands.shShell
# Navigationpwdls -lacd ~/lab-notesmkdir -p scans/2026-11 archivecd -# Files and texttouch notes.mdcp notes.md notes.backup.mdmv notes.backup.md archive/cat notes.mdless /var/log/sysloghead -n 5 notes.mdtail -n 5 notes.mdgrep -n "lab" notes.mdfind . -type f -name "*.md"# Pipelines and redirectiongrep "Failed password" /var/log/auth.log | wc -lls -la > listing.txtls /missing 2> errors.txt# Permissionschmod 600 notes.mdsudo chown analyst:analyst notes.md# Packages and servicessudo apt updatesudo apt install -y nmapsystemctl status sshps aux | grep sshtopkill -TERM 4242sudo ss -tulpn# Networkingip aping -c 4 10.10.10.20curl -I http://10.10.10.20wget http://10.10.10.20/file.txttar -czf notes.tar.gz notes/ssh analyst@10.10.10.20man lshistory | tail -n 20
Outputstdout
/home/analyst/lab-notes
total 12
drwxr-xr-x 4 analyst analyst 4096 Nov  1 10:15 .
drwxr-xr-x 3 analyst analyst 4096 Nov  1 10:14 ..
drwxr-xr-x 2 analyst analyst 4096 Nov  1 10:15 archive
drwxr-xr-x 2 analyst analyst 4096 Nov  1 10:15 scans
-rw-r--r-- 1 analyst analyst    0 Nov  1 10:15 notes.md
     12
Active: active (running) since Sun 2026-11-01 10:02:14 UTC
tcp   0   0 0.0.0.0:22   0.0.0.0:*   LISTEN   812/sshd

04Networking: Addresses, Ports, and Requests

ip a shows interfaces and addresses. lo is the loopback interface at 127.0.0.1, used for local communication. Private address ranges are 10.0.0.0/8, 172.16.0.0/12, and 192.168.0.0/16. Your lab uses 10.10.10.0/24. ip route shows the routing table and the default gateway. If the default route points at your home router while you are supposed to be isolated, stop and fix the network before running tools.

ping -c 4 10.10.10.20 sends four ICMP echo requests. Replies prove basic reachability, but a lack of replies does not prove a host is down; a firewall may block ICMP. Use several checks: ping, a listening service with ss, and an HTTP request with curl. Record which check you used and what it proves.

ss -tulpn lists listening sockets: -t for TCP, -u for UDP, -l for listening, -p for process, and -n for numeric addresses. Use sudo when process names are hidden. This is how you answer what a machine is exposing without a port scanner. Read the local address and port columns; 0.0.0.0 means all interfaces, while 127.0.0.1 means localhost only.

curl makes HTTP requests. curl -I http://10.10.10.20 sends a HEAD request and prints the status line and headers. curl -s saves noise, curl -o file saves the body, and curl -v shows the request and response in detail. Headers can include cookies, tokens, and server versions, so treat captured output as sensitive. wget downloads files and is convenient for mirrors and large files. Neither tool is an attack by itself, but both can reach out of the lab if the network is misconfigured.

ssh analyst@10.10.10.20 opens an encrypted remote shell. The first connection asks you to verify the host key fingerprint; in a lab, compare it with the guest's own key if you want to practise. Type exit to close the session. scp copies files over SSH. Use SSH keys instead of passwords when you can. Never reuse a real password in a lab, and never connect to a host you do not own.

05Build Confidence With Manuals and History

The manual is part of the toolkit. man command opens the full page; command --help prints a short usage summary; info command sometimes has more detail. Read the name, synopsis, description, options, examples, and see also sections. If a flag is not in the manual, do not assume it exists because a blog post used it.

Read errors literally. No such file or directory means the path is wrong. Permission denied means your user lacks permission, not that the file is corrupt. Command not found means the program is not installed or not in PATH. Check with command -v name and type name. After a command runs, echo $? prints its exit status; 0 usually means success, but a scanner can exit 0 with zero findings.

Practise in a snapshot. Before a destructive command, ask what it deletes, whether you have a copy, and how you would recover. Keep a notebook with the command, the output, and your interpretation. Use history to review what you did, but do not rely on it as a log; it can be cleared and it may not record everything. For real evidence, use script or tee.

Fluency comes from repetition, not memorisation. Drill a few commands each day: navigate, create a file, search a log, check a service, inspect a socket, and archive your notes. Explain each command out loud. If you cannot explain a flag, remove it and observe the difference. That habit will keep you safe when a command is copied from the internet.

LET IT CLICK

The ideas worth keeping.

  • A command is a program, options, and arguments; read the output before running the next one.
  • Pipes and redirection turn small commands into repeatable investigations.
  • Permissions, sudo, packages, and services are controlled changes, not guesswork.
  • Networking commands answer different questions: address, route, listener, request, and remote access.
TURN UNDERSTANDING INTO SOMETHING YOU CAN DO

Make it yours.

Type and test your code right here in the interactive workspace. Run your solution, check the output, and compare with the worked guide when ready.

01

Exercise 1: Create and inspect a notes tree

Using only the terminal, create a lab-notes directory with notes, scans, and archive subdirectories. Add a file, copy it, move the copy, restrict its permissions, and then list and find the files to prove the result.

Explore a worked solution
one_possible_solution.mdCybersecurity
mkdir -p ~/lab-notes/notes ~/lab-notes/scans ~/lab-notes/archive
cd ~/lab-notes
touch notes/day1.md
cp notes/day1.md archive/day1.md
mv archive/day1.md archive/day1-copy.md
chmod 600 notes/day1.md
ls -la notes archive
find ~/lab-notes -type f -name '*.md'

mkdir -p creates the whole tree in one step. cp leaves the original, mv renames or moves, and chmod 600 makes the note readable and writable only by its owner. The final find proves where the files ended up.

02

Exercise 2: Answer a question with a pipeline

A lab Ubuntu host is running SSH. Write commands that list listening TCP ports, show SSH processes, count failed-password lines in /var/log/auth.log, and show the five source addresses with the most failures. Explain what each command proves.

Explore a worked solution
one_possible_solution.mdCybersecurity
sudo ss -tulpn
ps aux | grep -i ssh
grep -c 'Failed password' /var/log/auth.log
grep 'Failed password' /var/log/auth.log | awk '{print $(NF-3)}' | sort | uniq -c | sort -nr | head -n 5
ip -brief address

ss shows what is listening, ps shows running processes, and the grep pipeline counts and groups authentication failures. The address field position can vary between log formats, so check one line before trusting awk. ip confirms which interface the service is bound to.

A SMALL QUESTION. A USEFUL NEXT STEP.

What stayed with you?

Check the ideas while they’re fresh. Your answers stay in this page and feedback appears as you go.

A LITTLE ACTIVE RECALL0 / 3 answered
01Which command lists all files, including hidden ones, with permissions, owners, and sizes?
02What does chmod 600 notes.md allow?
03What does sudo apt update do?

Keep exploring.

The official references behind this lesson, when you want a second angle or the full details.

One lesson closer.

Reading is a start. Trying it yourself makes the connection.

Completion is saved in this browser. It records reading and hands-on practice progress.