Advertisement
Header Ad Space (728x90)
Press ESC to close Press / to search

Complete Linux Command Line Guide: 100+ Essential Commands for Beginners to Advanced (2025)

Last Updated: December 2025 | Reading Time: 45 minutes | Tested on: Ubuntu 24.04, RHEL 9, Fedora 41

The Linux command line is the most powerful tool in a system administrators arsenal. Whether you are a complete beginner or an experienced sysadmin looking to expand your knowledge, this comprehensive guide covers over 100 essential Linux commands organized by category with practical examples and use cases. Master these commands and you will be able to efficiently manage any Linux system.

Prerequisites

Before diving in, you will need:

  • Access to a Linux system (physical, VM, or cloud server)
  • Terminal emulator or SSH access
  • Basic understanding of files and directories
  • Recommended: A VPS from Linode or DigitalOcean for hands-on practice

File and Directory Commands

These fundamental commands form the foundation of Linux file system navigation and manipulation.

ls – List Directory Contents

The ls command displays files and directories in the current location.

# Basic listing
ls

# Long format with details
ls -l

# Show hidden files
ls -la

# Human-readable file sizes
ls -lh

# Sort by modification time
ls -lt

# Recursive listing
ls -R

# List only directories
ls -d */

cd – Change Directory

# Change to home directory
cd ~

# Change to previous directory
cd -

# Go up one level
cd ..

# Go up two levels
cd ../..

# Absolute path
cd /var/log

# Relative path
cd Documents/Projects

pwd – Print Working Directory

# Show current directory
pwd

# Show physical path (resolve symlinks)
pwd -P

mkdir – Make Directory

# Create single directory
mkdir mydir

# Create nested directories
mkdir -p parent/child/grandchild

# Create with specific permissions
mkdir -m 755 securedir

# Create multiple directories
mkdir dir1 dir2 dir3

rm – Remove Files and Directories

# Remove file
rm file.txt

# Remove directory and contents
rm -r directory/

# Force remove without prompting
rm -rf directory/

# Interactive mode (prompt before each removal)
rm -i file.txt

# Verbose output
rm -v file.txt

cp – Copy Files and Directories

# Copy file
cp source.txt destination.txt

# Copy directory recursively
cp -r source_dir/ destination_dir/

# Preserve attributes
cp -p source.txt destination.txt

# Interactive mode
cp -i source.txt destination.txt

# Copy multiple files to directory
cp file1.txt file2.txt /destination/

mv – Move or Rename Files

# Rename file
mv oldname.txt newname.txt

# Move file to directory
mv file.txt /destination/

# Move multiple files
mv file1.txt file2.txt /destination/

# Interactive mode
mv -i source.txt destination.txt

touch – Create or Update File Timestamps

# Create empty file
touch newfile.txt

# Create multiple files
touch file1.txt file2.txt file3.txt

# Update timestamp only if file exists
touch -c existingfile.txt

File Viewing and Editing Commands

cat – Concatenate and Display Files

# Display file contents
cat file.txt

# Display with line numbers
cat -n file.txt

# Display multiple files
cat file1.txt file2.txt

# Create file from input
cat > newfile.txt
Type your content here
Press Ctrl+D to save

less and more – Page Through Files

# View large file with less
less /var/log/syslog

# Navigation in less:
# Space: Next page
# b: Previous page
# /pattern: Search forward
# ?pattern: Search backward
# n: Next search result
# q: Quit

# View with more
more file.txt

head and tail – View Beginning or End

# First 10 lines (default)
head file.txt

# First 20 lines
head -n 20 file.txt

# Last 10 lines (default)
tail file.txt

# Last 50 lines
tail -n 50 file.txt

# Follow file in real-time (great for logs)
tail -f /var/log/syslog

# Follow multiple files
tail -f /var/log/syslog /var/log/auth.log

nano – Simple Text Editor

# Open file in nano
nano file.txt

# Common shortcuts:
# Ctrl+O: Save
# Ctrl+X: Exit
# Ctrl+K: Cut line
# Ctrl+U: Paste
# Ctrl+W: Search

vim – Advanced Text Editor

# Open file in vim
vim file.txt

# Modes:
# i: Insert mode
# Esc: Normal mode
# :: Command mode

# Essential commands:
# :w - Save
# :q - Quit
# :wq - Save and quit
# :q! - Quit without saving
# dd - Delete line
# yy - Yank (copy) line
# p - Paste
# /pattern - Search
# n - Next result

File Search and Text Processing

find – Search for Files

# Find by name
find /home -name "*.txt"

# Find by name (case insensitive)
find /home -iname "*.TXT"

# Find by type (f=file, d=directory)
find /var -type f -name "*.log"

# Find by size
find / -size +100M    # Files larger than 100MB
find / -size -1k      # Files smaller than 1KB

# Find by modification time
find /var -mtime -7   # Modified in last 7 days
find /var -mtime +30  # Modified more than 30 days ago

# Find and execute command
find /tmp -type f -name "*.tmp" -exec rm {} \;

# Find with multiple conditions
find /var/log -type f -name "*.log" -size +10M

grep – Search Text Patterns

# Search for pattern in file
grep "error" logfile.txt

# Case insensitive search
grep -i "ERROR" logfile.txt

# Search recursively in directory
grep -r "function" /var/www/

# Show line numbers
grep -n "pattern" file.txt

# Invert match (show non-matching lines)
grep -v "DEBUG" logfile.txt

# Count matches
grep -c "error" logfile.txt

# Show context lines
grep -B 2 -A 2 "error" logfile.txt   # 2 lines before and after

# Extended regex
grep -E "error|warning|critical" logfile.txt

# Search for whole word
grep -w "root" /etc/passwd

awk – Pattern Scanning and Processing

# Print specific columns
awk "{print \$1, \$3}" file.txt

# Print with delimiter
awk -F":" "{print \$1, \$7}" /etc/passwd

# Filter by condition
awk "\$3 > 1000 {print \$1}" /etc/passwd

# Sum a column
awk "{sum += \$5} END {print sum}" file.txt

# Print line numbers
awk "{print NR, \$0}" file.txt

sed – Stream Editor

# Replace first occurrence on each line
sed "s/old/new/" file.txt

# Replace all occurrences
sed "s/old/new/g" file.txt

# Replace and save in place
sed -i "s/old/new/g" file.txt

# Delete lines matching pattern
sed "/pattern/d" file.txt

# Delete specific line
sed "5d" file.txt

# Insert line before match
sed "/pattern/i New line" file.txt

# Print only matching lines
sed -n "/pattern/p" file.txt

User and Permission Management

User Management Commands

# Add new user
sudo useradd -m -s /bin/bash newuser

# Add user with home directory and shell
sudo useradd -m -d /home/john -s /bin/bash john

# Set user password
sudo passwd username

# Delete user
sudo userdel username

# Delete user with home directory
sudo userdel -r username

# Modify user
sudo usermod -aG sudo username    # Add to sudo group
sudo usermod -s /bin/zsh username # Change shell

# View user info
id username

# Switch user
su - username

# Execute command as another user
sudo -u username command

Group Management

# Create group
sudo groupadd developers

# Delete group
sudo groupdel groupname

# Add user to group
sudo usermod -aG groupname username

# View group members
getent group groupname

# List user groups
groups username

chmod – Change File Permissions

# Numeric mode (r=4, w=2, x=1)
chmod 755 script.sh    # rwxr-xr-x
chmod 644 file.txt     # rw-r--r--
chmod 700 private/     # rwx------

# Symbolic mode
chmod u+x script.sh    # Add execute for user
chmod g+w file.txt     # Add write for group
chmod o-r file.txt     # Remove read for others
chmod a+r file.txt     # Add read for all

# Recursive
chmod -R 755 directory/

chown – Change File Ownership

# Change owner
sudo chown newowner file.txt

# Change owner and group
sudo chown newowner:newgroup file.txt

# Change only group
sudo chown :newgroup file.txt

# Recursive
sudo chown -R www-data:www-data /var/www/

System Information and Monitoring

System Information

# Kernel version
uname -r

# Full system info
uname -a

# Distribution info
cat /etc/os-release
lsb_release -a

# Hostname
hostname
hostnamectl

# Uptime
uptime

# Current date and time
date

# Hardware info
lscpu          # CPU info
lsmem          # Memory info
lsblk          # Block devices
lspci          # PCI devices
lsusb          # USB devices

Process Management

# List processes
ps aux

# Real-time process viewer
top
htop    # (if installed)

# Find process by name
pgrep nginx
ps aux | grep nginx

# Kill process by PID
kill 1234
kill -9 1234    # Force kill

# Kill by name
pkill nginx
killall nginx

# Background processes
command &           # Run in background
jobs               # List background jobs
fg %1              # Bring job 1 to foreground
bg %1              # Continue job 1 in background

# Process tree
pstree

Memory and Disk Usage

# Memory usage
free -h

# Disk usage
df -h

# Directory size
du -sh /var/log
du -h --max-depth=1 /var

# Disk I/O statistics
iostat

# Memory info
cat /proc/meminfo

Network Commands

Network Configuration

# View IP addresses
ip addr
ip a

# View routing table
ip route
route -n

# Network interfaces (legacy)
ifconfig

# DNS resolution
nslookup google.com
dig google.com

# Test connectivity
ping -c 4 google.com

# Trace route
traceroute google.com
tracepath google.com

# View active connections
ss -tuln
netstat -tuln

# View network statistics
ss -s

Network Utilities

# Download files
wget https://example.com/file.zip
curl -O https://example.com/file.zip

# Transfer files via SSH
scp file.txt user@server:/path/
scp user@server:/path/file.txt ./

# Rsync (efficient sync)
rsync -avz source/ destination/
rsync -avz -e ssh source/ user@server:/destination/

# SSH connection
ssh user@server
ssh -p 2222 user@server    # Custom port

# Port scanning
nc -zv server.com 80
nmap server.com

Package Management

debian-ubuntu">APT (Debian/Ubuntu)

# Update package lists
sudo apt update

# Upgrade all packages
sudo apt upgrade

# Full upgrade (handles dependencies)
sudo apt full-upgrade

# Install package
sudo apt install package-name

# Remove package
sudo apt remove package-name

# Remove package and config
sudo apt purge package-name

# Search packages
apt search keyword

# Show package info
apt show package-name

# List installed packages
apt list --installed

# Clean up
sudo apt autoremove
sudo apt clean

centos">DNF/YUM (RHEL/Fedora/CentOS)

# Update package lists and upgrade
sudo dnf update

# Install package
sudo dnf install package-name

# Remove package
sudo dnf remove package-name

# Search packages
dnf search keyword

# Show package info
dnf info package-name

# List installed packages
dnf list installed

# Clean up
sudo dnf autoremove
sudo dnf clean all

# Enable repository
sudo dnf config-manager --enable repo-name

Service and Systemd Management

# Start service
sudo systemctl start nginx

# Stop service
sudo systemctl stop nginx

# Restart service
sudo systemctl restart nginx

# Reload configuration
sudo systemctl reload nginx

# Check status
sudo systemctl status nginx

# Enable at boot
sudo systemctl enable nginx

# Disable at boot
sudo systemctl disable nginx

# List all services
systemctl list-units --type=service

# List failed services
systemctl --failed

# View service logs
journalctl -u nginx
journalctl -u nginx --since "1 hour ago"
journalctl -u nginx -f    # Follow logs

Archive and Compression

# Create tar archive
tar -cvf archive.tar files/

# Create compressed tar.gz
tar -czvf archive.tar.gz files/

# Create compressed tar.bz2
tar -cjvf archive.tar.bz2 files/

# Extract tar archive
tar -xvf archive.tar

# Extract tar.gz
tar -xzvf archive.tar.gz

# Extract tar.bz2
tar -xjvf archive.tar.bz2

# Extract to specific directory
tar -xzvf archive.tar.gz -C /destination/

# List archive contents
tar -tvf archive.tar

# Compress with gzip
gzip file.txt

# Decompress gzip
gunzip file.txt.gz

# Zip files
zip archive.zip file1 file2
zip -r archive.zip directory/

# Unzip files
unzip archive.zip

Disk and Storage Management

# List block devices
lsblk

# Disk partitioning
sudo fdisk /dev/sdb
sudo parted /dev/sdb

# Create filesystem
sudo mkfs.ext4 /dev/sdb1
sudo mkfs.xfs /dev/sdb1

# Mount filesystem
sudo mount /dev/sdb1 /mnt/data

# Unmount filesystem
sudo umount /mnt/data

# View mounted filesystems
mount | column -t
findmnt

# Edit fstab for permanent mounts
sudo nano /etc/fstab

# Check filesystem
sudo fsck /dev/sdb1

# Disk usage analysis
ncdu /var    # (if installed)

SSH Key Management

# Generate SSH key pair
ssh-keygen -t ed25519 -C "your_email@example.com"
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

# Copy public key to server
ssh-copy-id user@server

# Manual copy (if ssh-copy-id unavailable)
cat ~/.ssh/id_ed25519.pub | ssh user@server "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"

# SSH agent
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519

# List added keys
ssh-add -l

# SSH config file (~/.ssh/config)
Host myserver
    HostName server.example.com
    User admin
    Port 2222
    IdentityFile ~/.ssh/id_ed25519

Cron Jobs and Scheduling

# Edit user crontab
crontab -e

# List crontab entries
crontab -l

# Crontab format:
# * * * * * command
# │ │ │ │ │
# │ │ │ │ └─── Day of week (0-7, Sun=0 or 7)
# │ │ │ └────── Month (1-12)
# │ │ └─────── Day of month (1-31)
# │ └──────── Hour (0-23)
# └───────── Minute (0-59)

# Examples:
# Run every day at 2:30 AM
30 2 * * * /path/to/script.sh

# Run every 15 minutes
*/15 * * * * /path/to/script.sh

# Run every Monday at 9 AM
0 9 * * 1 /path/to/script.sh

# Run on first of every month
0 0 1 * * /path/to/script.sh

# System cron directories
/etc/cron.daily/
/etc/cron.weekly/
/etc/cron.monthly/

Environment Variables

# View all environment variables
env
printenv

# View specific variable
echo $PATH
echo $HOME

# Set temporary variable
export MYVAR="value"

# Set permanent variable (add to ~/.bashrc or ~/.profile)
echo "export MYVAR=\"value\"" >> ~/.bashrc
source ~/.bashrc

# Unset variable
unset MYVAR

# Common variables
$PATH      # Executable search path
$HOME      # User home directory
$USER      # Current username
$SHELL     # Current shell
$PWD       # Current directory
$HOSTNAME  # System hostname

Command Chaining and Redirection

# Command chaining
command1 && command2    # Run command2 only if command1 succeeds
command1 || command2    # Run command2 only if command1 fails
command1 ; command2     # Run both regardless of success

# Output redirection
command > file.txt      # Redirect stdout (overwrite)
command >> file.txt     # Redirect stdout (append)
command 2> error.txt    # Redirect stderr
command &> all.txt      # Redirect both stdout and stderr
command 2>&1            # Redirect stderr to stdout

# Input redirection
command < input.txt     # Read input from file

# Pipes
command1 | command2     # Pipe output to input
ls -la | grep ".txt"
cat file.txt | sort | uniq

# Here document
cat << EOF > file.txt
Line 1
Line 2
Line 3
EOF

Best Practices

  1. Always use sudo carefully – Double-check commands before running with elevated privileges
  2. Use tab completion – Press Tab to auto-complete commands and file paths
  3. Read man pages – Use man command to learn more about any command
  4. Create aliases – Simplify frequently used commands
  5. Backup before changes – Always backup config files before editing
  6. Use version control – Track changes to important configurations with git
  7. Practice regularly – Set up a test environment for experimentation

Conclusion

Mastering these Linux commands is essential for anyone working with Linux systems. Start with the basics and gradually work your way up to more advanced commands. Practice regularly on a test system, and do not be afraid to use man pages to learn more about each command.

Ready to practice? Set up your own Linux server on Linode or DigitalOcean to get hands-on experience with these commands in a real environment.

Disclosure: This article contains affiliate links. If you purchase through these links, we may earn a commission at no additional cost to you. This helps support TheLinuxClub and allows us to continue creating free tutorials.

Was this article helpful?

R

About Ramesh Sundararamaiah

Red Hat Certified Architect

Expert in Linux system administration, DevOps automation, and cloud infrastructure. Specializing in Red Hat Enterprise Linux, CentOS, Ubuntu, Docker, Ansible, and enterprise IT solutions.

🐧 Stay Updated with Linux Tips

Get the latest tutorials, news, and guides delivered to your inbox weekly.

Add Comment