The command line is an indispensable tool for anyone working in cybersecurity. Here’s a comprehensive guide to essential Linux commands and concepts.
File System Navigation
Basic Commands
# Change directory
cd /path/to/directory
# List files and directories
ls -la
# Print working directory
pwd
# Create directory
mkdir new_directory
# Remove file or directory
rm file.txt
rm -rf directory/
File Manipulation
Working with Files
# View file contents
cat file.txt
less file.txt
head -n 20 file.txt
tail -f logfile.log
# Search within files
grep "pattern" file.txt
grep -r "pattern" /directory/
# Find files
find / -name "filename"
find / -type f -size +100M
# Copy and move
cp source.txt destination.txt
mv old_name.txt new_name.txt
User and Permissions
Managing Permissions
# Change file permissions
chmod 755 script.sh
chmod +x executable
# Change file ownership
chown user:group file.txt
# View permissions
ls -l file.txt
Understanding Permission Notation
r(4): Readw(2): Writex(1): Execute
Example: chmod 755 = rwxr-xr-x (owner: rwx, group: r-x, others: r-x)
Process Management
# View running processes
ps aux
top
htop
# Kill a process
kill PID
kill -9 PID # Force kill
# Run process in background
command &
# View background jobs
jobs
# Bring to foreground
fg %1
Network Commands
Essential Network Tools
# Check network interfaces
ip addr
ifconfig
# Test connectivity
ping 8.8.8.8
ping -c 4 google.com
# DNS lookup
nslookup domain.com
dig domain.com
# Network connections
netstat -tuln
ss -tuln
# Download files
wget https://example.com/file.zip
curl -O https://example.com/file.zip
Text Processing
Powerful Text Manipulation
# Search and replace
sed 's/old/new/g' file.txt
# Pattern processing
awk '{print $1}' file.txt
# Sort and unique
sort file.txt
uniq file.txt
sort file.txt | uniq -c
# Count lines, words, characters
wc -l file.txt
Piping and Redirection
Combining Commands
# Pipe output to another command
cat file.txt | grep "error" | wc -l
# Redirect output to file
command > output.txt
command >> output.txt # Append
# Redirect error output
command 2> error.log
command &> all_output.log
System Information
# Disk usage
df -h
du -sh /path/
# Memory usage
free -h
# System information
uname -a
cat /etc/os-release
# Uptime and load
uptime
Security-Specific Commands
Useful for Security Work
# Check open ports
sudo netstat -tulpn
sudo ss -tulpn
# View system logs
sudo tail -f /var/log/syslog
sudo journalctl -f
# Check failed login attempts
sudo cat /var/log/auth.log | grep "Failed"
# View active network connections
sudo lsof -i
# Check for setuid binaries
find / -perm -4000 2>/dev/null
Tips for Efficiency
- Use Tab Completion: Press Tab to auto-complete file names and commands
- Command History: Use
historyto see previous commands,!123to run command 123 - Aliases: Create shortcuts for common commands in
~/.bashrc - Learn Vim or Nano: Essential for editing files on remote systems
Useful Aliases
alias ll='ls -lah'
alias update='sudo apt update && sudo apt upgrade'
alias ports='sudo netstat -tulpn'
Conclusion
Mastering these commands will significantly improve your efficiency and effectiveness as a security professional. Practice regularly and explore the man pages (man command) to learn more about each tool’s capabilities.
Remember: With great power comes great responsibility. Always ensure you have proper authorization before running commands on systems.