# Show current directory
pwd
 
# Change directory
cd [path]
 
# List files and directories
ls -la [path]
 
# Locate a file
locate [filename]
 
# Find files based on conditions
find [path] [options] [tests] [actions]

File Manipulation

touch filename.txt
cp [options] [source] [dest]
mv [options] [source] [dest]
rm [options] [path]
 
# Count lines in a file
wc -l file.txt
 
# Sort file contents
sort -u file.txt -o newfile.txt
 
# Find duplicate lines
uniq -i -c file.txt
 
# Identify file type
file filename.extension
 
# Remove pattern from file
sed -i '/pattern/d' file.txt
 
# Remove blank lines
sed '/^$/d' file.txt > output.txt
 
# All in one
sed '/^$/d' hashes_clean | sort | uniq
 
# Remove ANSI formatting
sed -e 's/\x1b\[[0-9;]*m//g' file.txt
 
# Print specific columns from file
awk '{print $1,$4}' file.txt
 
# Convert Windows to Linux format
dos2unix filename.txt
 
# Search for a string in a file
grep -i 'string' file.txt
 
# Find the same string(s) in two files
grep -Fxf file1.txt file2.txt
comm -12 <(sort file1.txt) <(sort file2.txt)
sort file1.txt file2.txt | uniq -d

Mount Network Shares

# Mount an NFS share
mount -t nfs -o soft 192.168.1.1:/sharename /local/target/dir
 
# Unmount an NFS share
umount 192.168.1.1:/sharename

Tools & Package Management

# Install packages (Debian-based)
apt-get install [package]
 
# Update package lists and upgrade
apt-get update -y && apt-get upgrade --full-upgrade -y
 
# Install packages (RedHat-based)
yum install [package]
 
# Clone a repository
git clone https://github.com/path/to/repo [directory]
 
# Install a Python package
pip install [package]
 
# Install a Ruby gem
gem install [package]
 
# Install a Go package
go install [package]

Downloading & Networking

# Download a file with curl
curl http://some.url --output some.file
 
# Count lines in HTTP response
curl -s http://example.com | wc -l
 
# Download with redirect handling
curl -JLO http://example.com/file.zip
 
# Download a file with wget
wget http://example.com/file.zip

Environment Variables

# Show all environment variables
env
 
# Display system-wide environment variables
cat /etc/environment
 
# Set an environment variable
export VARIABLENAME=value1,value2
 
# Remove an environment variable
unset VARIABLENAME
 
# Reload environment variables
while read -r env; do export "$env"; done < /etc/environment

System Management

Basics

# List running processes
ps aux
 
# Kill a process
kill -9 [PID]
 
# Show system uptime
uptime
 
# Show system information
uname -a
 
# Show memory usage
free -m

Disk Space Management

# Show disk space usage for all mounted filesystems
df -h
 
# Show disk usage for a specific directory
du -sh /path/to/dir
 
# Show block device info (size, mount points)
lsblk
 
# Display detailed partition information
fdisk -l
 
# Show inodes usage (to check inode exhaustion)
df -i
 
# Check current swap usage
swapon --show
 
# Add new swap file
fallocate -l 2G /swapfile && chmod 600 /swapfile && mkswap /swapfile && swapon /swapfile
 
# Persist swap across reboots
echo '/swapfile none swap sw 0 0' >> /etc/fstab
 
# Resize a partition (e.g. after expanding VM disk in hypervisor)
parted /dev/sdX resizepart [partition_number] [END]
 
# Resize filesystem (ext4)
resize2fs /dev/sdXn
 
# For LVM-based setups: resize PV, LV, then filesystem
pvresize /dev/sdX
lvextend -l +100%FREE /dev/mapper/volname
resize2fs /dev/mapper/volname
 

Networking

# Display network configuration
ip a
 
# Display active network connections
netstat -tulnp
 
# Test network connectivity
ping -c 4 [host]
 
# Trace route to a host
traceroute [host]
 
# Resolve a domain name
dig [domain]

History & Cleanup

bash

# One-liner cleanup and exit
unset HISTFILE && rm -f ~/.bash_history && history -c && exit
 
# Prevent writing to history file in current session
unset HISTFILE
 
# Disable history for session
export HISTSIZE=0
export HISTFILESIZE=0

zsh

# One-liner cleanup and exit
unset HISTFILE && rm -f ~/.zsh_history && fc -R && exit
 
# Prevent writing to history file in current session
unset HISTFILE