OS Notes
Essential Linux commands — file management, navigation, text processing, system information, process control, and networking commands with practical examples for beginners.
Introduction
The command line is the primary interface for working with Linux systems. While graphical desktops exist, serious system administration, development, and server management happens at the terminal. Every command you learn is a tool in your toolkit — and these tools combine in powerful ways that graphical interfaces cannot match.
Learning Linux commands is like learning vocabulary in a new language. Start with the most common ones, practice daily, and gradually build fluency. Within a few weeks of regular use, the command line becomes faster and more efficient than any GUI for most tasks.
Navigation Commands
# Print current directory (where am I?)
pwd
# Output: /home/alice/projects
# List directory contents
ls # Basic listing
ls -l # Long format (permissions, size, date)
ls -la # Include hidden files (starting with .)
ls -lh # Human-readable sizes (KB, MB, GB)
ls -lt # Sort by modification time (newest first)
ls -lS # Sort by size (largest first)
# Change directory
cd /var/log # Go to absolute path
cd projects # Go to relative path (from current dir)
cd .. # Go up one level
cd ~ # Go to home directory
cd - # Go to previous directoryFile and Directory Operations
# Create files
touch newfile.txt # Create empty file (or update timestamp)
echo "hello" > file.txt # Create file with content (overwrites)
echo "more" >> file.txt # Append to existing file
# Create directories
mkdir projects # Create single directory
mkdir -p a/b/c/d # Create nested directories (parents too)
# Copy files and directories
cp source.txt destination.txt # Copy file
cp -r source_dir/ destination_dir/ # Copy directory recursively
cp -i file.txt backup/ # Interactive (ask before overwrite)
# Move/rename files
mv old_name.txt new_name.txt # Rename
mv file.txt /other/path/ # Move to different directory
# Delete files and directories
rm file.txt # Remove file
rm -i important.txt # Ask confirmation before deleting
rm -r directory/ # Remove directory and contents
rm -rf temp/ # Force remove (no confirmation) — USE CAREFULLY
# View file contents
cat file.txt # Print entire file
less file.txt # Scrollable viewer (q to quit)
head -20 file.txt # First 20 lines
tail -20 file.txt # Last 20 lines
tail -f /var/log/syslog # Follow file in real-time (live log viewing)File Information
# File details
stat file.txt # Detailed metadata (size, timestamps, inode)
file document.pdf # Determine file type (text, binary, image, etc.)
wc file.txt # Count lines, words, characters
wc -l file.txt # Count lines only
# Disk usage
du -h directory/ # Size of directory and subdirectories
du -sh * # Size of each item in current directory
df -h # Disk space usage of mounted filesystemsText Processing
# Search within files
grep "error" logfile.txt # Lines containing "error"
grep -i "error" logfile.txt # Case-insensitive
grep -r "TODO" ./src/ # Recursive search in directory
grep -n "function" script.py # Show line numbers
grep -c "404" access.log # Count matching lines
grep -v "debug" app.log # Lines NOT matching (invert)
# Sort and filter
sort names.txt # Sort alphabetically
sort -n numbers.txt # Sort numerically
sort -r file.txt # Reverse sort
uniq file.txt # Remove consecutive duplicates
sort file.txt | uniq # Remove ALL duplicates (sort first!)
sort file.txt | uniq -c # Count occurrences
# Text extraction
cut -d',' -f1,3 data.csv # Extract columns 1 and 3 (comma delimiter)
cut -c1-10 file.txt # Extract first 10 characters of each line
awk '{print $1, $3}' file.txt # Print fields 1 and 3 (space delimiter)
sed 's/old/new/g' file.txt # Replace all occurrencesPipes and Redirection
The real power of Linux commands comes from combining them:
# Pipe: send output of one command as input to another
ls -la | grep ".txt" # List only .txt files
cat access.log | sort | uniq -c | sort -rn | head -10 # Top 10 repeated lines
ps aux | grep nginx # Find nginx processes
# Redirection
command > file.txt # Output to file (overwrite)
command >> file.txt # Output to file (append)
command 2> errors.txt # Redirect errors to file
command > out.txt 2>&1 # Both output and errors to same file
command < input.txt # Read input from fileSystem Information
# System details
uname -a # Kernel version, architecture
hostname # Machine name
uptime # How long system has been running
date # Current date and time
cal # Calendar for current month
# Hardware information
lscpu # CPU details
free -h # Memory usage (RAM and swap)
lsblk # Block devices (disks and partitions)
lsusb # Connected USB devices
lspci # PCI devices (network cards, GPU)Process Management
# View processes
ps aux # All running processes
ps aux --sort=-%cpu # Sorted by CPU usage
top # Real-time process monitor (q to quit)
htop # Better interactive process monitor
# Control processes
command & # Run in background
jobs # List background jobs
fg %1 # Bring job 1 to foreground
kill PID # Send SIGTERM (graceful stop)
kill -9 PID # Send SIGKILL (force stop)
killall process_name # Kill all processes by nameNetwork Commands
# Network information
ip addr # Network interfaces and IP addresses
ip route # Routing table
ss -tlnp # Listening TCP ports
ping google.com # Test connectivity
traceroute google.com # Trace network path
# Download
curl -O https://example.com/file.zip # Download file
wget https://example.com/file.zip # Download file (alternative)
# Remote access
ssh user@server # Connect to remote machine
scp file.txt user@server:/path/ # Copy file to remote machinePermissions and Ownership
chmod 755 script.sh # Set permissions (rwxr-xr-x)
chmod +x script.sh # Make executable
chown user:group file # Change owner and groupUseful Shortcuts and Tips
Combining Commands
# Find large files
find / -type f -size +100M 2>/dev/null | head -20
# Count files by extension in a project
find . -type f | sed 's/.*\.//' | sort | uniq -c | sort -rn
# Monitor disk space every 5 seconds
watch -n 5 'df -h | grep /dev/sd'
# Find and delete old log files
find /var/log -name "*.log" -mtime +30 -deleteKey Takeaways
ls,cd,pwdfor navigation;cp,mv,rmfor file operations- Pipes (
|) connect commands into powerful processing pipelines grepsearches content;findsearches filenames and metadata- Redirection (
>,>>,<) controls where input/output goes - Tab completion and history (
Ctrl+R) save enormous time - Practice daily — command line fluency comes from regular use, not memorization
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Basic Linux Commands - Command Line Usage.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Operating Systems topic.
Search Terms
operating-systems, operating systems, operating, systems, linux, and, unix, basic
Related Operating Systems Topics