Quick Reference - My Linux Environment

Fast lookup guide for common tasks and commands.

Quick Start (30 seconds)

Windows:

double-click start_linux.bat
login: root
password: [press Enter]

Linux/Mac:

chmod +x start_linux.sh
./start_linux.sh

Most Common Commands

System Info

uname -a                # System info
df -h                   # Disk space
free -h                 # Memory usage
ps aux                  # Running processes

Package Management

apk update              # Update package cache
apk add vim             # Install package
apk search python       # Search packages
apk del vim             # Remove package
apk info | wc -l        # Count installed

File Operations

ls -la                  # List files
cd /path                # Change directory
mkdir dirname           # Create directory
rm -rf dirname          # Delete directory
cp file1 file2          # Copy file
mv old new              # Rename/move
cat file                # View file

Editing Files

vi file                 # Vi editor
nano file               # Nano editor
echo "text" > file      # Write to file
cat >> file             # Append to file

User & Permissions

whoami                  # Current user
id                      # User info
chmod 755 file          # Change permissions
chown user file         # Change owner
su - username           # Switch user

Services (OpenRC)

rc-service sshd start   # Start service
rc-service sshd stop    # Stop service
rc-service sshd status  # Check status
rc-update add sshd      # Enable at boot
rc-update del sshd      # Disable at boot

Quick Tasks

Install Web Server

apk update
apk add nginx
rc-service nginx start
rc-update add nginx

Install Python & Run Script

apk add python3 py3-pip
pip install flask
python3 script.py

Initialize Git Repository

apk add git
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
cd /tmp && git init myrepo

Create User Account

adduser -D newuser
passwd newuser
addgroup newuser wheel  # Add to group

Enable SSH Server

apk add openssh
ssh-keygen -A
rc-service sshd start
rc-update add sshd

Create Backup

tar -czf backup.tar.gz ~/important_data/
ls -lh backup.tar.gz

Restore Backup

tar -xzf backup.tar.gz

Permission Quick Reference

chmod 755 file          # rwxr-xr-x (executables/scripts)
chmod 644 file          # rw-r--r-- (regular files)
chmod 700 file          # rwx------ (owner only)
chmod 700 /root         # rwx------ (home dir)

# Symbolic notation
chmod u+x file          # Add execute for user
chmod g-w file          # Remove write from group
chmod o-rwx file        # Remove all from others
chmod a+r file          # Add read for all

Directory Structure Reference

/root               # Root user home directory
/home               # Regular user homes
/etc                # Configuration files
/var                # Variable data, logs
/tmp                # Temporary files
/usr                # User programs & libraries
/usr/local          # User-installed software
/opt                # Optional software
/proc               # System information (virtual)
/sys                # System configuration (virtual)
/boot               # Kernel and bootloader
/dev                # Device files
/lib                # System libraries

Search & Find

grep "pattern" file     # Search in file
grep -r "pattern" .     # Search recursively
find . -name "*.txt"    # Find by filename
find . -size +10M       # Find by size
find . -type f          # Find all files
find . -type d          # Find all directories
locate filename         # Quick find (needs database)

Process Management

ps aux                  # List all processes
ps aux | grep vim       # Find specific process
top                     # Interactive view
kill 1234               # Terminate process PID 1234
kill -9 1234            # Force kill
pkill vim               # Kill by name
jobs                    # Background jobs
fg                      # Bring to foreground
bg                      # Resume in background

Network Commands

ifconfig                # View network interfaces
ip addr show            # Alternative to ifconfig
ping 8.8.8.8           # Test connectivity
route -n                # View routing table
netstat -an             # View connections
ss -an                  # Modern alternative
nslookup example.com    # DNS lookup
curl https://example.com # Download URL
wget https://example.com/file.zip # Download file

Text Processing

sed 's/old/new/g' file  # Replace text
awk '{print $1}' file   # Print column 1
cut -d: -f1 file        # Cut field
sort file               # Sort lines
uniq file               # Remove duplicates
wc -l file              # Count lines
head -5 file            # First 5 lines
tail -5 file            # Last 5 lines
cat file | grep pattern # Pipe example

Archive Management

# TAR archives
tar -czf archive.tar.gz dir/       # Create
tar -xzf archive.tar.gz            # Extract
tar -tzf archive.tar.gz            # List

# ZIP files (if installed)
apk add zip unzip
zip -r archive.zip dir/
unzip archive.zip

Exit Codes Reference

$?                  # Variable for last exit code
0                   # Success
1                   # General error
2                   # Misuse of shell command
126                 # Command cannot execute
127                 # Command not found
130                 # Script terminated by Ctrl+C

Alpine-Specific Commands

# APK operations
apk update              # Update cache
apk upgrade             # Upgrade packages
apk add package         # Install
apk del package         # Remove
apk info                # List installed
apk search pattern      # Search
apk cache clean         # Clean cache

# Init system (OpenRC)
rc-service ssh start    # Start service
rc-update add ssh       # Boot service
/etc/init.d/ssh start   # Direct init script

# Configuration
cat /etc/alpine-release # Alpine version
cat /etc/os-release     # OS info

Keyboard Shortcuts

Terminal Shortcuts

Ctrl+A              # Start of line
Ctrl+E              # End of line
Ctrl+U              # Clear line
Ctrl+W              # Delete word
Ctrl+L              # Clear screen
Ctrl+C              # Interrupt
Ctrl+Z              # Suspend
Ctrl+D              # EOF/Exit

QEMU Shortcuts

Ctrl+A then c       # QEMU monitor
Ctrl+A then x       # Force exit
Ctrl+A then d       # Detach

Vi Editor Shortcuts

:w                  # Save
:q                  # Quit
:wq                 # Save & quit
:q!                 # Quit without save
i                   # Insert mode
Esc                 # Command mode
:set number         # Show line numbers

Environment Variables

echo $PATH              # Command search path
echo $HOME              # Home directory
echo $USER              # Current user
echo $SHELL             # Current shell
echo $PWD               # Current directory
export VAR=value        # Set variable
unset VAR               # Unset variable
env                     # Show all variables

File Type Commands

file /path              # Determine file type
file -b /path           # Type only (no filename)
head -1 /path           # First line
strings /path           # Extract readable text
od -c /path             # Dump file content
hexdump -C /path        # Hex dump

Helpful One-Liners

# Count files
find . -type f | wc -l

# Find large files
find . -type f -size +10M

# List files by size
ls -lSh

# Search and replace in multiple files
find . -name "*.txt" -exec sed -i 's/old/new/g' {} \;

# Download entire website
wget -r https://example.com

# Create numbered backup
cp file.txt file.txt.$(date +%Y%m%d_%H%M%S)

# Monitor file
tail -f logfile

# Count lines in all Python files
find . -name "*.py" -exec wc -l {} +

# Remove all empty directories
find . -type d -empty -delete

# Check disk usage per directory
du -sh *

Troubleshooting Quick Fixes

Can’t find command

apk search command
apk add package_containing_command

Permission denied

chmod +x file
sudo command  # (if sudoers configured)

Disk full

df -h                   # Check usage
du -sh /*               # Find large dirs
apk cache clean         # Clean cache

Out of memory

free -h
ps aux | sort -k4 -rn | head  # Memory hogs

Can’t connect to network

ifconfig                # Check interface
ping 8.8.8.8           # Test connectivity
cat /etc/resolv.conf    # Check DNS

APK Package Examples

# Development
apk add build-base gcc g++ make cmake

# Python
apk add python3 py3-pip py3-virtualenv

# Node.js
apk add nodejs npm

# Web servers
apk add nginx apache2 php php-fpm

# Databases
apk add mysql mariadb postgresql sqlite

# Version control
apk add git mercurial

# Text editors
apk add vim nano neovim

# Utilities
apk add curl wget rsync openssh

# System tools
apk add htop iotop tmux screen

# Security
apk add openssl gnupg ssh-tools

# Compression
apk add tar gzip bzip2 zip unzip

File Descriptor Reference

0               # Standard input (stdin)
1               # Standard output (stdout)
2               # Standard error (stderr)

Examples:
command > file  # Redirect stdout to file
command 2> error.log  # Redirect stderr
command &> file # Redirect both
command >> file # Append instead of overwrite

Performance Tips

# Speed up apk
apk add alpine-sdk

# Enable compression
export CFLAGS="-O2 -march=native"

# Use faster mirrors (if available)
vi /etc/apk/repositories

# Check available resources
free -h; df -h; nproc

Need More Help?


Last Updated: July 30, 2025 Cheat Sheet Version: 1.0

← Back to Environment Hub