Before you start to learn AI, know this!

Ultimate Unix/Linux Command Cheat Sheet

Introduction

Many users, especially beginners, struggle with AI tutorials and managing their Unix/Linux environments. To help my non-tech friends, I’ve compiled this Unix/Linux cheat sheet. It’s okay not to know everything—just keep it handy!


1. Installing & Updating Linux

🌟 WSL Installation on Windows (Using PowerShell)

wsl --install  # Enable WSL
wsl --list --online  # List available Linux distributions
wsl --install -d Ubuntu  # Install a specific distribution
wsl --set-default-version 2  # Set default WSL version to 2
wsl --update  # Update WSL kernel

🖥️ ISO Installation on Virtual Machines

  1. Download the Linux ISO from the official site.
  2. Install Oracle VirtualBox or VMware.
  3. Create a new virtual machine and allocate resources.
  4. Mount the ISO and follow the installation steps.

2. Package Management

📦 Install & Update Packages

Ubuntu/Debian (APT)

sudo apt update && sudo apt install <package>

RHEL/CentOS (YUM)

sudo yum update && sudo yum install <package>

Arch Linux (Pacman)

sudo pacman -Syu <package>

OpenSUSE (Zypper)

sudo zypper install <package>


3. Virtual Environments & Containers

🐍 Python Virtual Environments

python -m venv myenv  # Create a virtual environment
source myenv/bin/activate  # Activate
pip install -r requirements.txt  # Install dependencies
deactivate  # Deactivate

🐳 Docker

docker pull ubuntu  # Pull an image
docker run -it ubuntu bash  # Run a container interactively
docker ps  # List running containers
docker stop <container_id>  # Stop a container

🏗️ Kubernetes

kubectl get pods  # List running pods
kubectl describe pod <pod_name>  # Get details of a pod
kubectl apply -f deployment.yaml  # Deploy an application


4. Basic Navigation & File Management

pwd  # Show current directory
ls -lah  # List files (including hidden files)
cd /path/to/directory  # Change directory
mkdir new_folder  # Create directory
rmdir old_folder  # Remove empty directory
cp file.txt backup.txt  # Copy files
mv oldname.txt newname.txt  # Rename/move files
rm -r directory_name  # Remove directory and contents


5. Viewing & Editing Files

cat file.txt  # Display file contents
less file.txt  # View file with scrolling support
head -n 10 file.txt  # First 10 lines
tail -f logfile.txt  # Live log monitoring

✍️ Text Editors

nano file.txt  # Simple editor
vim file.txt  # Advanced editor


6. Text Processing & Searching

grep 'pattern' file.txt  # Search for a pattern
sed 's/old/new/g' file.txt  # Replace text
awk '{print $2}' file.txt  # Extract column data
find . -name "*.conf"  # Find files by name
zgrep 'ERROR' /var/log/*.gz  # Search in compressed files
sort file.txt | uniq  # Sort and remove duplicates

7. File Permissions & Ownership

chmod 755 script.sh  # Set file permissions
chown user:staff file.txt  # Change ownership


8. Process & Job Management

ps aux  # List running processes
top  # Monitor system resources
kill 1234  # Terminate a process
jobs  # List background jobs
fg %1  # Bring job 1 to foreground


9. System Monitoring

df -h  # Disk space usage
du -sh /var/log  # Directory size
free -m  # Memory usage
uptime  # System uptime


10. Networking & Internet Utilities

ping google.com  # Check connectivity
traceroute google.com  # Trace route to a host
curl -I https://example.com  # Fetch HTTP headers
ssh user@remote.server.com  # Secure remote login


11. Compression, Archiving & Backup

tar -czvf archive.tar.gz /path/to/directory  # Create tar.gz archive
zip -r archive.zip /path/to/folder  # Create zip archive
rsync -avz source/ destination/  # Sync files between locations


12. Shell Scripting & Automation

#!/bin/bash
for file in *.txt; do
  echo "Processing $file"
done

🕒 Scheduled Tasks

crontab -e  # Edit cron jobs
0 2 * * * /path/to/backup.sh  # Run script daily at 2 AM


13. Version Control with Git

git clone <repo_url>  # Clone a repository
git status  # Check repository status
git add . && git commit -m "Commit message" && git push  # Save changes


14. Cybersecurity & System Hardening

🔍 Network Scanning

nmap -sV --script=vuln target_ip  # Scan for vulnerabilities
masscan -p1-65535 target_ip --rate=1000  # High-speed port scan

🛡️ Process & File Monitoring

chkrootkit  # Check for rootkits
rkhunter --check  # Rootkit scan
watch -n 2 'netstat -anp'  # Monitor live network connections


15. Advanced Automation Techniques

📊 Real-Time Monitoring

watch -n 2 'free -m'  # Monitor memory usage every 2 seconds
ls *.py | entr -r pytest  # Run pytest when files change

⚡ Parallel Processing

ls *.txt | parallel 'grep "error" {} > {}.errors'  # Run tasks in parallel


Leave a comment