Master essential Linux commands and concepts for cybersecurity.
Linux is the backbone of cybersecurity for several reasons:
/ Root directory
├── bin Essential command binaries
├── boot Boot loader files
├── dev Device files
├── etc System configuration files
├── home User home directories
├── lib Shared libraries
├── opt Optional software
├── root Root user home directory
├── sbin System binaries
├── tmp Temporary files
├── usr User programs
└── var Variable data (logs, etc.)
pwd # Print working directory
ls # List files
ls -la # List all files with details
cd /path/to/dir # Change directory
cd .. # Go up one directory
cd ~ # Go to home directory
cat file.txt # Display file contents
less file.txt # View file with pagination
head -n 10 file.txt # Show first 10 lines
tail -f log.txt # Follow log file in real-time
cp source dest # Copy file
mv old new # Move/rename file
rm file.txt # Delete file
mkdir dirname # Create directory
rmdir dirname # Remove empty directory
rm -rf dirname # Remove directory recursively
Linux uses a permission system with three levels:
Three permission types:
# View permissions
ls -l file.txt
# Output: -rw-r--r-- 1 user group 1234 Jan 1 12:00 file.txt
# Change permissions
chmod 755 script.sh # rwxr-xr-x
chmod u+x script.sh # Add execute for owner
chmod go-w file.txt # Remove write for group/others
# Change ownership
chown user:group file.txt
ps aux # List all processes
top # Interactive process viewer
htop # Enhanced process viewer
kill PID # Terminate process
killall name # Kill all processes by name
bg # Send process to background
fg # Bring process to foreground
jobs # List background jobs
find / -name "*.txt" # Find files by name
find / -type f -size +100M # Find files larger than 100MB
grep "pattern" file.txt # Search for pattern in file
grep -r "pattern" /path/ # Recursive search
locate filename # Quick file search
which command # Find command location
ifconfig # Network interface configuration
ip addr show # Show IP addresses
ping host.com # Test connectivity
netstat -tulpn # Show listening ports
ss -tulpn # Modern netstat alternative
nmap target.com # Network scanning
curl https://api.com # Make HTTP requests
wget https://file.com # Download files
Debian/Ubuntu (APT)
sudo apt update # Update package lists
sudo apt upgrade # Upgrade packages
sudo apt install pkg # Install package
sudo apt remove pkg # Remove package
apt search keyword # Search for packages
Red Hat/CentOS (YUM/DNF)
sudo yum update
sudo yum install pkg
sudo dnf install pkg
cat file.txt | grep "error" # Filter lines
cat file.txt | sort | uniq # Sort and remove duplicates
awk '{print $1}' file.txt # Print first column
sed 's/old/new/g' file.txt # Replace text
cut -d',' -f1 data.csv # Extract CSV column
#!/bin/bash
# Variables
NAME="John"
echo "Hello, $NAME"
# Conditionals
if [ -f "/etc/passwd" ]; then
echo "File exists"
fi
# Loops
for i in {1..5}; do
echo "Number: $i"
done
# Functions
function greet() {
echo "Hello, $1"
}
greet "World"
sudo apt update && sudo apt upgrade/var/log/ regularlysystemctl disable serviceufw enableReady for Networking Fundamentals!