DEV Community

Cover image for 100+ Linux Commands: A Complete Guide for Beginners and Professionals
10000coders
10000coders

Posted on

100+ Linux Commands: A Complete Guide for Beginners and Professionals

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

  1. 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

Enter fullscreen mode Exit fullscreen mode
  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. pwd - Print Working Directory
pwd                  # Show current directory path
Enter fullscreen mode Exit fullscreen mode
  1. mkdir - Make Directory
mkdir dirname        # Create a directory
mkdir -p dir1/dir2   # Create nested directories
mkdir -m 755 dirname # Create with specific permissions
Enter fullscreen mode Exit fullscreen mode
  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. 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)
Enter fullscreen mode Exit fullscreen mode
  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. rmdir - Remove Directory
rmdir dirname        # Remove empty directory
rmdir -p dir1/dir2   # Remove directory and parent if empty
Enter fullscreen mode Exit fullscreen mode

File Content Manipulation

  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. tac - Reverse Cat
tac filename         # Display file content in reverse order
Enter fullscreen mode Exit fullscreen mode
  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. more - Page Through File
more filename        # Display file page by page
more -p "pattern" filename  # Start at pattern
Enter fullscreen mode Exit fullscreen mode
  1. less - Advanced File Viewer
less filename        # Display file with navigation
less -N filename     # Display with line numbers
less -R filename     # Display with color support
Enter fullscreen mode Exit fullscreen mode
  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. nl - Number Lines
nl filename          # Number all lines
nl -b a filename     # Number non-empty lines
nl -s ":" filename   # Use colon as separator
Enter fullscreen mode Exit fullscreen mode
  1. 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
Enter fullscreen mode Exit fullscreen mode

System Monitoring & Information

  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. htop - Enhanced Process Viewer
htop                  # Interactive process viewer (if installed)
htop -u username      # Monitor specific user
htop -p PID1,PID2     # Monitor specific processes
Enter fullscreen mode Exit fullscreen mode
  1. uptime - System Uptime
uptime                # Show system uptime and load average
Enter fullscreen mode Exit fullscreen mode
  1. lscpu - CPU Information
lscpu                 # Display CPU architecture information
lscpu -x              # Display in hex format
Enter fullscreen mode Exit fullscreen mode
  1. free - Memory Usage
free                  # Display memory usage
free -h               # Human-readable format
free -s 5             # Update every 5 seconds
free -t               # Show total line
Enter fullscreen mode Exit fullscreen mode
  1. df - Disk Space
df                    # Display disk space usage
df -h                 # Human-readable format
df -i                 # Show inode information
df -T                 # Show filesystem type
Enter fullscreen mode Exit fullscreen mode
  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. whoami - Current User
whoami                # Display current username
Enter fullscreen mode Exit fullscreen mode

Compression & Archiving

  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. gunzip - Decompress Files
gunzip filename.gz    # Decompress file
gunzip -l filename.gz # List compression info
Enter fullscreen mode Exit fullscreen mode
  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. bzip2 - Block-Sorting Compressor
bzip2 filename         # Compress file (creates filename.bz2)
bzip2 -d filename.bz2  # Decompress file
bzip2 -t filename.bz2  # Test compressed file
Enter fullscreen mode Exit fullscreen mode

Networking

  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. ifconfig - Network Interface Configuration
ifconfig              # Show all interfaces
ifconfig eth0         # Show specific interface
ifconfig eth0 up      # Enable interface
ifconfig eth0 down    # Disable interface
Enter fullscreen mode Exit fullscreen mode
  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. hostname - Show/Set Hostname
hostname              # Show current hostname
hostname -f           # Show fully qualified hostname
hostname -i           # Show IP address
Enter fullscreen mode Exit fullscreen mode
  1. netstat - Network Statistics
netstat -tuln         # Show listening ports
netstat -an           # Show all connections
netstat -i            # Show interface statistics
netstat -r            # Show routing table
Enter fullscreen mode Exit fullscreen mode
  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. nslookup - Name Server Lookup
nslookup google.com   # Lookup domain
nslookup 8.8.8.8     # Reverse lookup
nslookup -type=mx google.com  # Lookup MX records
Enter fullscreen mode Exit fullscreen mode

User & Group Management

  1. who - Show Logged-in Users
who                   # Show logged-in users
who -H                # Show with headers
who -q                # Show user count only
Enter fullscreen mode Exit fullscreen mode
  1. groups - Show User Groups
groups                # Show current user's groups
groups username       # Show specific user's groups
Enter fullscreen mode Exit fullscreen mode
  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. finger - User Information
finger                # Show current user info
finger username       # Show specific user info
Enter fullscreen mode Exit fullscreen mode
  1. 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
Enter fullscreen mode Exit fullscreen mode

Package & Process Control

  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. nice - Set Process Priority
nice -n 10 command    # Run command with nice value 10
nice command          # Run command with nice value 10
Enter fullscreen mode Exit fullscreen mode
  1. renice - Change Process Priority
renice 10 PID         # Change process priority to 10
renice -n 5 -p PID    # Change process priority by -5
Enter fullscreen mode Exit fullscreen mode
  1. jobs - List Background Jobs
jobs                  # List background jobs
jobs -l               # List with process IDs
jobs -r               # List running jobs only
Enter fullscreen mode Exit fullscreen mode
  1. bg - Background Job
bg                    # Continue stopped job in background
bg %1                 # Continue job number 1 in background
Enter fullscreen mode Exit fullscreen mode
  1. fg - Foreground Job
fg                    # Bring background job to foreground
fg %1                 # Bring job number 1 to foreground
Enter fullscreen mode Exit fullscreen mode

Disk & Filesystem

  1. mount - Mount Filesystems
mount                 # Show mounted filesystems
mount /dev/sda1 /mnt  # Mount device to directory
mount -t nfs server:/share /mnt  # Mount NFS share
Enter fullscreen mode Exit fullscreen mode
  1. umount - Unmount Filesystems
umount /mnt           # Unmount directory
umount /dev/sda1      # Unmount device
umount -f /mnt        # Force unmount
Enter fullscreen mode Exit fullscreen mode
  1. lsblk - List Block Devices
lsblk                 # List all block devices
lsblk -f              # Show filesystem information
lsblk -o NAME,SIZE,TYPE  # Show specific columns
Enter fullscreen mode Exit fullscreen mode
  1. fdisk - Partition Table Manipulator
fdisk -l              # List all partitions
fdisk /dev/sda        # Edit partition table
Enter fullscreen mode Exit fullscreen mode

Text Editors

  1. nano - Simple Text Editor
nano filename         # Edit file
nano -w filename      # Disable word wrapping
nano -c filename      # Show cursor position
Enter fullscreen mode Exit fullscreen mode
  1. 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
Enter fullscreen mode Exit fullscreen mode

Scripting & Environment

  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. printenv - Print Environment Variables
printenv              # Print all environment variables
printenv PATH         # Print specific variable
Enter fullscreen mode Exit fullscreen mode
  1. export - Set Environment Variables
export VAR=value      # Set environment variable
export PATH=$PATH:/new/path  # Add to PATH
export -p             # List all exported variables
Enter fullscreen mode Exit fullscreen mode
  1. env - Run Command with Environment
env                   # Print environment
env VAR=value command # Run command with variable
env -i command        # Run with clean environment
Enter fullscreen mode Exit fullscreen mode
  1. alias - Create Command Aliases
alias ll='ls -la'     # Create alias
alias                 # List all aliases
unalias ll            # Remove alias
Enter fullscreen mode Exit fullscreen mode
  1. history - Command History
history               # Show command history
history 10            # Show last 10 commands
history -c            # Clear history
!n                    # Execute command number n
Enter fullscreen mode Exit fullscreen mode
  1. which - Locate Command
which command         # Show command location
which -a command      # Show all locations
Enter fullscreen mode Exit fullscreen mode

Miscellaneous Tools

  1. man - Manual Pages
man command           # Show manual page
man -k keyword        # Search manual pages
man -f command        # Show brief description
Enter fullscreen mode Exit fullscreen mode
  1. help - Shell Built-in Help
help                  # Show shell help
help cd               # Show help for specific command
Enter fullscreen mode Exit fullscreen mode
  1. cal - Calendar
cal                   # Show current month
cal 2024              # Show year calendar
cal -m                # Monday as first day
cal -3                # Show previous, current, next month
Enter fullscreen mode Exit fullscreen mode
  1. bc - Calculator
bc                    # Start calculator
echo "2+2" | bc       # Calculate expression
bc -l                 # Start with math library
Enter fullscreen mode Exit fullscreen mode
  1. sl - Steam Locomotive (Fun)
sl                    # Animated steam locomotive (if installed)
sl -a                 # An accident occurs
sl -l                 # Little locomotive
Enter fullscreen mode Exit fullscreen mode
  1. cmatrix - Matrix Effect
cmatrix               # Matrix-style display (if installed)
cmatrix -C green      # Green color
cmatrix -s            # Screensaver mode
Enter fullscreen mode Exit fullscreen mode
  1. banner - Large Text
banner "Hello"        # Display large text
banner -w 50 "Text"   # Set width to 50
Enter fullscreen mode Exit fullscreen mode
  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. xeyes - Follow Mouse
xeyes                 # Display eyes following mouse (if installed)
Enter fullscreen mode Exit fullscreen mode

Advanced Commands

  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. uniq - Remove Duplicates
uniq file.txt                 # Remove consecutive duplicates
uniq -c file.txt              # Count occurrences
uniq -d file.txt              # Show only duplicates
Enter fullscreen mode Exit fullscreen mode
  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. xargs - Execute Commands
find . -name "*.txt" | xargs rm  # Remove all .txt files
echo "1 2 3" | xargs -n 1 echo   # Process each number separately
Enter fullscreen mode Exit fullscreen mode
  1. watch - Execute Command Periodically
watch -n 1 'ps aux'           # Watch processes every second
watch -d 'ls -la'             # Highlight differences
Enter fullscreen mode Exit fullscreen mode
  1. time - Measure Command Execution Time
time command                  # Measure execution time
time -p command               # POSIX format
Enter fullscreen mode Exit fullscreen mode
  1. sleep - Delay Execution
sleep 5                       # Sleep for 5 seconds
sleep 1m                      # Sleep for 1 minute
sleep 1h                      # Sleep for 1 hour
Enter fullscreen mode Exit fullscreen mode
  1. wait - Wait for Background Jobs
wait                          # Wait for all background jobs
wait %1                       # Wait for job number 1
Enter fullscreen mode Exit fullscreen mode
  1. trap - Handle Signals
trap 'echo "Caught signal"' INT  # Handle Ctrl+C
trap - INT                       # Remove signal handler
Enter fullscreen mode Exit fullscreen mode
  1. ulimit - Control Resource Limits
ulimit -a                      # Show all limits
ulimit -n 1024                 # Set file descriptor limit
ulimit -u 1000                 # Set process limit
Enter fullscreen mode Exit fullscreen mode
  1. strace - Trace System Calls
strace command                 # Trace system calls
strace -p PID                  # Trace running process
strace -e trace=network command # Trace network calls only
Enter fullscreen mode Exit fullscreen mode
  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. screen - Terminal Multiplexer
screen                        # Start new screen session
screen -S sessionname         # Start named session
screen -r sessionname         # Reattach to session
screen -ls                    # List sessions
Enter fullscreen mode Exit fullscreen mode

Pro Tips for Linux Command Mastery

  1. Use Tab Completion
    Press Tab to auto-complete commands, filenames, and paths.

  2. Command History
    Use Ctrl+R to search command history
    Use !$ to reference the last argument of previous command
    Use !! to repeat the last command

  3. Aliases for Efficiency

alias ll='ls -la'
alias grep='grep --color=auto'
alias df='df -h'
alias du='du -h'
Enter fullscreen mode Exit fullscreen mode
  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. Background and Foreground
command &              # Run command in background
Ctrl+Z                 # Suspend current process
Ctrl+C                 # Terminate current process
Enter fullscreen mode Exit fullscreen mode
  1. File Permissions
chmod 755 file         # Set permissions (rwxr-xr-x)
chmod +x file          # Make executable
chown user:group file  # Change ownership
Enter fullscreen mode Exit fullscreen mode
  1. Process Management
Ctrl+Z                 # Suspend process
bg                     # Continue in background
fg                     # Bring to foreground
jobs                   # List background jobs
Enter fullscreen mode Exit fullscreen mode

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)