100+ Linux Commands: A Complete Guide for Beginners and Professionals
Master the essential Linux commands that every developer, system administrator, and IT professional should know. This comprehensive guide covers file management, system monitoring, networking, and much more.
Table of Contents
File & Directory Management
File Content Manipulation
System Monitoring & Information
Compression & Archiving
Networking
User & Group Management
Package & Process Control
Disk & Filesystem
Text Editors
Scripting & Environment
Miscellaneous Tools
File & Directory Management
- ls - List Directory Contents
ls # List files and directories
ls -la # List all files (including hidden) with details
ls -lh # List with human-readable file sizes
ls -lt # List sorted by modification time
ls -R # List recursively (subdirectories)
ls *.txt # List only .txt files
- cd - Change Directory
cd # Go to home directory
cd /path/to/dir # Go to specific directory
cd .. # Go to parent directory
cd - # Go to previous directory
cd ~ # Go to home directory
- pwd - Print Working Directory
pwd # Show current directory path
- mkdir - Make Directory
mkdir dirname # Create a directory
mkdir -p dir1/dir2 # Create nested directories
mkdir -m 755 dirname # Create with specific permissions
- touch - Create Empty File
touch filename # Create empty file
touch file1 file2 # Create multiple files
touch -a filename # Update access time only
touch -m filename # Update modification time only
- cp - Copy Files and Directories
cp file1 file2 # Copy file1 to file2
cp -r dir1 dir2 # Copy directory recursively
cp -v file1 file2 # Copy with verbose output
cp -p file1 file2 # Preserve permissions and timestamps
cp -i file1 file2 # Interactive copy (prompt before overwrite)
- mv - Move/Rename Files
mv file1 file2 # Rename file1 to file2
mv file1 /path/dir # Move file1 to directory
mv -i file1 file2 # Interactive move
mv -v file1 file2 # Verbose move
- rm - Remove Files
rm filename # Remove file
rm -r dirname # Remove directory recursively
rm -f filename # Force remove (no confirmation)
rm -i filename # Interactive remove
rm -v filename # Verbose remove
- find - Find Files
find . -name "*.txt" # Find .txt files in current directory
find /home -user username # Find files owned by user
find . -size +100M # Find files larger than 100MB
find . -mtime -7 # Find files modified in last 7 days
find . -type f -exec rm {} \; # Find and remove files
- rmdir - Remove Directory
rmdir dirname # Remove empty directory
rmdir -p dir1/dir2 # Remove directory and parent if empty
File Content Manipulation
- cat - Concatenate and Display Files
cat filename # Display file content
cat file1 file2 # Display multiple files
cat > filename # Create file with input
cat >> filename # Append to file
cat -n filename # Display with line numbers
- tac - Reverse Cat
tac filename # Display file content in reverse order
- head - Display Beginning of File
head filename # Display first 10 lines
head -n 20 filename # Display first 20 lines
head -c 100 filename # Display first 100 characters
- tail - Display End of File
tail filename # Display last 10 lines
tail -n 20 filename # Display last 20 lines
tail -f filename # Follow file (real-time updates)
tail -c 100 filename # Display last 100 characters
- more - Page Through File
more filename # Display file page by page
more -p "pattern" filename # Start at pattern
- less - Advanced File Viewer
less filename # Display file with navigation
less -N filename # Display with line numbers
less -R filename # Display with color support
- cut - Extract Sections from Lines
cut -d: -f1 /etc/passwd # Extract first field (username)
cut -c1-10 filename # Extract first 10 characters
cut -f2,4 filename # Extract 2nd and 4th fields
- split - Split Files
split -l 1000 file.txt # Split into 1000-line chunks
split -b 1M file.txt # Split into 1MB chunks
split -n 5 file.txt # Split into 5 equal parts
- nl - Number Lines
nl filename # Number all lines
nl -b a filename # Number non-empty lines
nl -s ":" filename # Use colon as separator
- tr - Translate Characters
tr 'a-z' 'A-Z' < file # Convert to uppercase
tr -d '0-9' < file # Delete digits
tr -s ' ' < file # Squeeze multiple spaces
System Monitoring & Information
- top - Process Monitor
top # Interactive process viewer
top -p PID # Monitor specific process
top -u username # Monitor specific user's processes
top -n 5 # Update 5 times then exit
- htop - Enhanced Process Viewer
htop # Interactive process viewer (if installed)
htop -u username # Monitor specific user
htop -p PID1,PID2 # Monitor specific processes
- uptime - System Uptime
uptime # Show system uptime and load average
- lscpu - CPU Information
lscpu # Display CPU architecture information
lscpu -x # Display in hex format
- free - Memory Usage
free # Display memory usage
free -h # Human-readable format
free -s 5 # Update every 5 seconds
free -t # Show total line
- df - Disk Space
df # Display disk space usage
df -h # Human-readable format
df -i # Show inode information
df -T # Show filesystem type
- du - Disk Usage
du # Show directory sizes
du -h # Human-readable format
du -s dirname # Show total size of directory
du -a # Show sizes of all files
du --max-depth=2 # Limit depth to 2 levels
- ps - Process Status
ps aux # Show all processes
ps -ef # Show all processes (alternative format)
ps -p PID # Show specific process
ps -u username # Show user's processes
ps aux | grep process # Find specific process
- whoami - Current User
whoami # Display current username
Compression & Archiving
- tar - Tape Archive
tar -cvf archive.tar files/ # Create archive
tar -xvf archive.tar # Extract archive
tar -czvf archive.tar.gz files/ # Create compressed archive
tar -xzvf archive.tar.gz # Extract compressed archive
tar -tvf archive.tar # List archive contents
- gzip - Compress Files
gzip filename # Compress file (creates filename.gz)
gzip -d filename.gz # Decompress file
gzip -l filename.gz # List compression info
gzip -9 filename # Maximum compression
- gunzip - Decompress Files
gunzip filename.gz # Decompress file
gunzip -l filename.gz # List compression info
- zip - Create ZIP Archive
zip archive.zip file1 file2 # Create ZIP archive
zip -r archive.zip directory/ # Create recursive ZIP
zip -e archive.zip files/ # Create encrypted ZIP
zip -l archive.zip # List archive contents
- unzip - Extract ZIP Archive
unzip archive.zip # Extract ZIP archive
unzip -l archive.zip # List archive contents
unzip -d directory archive.zip # Extract to specific directory
- bzip2 - Block-Sorting Compressor
bzip2 filename # Compress file (creates filename.bz2)
bzip2 -d filename.bz2 # Decompress file
bzip2 -t filename.bz2 # Test compressed file
Networking
- ping - Test Network Connectivity
ping google.com # Ping host
ping -c 4 google.com # Ping 4 times
ping -i 2 google.com # Ping every 2 seconds
ping -s 1000 google.com # Ping with 1000-byte packets
- ifconfig - Network Interface Configuration
ifconfig # Show all interfaces
ifconfig eth0 # Show specific interface
ifconfig eth0 up # Enable interface
ifconfig eth0 down # Disable interface
- ip - IP Command (Modern)
ip addr # Show IP addresses
ip link # Show network interfaces
ip route # Show routing table
ip addr add 192.168.1.100/24 dev eth0 # Add IP address
- hostname - Show/Set Hostname
hostname # Show current hostname
hostname -f # Show fully qualified hostname
hostname -i # Show IP address
- netstat - Network Statistics
netstat -tuln # Show listening ports
netstat -an # Show all connections
netstat -i # Show interface statistics
netstat -r # Show routing table
- nc - Netcat
nc -l 8080 # Listen on port 8080
nc hostname 80 # Connect to hostname on port 80
nc -z hostname 20-30 # Scan ports 20-30
nc -v hostname 80 # Verbose connection
- nslookup - Name Server Lookup
nslookup google.com # Lookup domain
nslookup 8.8.8.8 # Reverse lookup
nslookup -type=mx google.com # Lookup MX records
User & Group Management
- who - Show Logged-in Users
who # Show logged-in users
who -H # Show with headers
who -q # Show user count only
- groups - Show User Groups
groups # Show current user's groups
groups username # Show specific user's groups
- passwd - Change Password
passwd # Change current user's password
passwd username # Change specific user's password
passwd -l username # Lock user account
passwd -u username # Unlock user account
- finger - User Information
finger # Show current user info
finger username # Show specific user info
- id - User/Group IDs
id # Show current user's IDs
id username # Show specific user's IDs
id -g # Show group ID only
id -u # Show user ID only
Package & Process Control
- kill - Terminate Processes
kill PID # Send SIGTERM to process
kill -9 PID # Force kill process (SIGKILL)
kill -l # List all signals
kill -HUP PID # Send SIGHUP signal
- killall - Kill by Name
killall processname # Kill all processes by name
killall -9 processname # Force kill by name
killall -u username processname # Kill user's processes
- nice - Set Process Priority
nice -n 10 command # Run command with nice value 10
nice command # Run command with nice value 10
- renice - Change Process Priority
renice 10 PID # Change process priority to 10
renice -n 5 -p PID # Change process priority by -5
- jobs - List Background Jobs
jobs # List background jobs
jobs -l # List with process IDs
jobs -r # List running jobs only
- bg - Background Job
bg # Continue stopped job in background
bg %1 # Continue job number 1 in background
- fg - Foreground Job
fg # Bring background job to foreground
fg %1 # Bring job number 1 to foreground
Disk & Filesystem
- mount - Mount Filesystems
mount # Show mounted filesystems
mount /dev/sda1 /mnt # Mount device to directory
mount -t nfs server:/share /mnt # Mount NFS share
- umount - Unmount Filesystems
umount /mnt # Unmount directory
umount /dev/sda1 # Unmount device
umount -f /mnt # Force unmount
- lsblk - List Block Devices
lsblk # List all block devices
lsblk -f # Show filesystem information
lsblk -o NAME,SIZE,TYPE # Show specific columns
- fdisk - Partition Table Manipulator
fdisk -l # List all partitions
fdisk /dev/sda # Edit partition table
Text Editors
- nano - Simple Text Editor
nano filename # Edit file
nano -w filename # Disable word wrapping
nano -c filename # Show cursor position
- vim - Advanced Text Editor
vim filename # Edit file
vim -R filename # Read-only mode
vim +10 filename # Open at line 10
vim -c "set number" filename # Open with line numbers
Scripting & Environment
- echo - Display Text
echo "Hello World" # Display text
echo $PATH # Display environment variable
echo -e "Line1\nLine2" # Interpret escape sequences
echo -n "No newline" # Suppress newline
- printenv - Print Environment Variables
printenv # Print all environment variables
printenv PATH # Print specific variable
- export - Set Environment Variables
export VAR=value # Set environment variable
export PATH=$PATH:/new/path # Add to PATH
export -p # List all exported variables
- env - Run Command with Environment
env # Print environment
env VAR=value command # Run command with variable
env -i command # Run with clean environment
- alias - Create Command Aliases
alias ll='ls -la' # Create alias
alias # List all aliases
unalias ll # Remove alias
- history - Command History
history # Show command history
history 10 # Show last 10 commands
history -c # Clear history
!n # Execute command number n
- which - Locate Command
which command # Show command location
which -a command # Show all locations
Miscellaneous Tools
- man - Manual Pages
man command # Show manual page
man -k keyword # Search manual pages
man -f command # Show brief description
- help - Shell Built-in Help
help # Show shell help
help cd # Show help for specific command
- cal - Calendar
cal # Show current month
cal 2024 # Show year calendar
cal -m # Monday as first day
cal -3 # Show previous, current, next month
- bc - Calculator
bc # Start calculator
echo "2+2" | bc # Calculate expression
bc -l # Start with math library
- sl - Steam Locomotive (Fun)
sl # Animated steam locomotive (if installed)
sl -a # An accident occurs
sl -l # Little locomotive
- cmatrix - Matrix Effect
cmatrix # Matrix-style display (if installed)
cmatrix -C green # Green color
cmatrix -s # Screensaver mode
- banner - Large Text
banner "Hello" # Display large text
banner -w 50 "Text" # Set width to 50
- date - Display Date/Time
date # Show current date/time
date +%Y-%m-%d # Show date in specific format
date -d "tomorrow" # Show tomorrow's date
date -s "2024-01-01" # Set system date
- shuf - Shuffle Lines
shuf file.txt # Shuffle lines in file
shuf -i 1-100 # Generate random numbers 1-100
shuf -n 5 file.txt # Select 5 random lines
- xeyes - Follow Mouse
xeyes # Display eyes following mouse (if installed)
Advanced Commands
- awk - Text Processing
awk '{print $1}' file.txt # Print first field
awk -F: '{print $1}' /etc/passwd # Use colon as delimiter
awk '$3 > 1000' file.txt # Print lines where field 3 > 1000
- sed - Stream Editor
sed 's/old/new/g' file.txt # Replace text
sed -i 's/old/new/g' file.txt # Replace in file
sed -n '5p' file.txt # Print line 5
sed '1,5d' file.txt # Delete lines 1-5
- grep - Search Text
grep "pattern" file.txt # Search for pattern
grep -i "pattern" file.txt # Case-insensitive search
grep -r "pattern" directory/ # Recursive search
grep -v "pattern" file.txt # Invert match
grep -n "pattern" file.txt # Show line numbers
- sort - Sort Lines
sort file.txt # Sort alphabetically
sort -n file.txt # Sort numerically
sort -r file.txt # Reverse sort
sort -u file.txt # Remove duplicates
- uniq - Remove Duplicates
uniq file.txt # Remove consecutive duplicates
uniq -c file.txt # Count occurrences
uniq -d file.txt # Show only duplicates
- wc - Word Count
wc file.txt # Count lines, words, characters
wc -l file.txt # Count lines only
wc -w file.txt # Count words only
wc -c file.txt # Count characters only
- tee - Read from Stdin, Write to Stdout and Files
echo "text" | tee file.txt # Write to file and display
echo "text" | tee -a file.txt # Append to file
- xargs - Execute Commands
find . -name "*.txt" | xargs rm # Remove all .txt files
echo "1 2 3" | xargs -n 1 echo # Process each number separately
- watch - Execute Command Periodically
watch -n 1 'ps aux' # Watch processes every second
watch -d 'ls -la' # Highlight differences
- time - Measure Command Execution Time
time command # Measure execution time
time -p command # POSIX format
- sleep - Delay Execution
sleep 5 # Sleep for 5 seconds
sleep 1m # Sleep for 1 minute
sleep 1h # Sleep for 1 hour
- wait - Wait for Background Jobs
wait # Wait for all background jobs
wait %1 # Wait for job number 1
- trap - Handle Signals
trap 'echo "Caught signal"' INT # Handle Ctrl+C
trap - INT # Remove signal handler
- ulimit - Control Resource Limits
ulimit -a # Show all limits
ulimit -n 1024 # Set file descriptor limit
ulimit -u 1000 # Set process limit
- strace - Trace System Calls
strace command # Trace system calls
strace -p PID # Trace running process
strace -e trace=network command # Trace network calls only
- lsof - List Open Files
lsof # List all open files
lsof -p PID # List files opened by process
lsof -i :80 # List processes using port 80
- netcat - Network Swiss Army Knife
nc -l 8080 # Listen on port 8080
nc hostname 80 # Connect to hostname:80
nc -z hostname 20-30 # Scan ports 20-30
- curl - Transfer Data
curl http://example.com # Download webpage
curl -O http://example.com/file.txt # Download file
curl -X POST -d "data" http://example.com # POST data
- wget - Retrieve Files
wget http://example.com/file.txt # Download file
wget -c http://example.com/file.txt # Continue download
wget -r http://example.com # Recursive download
- rsync - Remote Sync
rsync -av source/ dest/ # Sync directories
rsync -avz source/ user@host:dest/ # Sync to remote host
rsync -av --delete source/ dest/ # Sync with deletion
- scp - Secure Copy
scp file.txt user@host:/path/ # Copy file to remote host
scp user@host:/path/file.txt . # Copy file from remote host
scp -r dir/ user@host:/path/ # Copy directory
- ssh - Secure Shell
ssh user@hostname # Connect to remote host
ssh -p 2222 user@hostname # Connect on specific port
ssh -X user@hostname # Enable X11 forwarding
- screen - Terminal Multiplexer
screen # Start new screen session
screen -S sessionname # Start named session
screen -r sessionname # Reattach to session
screen -ls # List sessions
Pro Tips for Linux Command Mastery
Use Tab Completion
Press Tab to auto-complete commands, filenames, and paths.Command History
Use Ctrl+R to search command history
Use !$ to reference the last argument of previous command
Use !! to repeat the last commandAliases for Efficiency
alias ll='ls -la'
alias grep='grep --color=auto'
alias df='df -h'
alias du='du -h'
- Redirection and Pipes
command > file.txt # Redirect output to file
command >> file.txt # Append output to file
command < file.txt # Redirect input from file
command1 | command2 # Pipe output to another command
- Background and Foreground
command & # Run command in background
Ctrl+Z # Suspend current process
Ctrl+C # Terminate current process
- File Permissions
chmod 755 file # Set permissions (rwxr-xr-x)
chmod +x file # Make executable
chown user:group file # Change ownership
- Process Management
Ctrl+Z # Suspend process
bg # Continue in background
fg # Bring to foreground
jobs # List background jobs
Conclusion
Mastering these Linux commands will significantly improve your productivity and system administration skills. Remember to:
Practice regularly - Use these commands in your daily workflow
Read man pages - Use man command for detailed information
Combine commands - Use pipes and redirection for powerful operations
Create aliases - Customize your environment for efficiency
Stay updated - Learn new commands and features as they become available
π‘ Pro Tip: Create a personal cheat sheet with your most frequently used commands and their options. This will help you remember them and work more efficiently.
The key to mastering Linux commands is consistent practice and understanding the underlying concepts. Start with the basic file management commands and gradually work your way up to more advanced system administration tasks.
π Ready to kickstart your tech career?
π [Apply to 10000Coders]
π [Learn Web Development for Free]
π [See how we helped 2500+ students get jobs]
Top comments (0)