LESSON 21 · BEGINNER5 min read

Linux Command-Line Essentials

Navigate the filesystem, read files, combine commands with pipes, and investigate a system without a graphical interface.

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

By the end, you’ll be able to…

  • Navigate the Linux filesystem and use absolute and relative paths confidently.
  • Create, inspect, search, and archive files from the shell.
  • Combine commands with pipes and redirection to answer investigative questions.
  • Use manual pages and safe habits to discover commands without guessing.

01The Shell Is an Investigative Workspace

Linux is everywhere in security work: servers, cloud instances, containers, network appliances, and the security distributions you will use in labs. A graphical desktop is convenient, but the shell is where you inspect configuration, correlate logs, automate repetitive work, and recover a system that will not boot into a desktop.

A shell reads a command, expands arguments, and asks the operating system to run a program. Commands are usually small programs that do one thing well. The power comes from composition: list a directory, filter the output, sort it, count it, and write the result to a file. You are not memorising hundreds of tools. You are learning a small grammar for asking questions.

The prompt usually shows your username, hostname, and current directory. The tilde character represents your home directory. A hash may indicate a root shell, although the prompt is configurable and should never be trusted as proof of identity. When in doubt, run whoami and id.

navigate.shShell
pwdwhoamiidls -lacd /var/logpwdls -lhcd ~pwdman ls
Outputstdout
/home/analyst
analyst
uid=1000(analyst) gid=1000(analyst) groups=1000(analyst),27(sudo)
total 48
drwxr-xr-x 2 analyst analyst 4096 Nov  1 09:00 .
drwxr-xr-x 4 root    root    4096 Nov  1 08:00 ..
-rw-r----- 1 root    adm     8123 Nov  1 09:10 auth.log
/home/analyst

02Files, Paths, and Redirection

Every file has a path. An absolute path starts at the root directory, such as /etc/ssh/sshd_config. A relative path starts from your current directory, such as ssh/sshd_config or ../logs/auth.log. The dot represents the current directory, two dots represent the parent, and a leading slash represents the filesystem root.

Redirection changes where input and output go. The > operator overwrites a file, >> appends, < reads from a file, and 2> redirects errors. A pipe, written as |, sends the output of one command into another. These operators are the backbone of log analysis and evidence collection. They also demand care: a misplaced > can erase a file before you have read it.

Text tools are the security analyst's everyday instruments. cat displays a file, less pages through it, head and tail show the beginning or end, grep finds matching lines, sort orders them, uniq removes adjacent duplicates, wc counts, cut selects columns, and awk handles structured text. find locates files by name, size, or permission. tar creates archives for evidence or backups.

log-triage.shShell
# Count failed SSH logins by source address.sudo grep "Failed password" /var/log/auth.log \  | awk '{print $(NF-3)}' \  | sort | uniq -c | sort -nr | head# Find world-writable files under /etc.find /etc -type f -perm -0002 2>/dev/null# Archive a directory with a timestamp, preserving permissions.stamp=$(date +%Y%m%d-%H%M%S)tar -czf "notes-$stamp.tar.gz" /home/analyst/notes# Read a long file safely, one screen at a time.less /var/log/syslog
Outputstdout
     18 203.0.113.77
      4 198.51.100.22
      1 192.0.2.45
(no world-writable files found)

03Searching With Purpose

A search is only useful when you know what question you are asking. 'Find suspicious activity' is too broad. 'Which source addresses failed authentication more than ten times in the last hour?' is testable. Start with the log source, choose the field that identifies the actor, filter the event type, aggregate, and sort.

grep supports regular expressions, but a fixed string is often safer and faster. Use grep -F for literal text, grep -i for case-insensitive matching, and grep -r for recursive search. The -n flag adds line numbers, which helps when you need to cite evidence. For structured logs, jq is more reliable than ad-hoc text slicing. For CSV, Python's csv module handles quoting correctly.

Record the command and its output when you find something important. A terminal scrollback is not evidence. Save the query, the timestamp, the source file, and the result. If the log rotates, the evidence may disappear. Defensive work depends on being able to explain how you reached a conclusion.

structured-search.shShell
# Literal search with line numbers.grep -nF "Accepted publickey" /var/log/auth.log | tail -20# Case-insensitive search for a username.grep -in "analyst" /var/log/auth.log | head# Parse JSON logs one object per line.jq -r 'select(.event.action == "login" and .event.outcome == "failure") | [.source.ip, .user.name] | @tsv' \  /var/log/app/events.jsonl | sort | uniq -c | sort -nr# Inspect file metadata.stat /etc/passwdfile /usr/local/bin/tool
Outputstdout
12:34:56 Accepted publickey for analyst from 10.10.10.20 port 51234
     42 203.0.113.77  admin
      7 198.51.100.22  analyst

04Build Muscle Memory Safely

You become fluent by typing commands, not by reading them. Start with a small daily drill: create a directory tree, move files, inspect permissions, search a log, and archive the result. Then explain each command out loud. If you cannot explain a flag, remove it and see what changes.

Use tab completion, history search with Ctrl-R, and the manual pages. Avoid running as root unless the task requires it. Prefer read-only commands when investigating. Before a destructive action, ask what the command will delete or overwrite, whether you have a snapshot, and how you would recover.

The command line rewards precision. A missing space, a wildcard in the wrong place, or an unquoted variable can turn a harmless read into a destructive write. That is not a reason to avoid the shell. It is a reason to slow down, use quotes, test in a lab, and keep notes. The same discipline will make you effective during an incident when speed matters.

LET IT CLICK

The ideas worth keeping.

  • The shell is a composition language: small tools connected by pipes answer larger questions.
  • Absolute and relative paths behave differently; know where you are before you write or delete.
  • grep, awk, sort, uniq, find, and jq are core investigative tools.
  • Read-only investigation, snapshots, and saved evidence protect you from expensive mistakes.
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: Answer a question with a pipeline

Write a command pipeline that finds the five most frequent source IP addresses in a log file named access.log. Assume each line contains the client IP as the first whitespace-separated field. Explain what each stage does.

Explore a worked solution
one_possible_solution.mdCybersecurity
awk '{print $1}' access.log | sort | uniq -c | sort -nr | head -5

awk extracts the first field (the client IP). sort groups identical addresses together. uniq -c counts adjacent duplicates. sort -nr orders the counts numerically from highest to lowest. head -5 prints the top five.

Each tool does one small job. The pipeline is easier to inspect and modify than a single complex script.

02

Exercise 2: Find exposed files

Write a read-only command that lists files under /etc that are world-writable. Explain why world-writable configuration files are a security concern.

Explore a worked solution
one_possible_solution.mdCybersecurity
find /etc -type f -perm -0002 2>/dev/null

World-writable files can be modified by any local user. If a configuration file, script, or service definition is world-writable, an attacker with a low-privileged account may be able to change behaviour, persist, or escalate privileges. The 2>/dev/null suppresses permission-denied noise; it does not change the search.

The permission bit 0002 is the world-write bit. Use read-only commands during an audit and record the output before making changes.

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 / 4 answered
01What does the pipe operator | do?
02Which command shows a file one screen at a time and allows scrolling?
03What does the path ../logs/auth.log mean?
04Why is saving the command and output important during an investigation?

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.