Command Line Essentials: Mastering the Terminal for Security Work
Essential command line skills for cybersecurity professionals including navigation, text processing, scripting, and automation.
Why the Command Line Matters
The command line interface is the most powerful tool in a cybersecurity professional's arsenal. While graphical interfaces are user-friendly, the terminal provides speed, automation capabilities, remote system access via SSH, and access to security tools that lack graphical equivalents.
Essential Navigation
pwd — Print working directory (where am I?)
ls — List files and directories (-l for details, -a for hidden, -h for readable sizes)
cd — Change directory (cd .. goes up, cd ~ goes home, cd - goes back)
tree — Display directory structure
File Operations
cp — Copy files (-r for directories, -v for verbose)
mv — Move or rename files
rm — Remove files (-r for directories, -f for force)
mkdir — Create directories (-p creates parent directories)
touch — Create empty files or update timestamps
Viewing and Editing Files
cat — Display entire file content
less — View files page by page (space to advance, b to go back, q to quit)
head and tail — Show first or last lines (tail -f follows a file in real-time)
nano — Simple terminal-based text editor
vim — Powerful modal editor with steep learning curve
Text Processing
grep — Search Text
grep pattern file — Search for pattern in file
grep -r pattern directory — Recursive search
grep -i — Case-insensitive search
grep -v — Invert match (show non-matching lines)
sed — Stream Editor
sed 's/old/new/g' file — Replace all occurrences of old with new
sed -n '5,10p' file — Print lines 5 through 10
awk — Text Processing Language
awk '{print $1}' — Print first column
awk -F: '{print $1, $3}' — Custom field separator
Process Management
ps aux — View all running processes
top or htop — Interactive process viewer
kill PID — Terminate process by ID
kill -9 PID — Force terminate
pkill name — Kill processes by name
pgrep name — Find process IDs by name
Network Commands
ping host — Test network connectivity
traceroute host — Trace network path
curl URL — Transfer data from/to servers
wget URL — Download files from the web
ssh user@host — Secure shell to remote system
scp file user@host:/path/ — Secure file copy
netstat -tuln — List listening ports
Shell Scripting Basics
#!/bin/bash
set -euo pipefail
# Variables
name="World"
echo "Hello, $name"
# Conditionals
if [ -f "$file" ]; then
echo "File exists"
fi
# Loops
for i in {1..5}; do
echo "Number: $i"
done
# Functions
function scan() {
nmap -sV "$1"
}
scan 192.168.1.1
Command Chaining and Redirection
&& — Run next command only if previous succeeded
|| — Run next command only if previous failed
| — Pipe output to next command
> — Redirect output to file (overwrite)
>> — Redirect output to file (append)
Terminal Multiplexers
tmux allows running multiple terminal sessions in one window:
tmux new -s session — Create new session
tmux attach -t session — Attach to existing session
Ctrl+B % — Split pane vertically
Ctrl+B " — Split pane horizontally
Mastering the command line is a career-long journey. Start with basic navigation and gradually incorporate more advanced tools as you build confidence and capability.