===============================================
LINUX COMMAND LINE REFERENCE GUIDE
===============================================
Last Updated: October 13, 2025
Linux Command Structure: Command name + Options + Arguments
*Linux commands are case sensitive
===============================================
BASIC FILE VIEWING COMMANDS
===============================================
cat --> Display contents of file
cat -n [Link] --> Display with line numbers
less [Link] --> View large files (scrollable, press 'q' to quit)
more [Link] --> View file page by page
head [Link] --> Display first 10 lines
head -n 20 [Link] --> Display first 20 lines
tail [Link] --> Display last 10 lines
tail -n 15 [Link] --> Display last 15 lines
tail -f [Link] --> Follow file in real-time (logs)
===============================================
DIRECTORY NAVIGATION
===============================================
pwd --> Print working directory
ls --> List all files
ls -a --> List including hidden files
ls -l --> Long format with details
ls -alh --> All files, human-readable
ls -alht --> Sorted by modification time
ls -alhtr --> Reverse sort by time
cd . --> Current directory
cd .. --> Parent directory
cd / --> Root directory
cd ~ --> Home directory
cd - --> Previous directory
tree --> Directory structure as tree
Path Types:
cd /home/user/Documents --> Absolute path (from root)
cd Documents --> Relative path (from current location)
===============================================
CALENDAR COMMANDS
===============================================
ncal --> Current calendar
ncal 2022 --> 2022 calendar
ncal july 2022 --> July 2022 calendar
ncal november 2000 -w --> Show week numbers
ncal november 2000 -w -M --> Calendar starts Monday
ncal april 2003 -wM --> -w and -M together
cal --> Display calendar
cal March 2024 --> Specific month/year
===============================================
FILE AND FOLDER CREATION
===============================================
mkdir movies --> Create folder
mkdir comedy action horror --> Create multiple folders
mkdir -p kids/animation/2010 --> Create nested directories
touch [Link] --> Create empty file
touch 'a [Link]' --> File with spaces
touch [Link] [Link] --> Create multiple files
===============================================
FILE OPERATIONS
===============================================
cp [Link] [Link] --> Copy file
cp -r folder1 folder2 --> Copy directory recursively
cp -i file1 file2 --> Prompt before overwrite
mv [Link] [Link] --> Rename file
mv [Link] /path/to/dir/ --> Move file
rm [Link] --> Remove file
rm -r directory --> Remove directory recursively
rm -i [Link] --> Prompt before deletion
rm -f [Link] --> Force remove without prompt
rmdir empty_folder --> Remove empty directory only
===============================================
FILE INFORMATION
===============================================
stat [Link] --> Display all file statistics
file [Link] --> Show file type
wc [Link] --> Count lines, words, characters
wc -l [Link] --> Count lines only
wc -w [Link] --> Count words only
wc -c [Link] --> Count characters only
===============================================
TIMESTAMPS
===============================================
ls -l --> Show modification time
ls -lc --> Show change time (rename, permissions)
ls -lu --> Show last access time
===============================================
MANUAL PAGES & HELP
===============================================
man command_name --> Display manual page
man cat --> Manual for cat
man mkdir --> Manual for mkdir
whatis command_name --> Brief description
whereis sudo --> Locate binary, source, manual
===============================================
TEXT EDITORS
===============================================
nano [Link] --> Open in nano editor
Nano Shortcuts:
Ctrl + O --> Save file
Ctrl + X --> Exit editor
Ctrl + Up/Down --> First/Last line
Ctrl + E --> End of line
Ctrl + A --> Start of line
Alt + G --> Go to line number
Ctrl + Shift + C --> Copy to clipboard
Ctrl + Shift + V --> Paste from clipboard
Alt + ^ --> Copy the line
Ctrl + K --> Cut a line
Ctrl + U --> Paste
Alt + U --> Undo
Ctrl + W --> Search
Ctrl + \ --> Replace
vim [Link] --> Open in vim editor
Vim Basic Commands:
i --> Insert mode
Esc --> Normal mode
:w --> Save
:q --> Quit
:wq --> Save and quit
:q! --> Quit without saving
===============================================
SEARCHING FILES AND TEXT
===============================================
find . -name "[Link]" --> Find file by name
find /path -name "*.txt" --> Find all .txt files
find . -type f --> Find all files
find . -type d --> Find all directories
find . -size +10M --> Files larger than 10MB
grep "pattern" [Link] --> Search for pattern
grep -i "pattern" [Link] --> Case-insensitive search
grep -r "pattern" directory/ --> Recursive search
grep -n "pattern" [Link] --> Show line numbers
grep -v "pattern" [Link] --> Invert match (non-matching)
grep -c "pattern" [Link] --> Count matching lines
===============================================
TEXT PROCESSING
===============================================
awk '{print $1}' [Link] --> Print first column
awk '{print $2}' [Link] | sort --> Print & sort 2nd column
sed 's/old/new/g' [Link] --> Replace all occurrences
sed -i 's/old/new/g' [Link] --> Replace in-place (modify file)
cut -d':' -f1 /etc/passwd --> Cut using delimiter
sort [Link] --> Sort alphabetically
sort -r [Link] --> Reverse sort
sort -n [Link] --> Numerical sort
uniq [Link] --> Remove adjacent duplicates
sort [Link] | uniq --> Sort & remove duplicates
===============================================
FILE COMPARISON
===============================================
diff file1 file2 --> Show differences between files
diff -u file1 file2 --> Unified format (readable)
cmp file1 file2 --> Compare byte by byte
comm file1 file2 --> Compare sorted files line by line
===============================================
COMPRESSION AND ARCHIVING
===============================================
tar -cvf [Link] files --> Create archive
tar -xvf [Link] --> Extract archive
tar -czvf [Link] files --> Create compressed (gzip)
tar -xzvf [Link] --> Extract compressed
tar -cjvf [Link].bz2 files --> Create bzip2 compressed
tar -tf [Link] --> List contents
zip [Link] file1 file2 --> Create zip archive
zip -r [Link] directory/ --> Compress directory
unzip [Link] --> Extract zip
unzip -l [Link] --> List contents
gzip [Link] --> Compress (creates [Link])
gunzip [Link] --> Decompress gzip file
===============================================
FILE PERMISSIONS
===============================================
chmod 755 [Link] --> rwxr-xr-x permissions
chmod +x [Link] --> Add execute permission
chmod -w [Link] --> Remove write permission
chmod u+x [Link] --> Add execute for user
chmod g+w [Link] --> Add write for group
chmod o-r [Link] --> Remove read for others
chown user:group [Link] --> Change owner and group
chown -R user:group directory/ --> Change recursively
chgrp group [Link] --> Change group only
umask --> Default permission mask
Permission Numbers:
4 = read (r)
2 = write (w)
1 = execute (x)
Examples:
755 = rwxr-xr-x (owner: all, group/others: read+execute)
644 = rw-r--r-- (owner: read+write, others: read only)
777 = rwxrwxrwx (all permissions for everyone)
===============================================
PROCESS MANAGEMENT
===============================================
ps --> Show running processes
ps aux --> Show all processes
ps -ef --> Full format listing
ps -p PID --> Show specific process
top --> Dynamic process viewer
htop --> Enhanced interactive viewer
kill PID --> Kill process by ID
kill -9 PID --> Force kill process
killall process_name --> Kill all by name
pkill process_name --> Kill by name pattern
bg --> Resume job in background
fg --> Bring job to foreground
jobs --> List background jobs
nohup command & --> Run immune to hangups
===============================================
SYSTEM INFORMATION
===============================================
uname -a --> System and kernel info
uname -r --> Kernel release
uname -m --> Machine hardware name
hostname --> Show/set hostname
uptime --> System uptime and load
date --> Display/set date and time
whoami --> Current username
who --> Who is logged in
w --> Who is logged in + activity
id --> User and group IDs
last --> Last logins
dmesg --> Kernel ring buffer messages
===============================================
DISK AND STORAGE
===============================================
df --> Disk usage of filesystems
df -h --> Human-readable format
df -i --> Show inode information
du -sh directory/ --> Summary in human-readable
du -h --max-depth=1 --> Subdirectory sizes (1 level)
lsblk --> List block devices
fdisk -l --> Disk partition tables
mount /dev/sdb1 /mnt --> Mount device
umount /mnt --> Unmount filesystem
free --> Memory usage
free -h --> Human-readable memory
===============================================
NETWORKING
===============================================
ping [Link] --> Test connectivity
ping -c 4 [Link] --> Ping 4 times then stop
ifconfig --> Display interfaces (deprecated)
ip a --> Show IP addresses (modern)
ip addr show --> Display IP addresses
ip link --> Show network interfaces
netstat -tuln --> Show listening ports (deprecated)
ss -tuln --> Modern netstat alternative
traceroute [Link] --> Trace network path
nslookup [Link] --> Query DNS records
dig [Link] --> Advanced DNS query
host [Link] --> Simple DNS lookup
wget [Link] --> Download file
wget -c URL --> Resume download
curl -O [Link] --> Download file
curl -I [Link] --> Show headers only
===============================================
USER MANAGEMENT
===============================================
adduser username --> Add new user (interactive)
useradd username --> Add new user (manual)
userdel username --> Delete user
userdel -r username --> Delete user + home directory
usermod -aG sudo username --> Add user to sudo group
passwd --> Change password
passwd username --> Change user's password
groups username --> Show user's groups
su username --> Switch user
sudo command --> Execute as root
===============================================
SERVICE AND SYSTEM MANAGEMENT
===============================================
systemctl start service_name --> Start service
systemctl stop service_name --> Stop service
systemctl restart service_name --> Restart service
systemctl status service_name --> Check status
systemctl enable service_name --> Enable at boot
systemctl disable service_name --> Disable at boot
service ssh status --> Check SSH (older systems)
journalctl -xe --> Recent logs
journalctl -u service_name --> Service logs
reboot --> Reboot system
shutdown now --> Shutdown immediately
shutdown -h +10 --> Shutdown in 10 min
===============================================
FIREWALL
===============================================
ufw status --> Check firewall status
ufw enable --> Enable firewall
ufw disable --> Disable firewall
ufw allow 80 --> Allow port 80
ufw deny 22 --> Deny port 22
ufw allow ssh --> Allow SSH
iptables -L --> List all rules
iptables -A INPUT -p tcp --dport 80 -j ACCEPT --> Allow HTTP
===============================================
PACKAGE MANAGEMENT
===============================================
Ubuntu/Debian (apt):
apt update --> Update package list
apt upgrade --> Upgrade all packages
apt install package_name --> Install package
apt remove package_name --> Remove package
apt search package_name --> Search for package
apt autoremove --> Remove unnecessary packages
Fedora/RHEL (yum/dnf):
yum install package_name --> Install package
dnf install package_name --> Install (newer)
yum update --> Update all packages
Arch Linux (pacman):
pacman -S package_name --> Install package
pacman -Syu --> Update system
===============================================
FILE TRANSFER
===============================================
scp [Link] user@host:/path/ --> Copy to remote
scp user@host:/path/[Link] . --> Copy from remote
scp -r directory/ user@host:/path/ --> Copy directory
rsync -avz source/ destination/ --> Sync directories
rsync -avz user@host:/path/ local/ --> Sync from remote
ssh user@hostname --> Connect to remote
ssh -p 2222 user@host --> Connect on custom port
===============================================
ENVIRONMENT AND VARIABLES
===============================================
echo $VARIABLE --> Print environment variable
echo $PATH --> Show PATH variable
export VAR=value --> Set environment variable
env --> Display all env variables
printenv --> Print environment variables
alias ll='ls -la' --> Create alias
unalias ll --> Remove alias
history --> Show command history
!number --> Execute from history by number
!! --> Repeat last command
===============================================
PIPES AND REDIRECTION
===============================================
command1 | command2 --> Pipe output to command2
command > [Link] --> Redirect output (overwrite)
command >> [Link] --> Redirect output (append)
command < [Link] --> Redirect input from file
command 2> [Link] --> Redirect errors to file
command &> [Link] --> Redirect output and errors
command | tee [Link] --> Display and save to file
===============================================
SYMBOLIC LINKS
===============================================
ln -s source_file link_name --> Create symbolic link (soft)
ln source_file link_name --> Create hard link
readlink link_name --> Show link target
===============================================
ADVANCED COMMANDS
===============================================
find . -name "*.txt" | xargs rm --> Find and delete
watch -n 5 df -h --> Run df every 5 seconds
time command --> Measure execution time
sleep 10 --> Delay for 10 seconds
clear --> Clear terminal screen
reset --> Reset terminal
script [Link] --> Record terminal session
dd if=/dev/sdb of=/dev/sda --> Clone disk
dd if=/dev/zero of=[Link] bs=1M count=10 --> Create 10MB file
===============================================
USEFUL TIPS & KEYBOARD SHORTCUTS
===============================================
Tab --> Auto-completion
Ctrl+C --> Cancel running command
Ctrl+Z --> Suspend current process
Ctrl+D --> Exit shell or send EOF
Ctrl+L --> Clear screen
Ctrl+R --> Search command history
Ctrl+A --> Move to beginning of line
Ctrl+E --> Move to end of line
Ctrl+U --> Delete from cursor to beginning
Ctrl+K --> Delete from cursor to end
command1 && command2 --> Execute if previous succeeds
command1 || command2 --> Execute if previous fails
command1 ; command2 --> Run sequentially
===============================================
END OF REFERENCE GUIDE
===============================================