Linux Commands Explained: Essential Commands with Examples for Beginners
Understand Linux command syntax, options and arguments through practical examples for navigation, files, permissions, processes, networking and text.
Hands-on Reference: Looking for quick syntax? Browse our complete 163 Linux Commands Cheat Sheet or practice live in your browser using our Free Online Linux Terminal Sandbox.
Why Master the Linux Command Line?
The Linux command line is the most powerful interface for interacting with any Unix-based system. For cybersecurity professionals, mastering terminal commands is not optional — it is foundational. Most security tools, servers, and hacking targets run Linux, and the command line provides precision, speed, and automation capabilities that graphical interfaces cannot match.
Below, each command category is broken down with hands-on examples, so you understand not just the syntax but why a particular tool matters in a real workflow.
How to Read Any Linux Command
Every Linux command follows the same pattern: command [options] [arguments]. Once you can read that pattern, you can understand almost any command you meet — including ones nobody has explained to you yet.
| Part | What it means | In the command ls -la /home |
|---|---|---|
| Command | The program to run | ls — list directory contents |
| Options | Flags that change behaviour, usually starting with - | -la — long format (-l) including hidden files (-a) |
| Arguments | The target the command acts on | /home — the directory to list |
A second example: in grep -r "password" /var/log, the command is grep (search text), the option -r makes it search recursively through folders, "password" is the text to find, and /var/log is where to search. Every table in this guide uses exactly this pattern — what the command does, how to write it, and a practical example of it in use.
Filesystem Navigation
Understanding the Linux filesystem hierarchy is your first step. The filesystem is a tree starting at the root directory (/).
| Command | Description | Example |
|---|---|---|
pwd | Print working directory — shows your current location | pwd → /home/user |
ls | List directory contents | ls -la shows all files with details |
cd | Change directory | cd /var/log moves to the log directory |
tree | Display directory tree | tree -L 2 shows two levels deep |
The ls -la command is particularly useful. The -l flag gives a long listing format showing permissions, owner, size, and modification time. The -a flag shows hidden files (those starting with a dot).
File Operations
Creating, copying, moving, and deleting files are everyday tasks. Use our dedicated touch command reference for timestamp modification and empty file creation.
touch file.txt # Create an empty file
cp source.txt dest.txt # Copy a file
mv old.txt new.txt # Move or rename a file
rm file.txt # Remove a file (permanently)
mkdir dirname # Create a directory
rmdir dirname # Remove an empty directory
rm -rf dirname # Remove a directory and all contents
The rm -rf command is dangerous — it recursively deletes without confirmation. Always double-check before running it. For complete option tables and safety rules, check our dedicated references for mkdir directory creation, cp file copying, mv moving and renaming, and rm safe file deletion.
Viewing File Contents
Linux provides several commands for examining file contents, each suited to different scenarios.
cat displays the entire file at once. Use less for paginated viewing of large files — press space to scroll, q to quit. head -n 20 shows the first 20 lines, while tail -n 20 shows the last 20. Compare revisions with diff, inspect file types with file, and count words or lines with wc. tail -f follows a file in real time, essential for monitoring log files.
cat /etc/passwd
less /var/log/syslog
head -50 access.log
tail -f /var/log/auth.log
File Permissions
Linux permissions control who can read, write, and execute files. Every file has three permission sets: owner, group, and others.
chmod 755 script.sh # rwxr-xr-x — owner can write, others can read/execute
chmod u+x script.sh # Add execute permission for the owner
chown user:group file # Change file owner and group
Review the complete syntax and verified option tables in our chmod permissions reference and chown ownership guide. We cover permissions in depth in the Linux File Permissions Complete Guide.
Process Management
Processes are running programs. Knowing how to inspect and control them is crucial.
ps aux # List all running processes
top # Interactive process viewer
htop # Enhanced process viewer (if installed)
kill PID # Terminate a process by ID
kill -9 PID # Force kill
pkill process_name # Kill by name
The ps aux command shows user, PID, CPU/memory usage, and the command that started each process. Explore our detailed guides on ps process listing, the interactive top system monitor, and kill signal delivery for safe process management. For system and storage diagnostics, check kernel details with uname, inspect filesystem capacity with df, and examine directory usage with du.
Network Commands
Network troubleshooting and analysis commands are essential for cybersecurity work.
ping tests connectivity to a host and measures round-trip time. netstat -tulpn shows listening ports and the programs attached to them. ss is the modern replacement for netstat. The modern ip network configuration tool replaces legacy ifconfig. ssh remote shell establishes an encrypted remote connection. curl transfers data from or to a server, while the wget network downloader retrieves remote files directly to disk.
ping -c 4 google.com
netstat -tulpn | grep LISTEN
ssh kali@192.168.1.100
curl -I https://example.com
Text Processing
Text processing commands form the backbone of log analysis and data extraction.
grep "ERROR" app.log # Search for lines containing ERROR
grep -r "password" /etc/ # Recursive search
sed 's/old/new/g' file.txt # Replace all occurrences
awk '{print $1, $3}' file # Print specific columns
sort data.txt | uniq -c # Count unique lines
wc -l file.txt # Count lines
Filter and transform data pipelines using sort, deduplicate with uniq, slice columns with cut, translate characters with tr, split streams with tee, and batch arguments with xargs. For advanced pattern matching, data extraction, and log audits, consult our verified references on grep pattern search, find filesystem search, sed stream transformation, and awk column extraction.
Compression and Archiving
tar -czvf archive.tar.gz /path # Create a gzipped tar archive
tar -xzvf archive.tar.gz # Extract it
gzip file.txt # Compress
gunzip file.txt.gz # Decompress
Package Management
On Debian-based systems like Kali Linux:
sudo apt update # Update package list
sudo apt install nmap # Install a package
sudo apt remove nmap # Remove a package
sudo apt upgrade # Upgrade all packages
apt search "web scanner" # Search for packages
Mastering these commands transforms you from a casual user into a power user. Practice each command daily, read man pages (man ls), and gradually incorporate them into your workflow.
Frequently Asked Questions
Continue Learning
100 Essential Linux Commands Every Beginner Should Know
A quick-reference cheat sheet of 100 essential Linux commands every beginner should know, organized by category with syntax, examples, and practical use cases for system administration and cybersecurity.
Linux · BeginnerCommand Line Essentials: Mastering the Terminal for Security Work
Essential command line skills for cybersecurity professionals including navigation, text processing, scripting, and automation.
Linux · IntermediateLinux Terminal Guide: Advanced Shell Skills for Professionals
Advanced Linux terminal techniques including shell customization, multiplexing, productivity tools, and scripting best practices.
Linux · BeginnerBash Scripting Basics: Automate Tasks Like a Pro
Learn Bash scripting from scratch covering variables, conditionals, loops, functions, error handling, and practical automation scripts for cybersecurity.
Related Security Tools
tcpdump
tcpdump is a powerful, lightweight command-line packet analyzer that allows users to capture, parse, and filter TCP/IP and other packets transmitted or received over a network.
Sniffing & SpoofingNetcat
Learn how to use Netcat (nc) in Kali Linux to open a TCP or UDP connection, check a port, and see what a service sends back. Follow the examples to send your first message, inspect HTTP and SMTP responses, and transfer a test file without exposing sensitive data.
Information Gatheringdig
dig (domain information groper) is a flexible tool for interrogating DNS name servers. It performs DNS lookups and displays the answers that are returned from the name server(s).
Reverse EngineeringADB
ADB, or Android Debug Bridge, is a versatile command-line tool that acts as a client-server program, facilitating communication between your development machine (the client) and an Android device (running the adbd daemon) via a server process binding TCP port 5037. It ships as part of the Android SDK Platform Tools, and on Kali Linux, it's available as the `android-tools-adb` package. ADB is the standard device bridge for Android mobile pentesting and forensics, enabling actions like deploying Frida servers, pulling APKs, and capturing detailed logcat output for analysis.