Table of Contents[Hide][Show]
Linux commands form the backbone of system administration and are essential tools for anyone working with Linux operating systems. Whether you’re a beginner just starting your Linux journey or an experienced administrator looking to refresh your knowledge, mastering these top 50 Linux commands you must know will significantly enhance your productivity and system management capabilities.
This comprehensive guide presents each command with detailed descriptions and practical examples, arranged in a randomised order to encourage diverse learning experiences.
Top 50 Linux Commands You Must Know
Essential File System Navigation Commands
1. mount – Mount File Systems in Linux
The mount command attaches file systems to the Linux directory tree, making them accessible to users and applications.
Description: This command allows you to mount various file systems including local drives, network shares, and removable media to specific mount points in your Linux system.
Example:
# Mount a USB drive
sudo mount /dev/sdb1 /mnt/usb
# Mount with specific file system type
sudo mount -t ext4 /dev/sda2 /home
# View all mounted file systems
mount
2. df – Display Disk Filesystem Information
The df command shows disk space usage for all mounted file systems, providing crucial information about storage capacity and availability.
Description: This utility displays the amount of disk space used and available on file systems, helping administrators monitor storage resources effectively.
Example:
# Display disk usage in human-readable format
df -h
# Show disk usage for specific directory
df -h /home
# Display inode usage
df -i
3. cd – Linux Command to Navigate Through Directories
The cd command changes the current working directory, enabling navigation through the Linux file system hierarchy.
Description: This fundamental navigation command allows users to move between directories efficiently, supporting both absolute and relative paths.
Example:
# Change to home directory
cd ~
# Move to parent directory
cd ..
# Change to specific directory
cd /var/log
# Return to previous directory
cd -
User and System Information Commands
3. whoami – Get the Active Username
The whoami command displays the current logged-in username, useful for scripts and system identification.
Description: This simple command returns the effective user ID of the current user, particularly helpful in multi-user environments or when using sudo.
Example:
# Display current username
whoami
# Use in scripts for conditional operations
if [ $(whoami) = "root" ]; then
echo "Running as root user"
fi
4. uname – Linux Command to Get Basic Information About the OS
The uname command provides essential system information including kernel version, architecture, and operating system details.
Description: This command reveals crucial system specifications that help in troubleshooting, software compatibility checks, and system documentation.
Example:
# Display all system information
uname -a
# Show kernel version only
uname -r
# Display machine architecture
uname -m
# Show operating system name
uname -s
File Compression and Archive Management
5. zip – Zip Files in Linux
The zip command creates compressed archive files using the ZIP compression format, widely compatible across different operating systems.
Description: This utility compresses files and directories into ZIP archives, reducing storage space and facilitating file transfer.
Example:
# Create a ZIP archive
zip archive.zip file1.txt file2.txt
# Compress directory recursively
zip -r backup.zip /home/user/documents
# Create password-protected archive
zip -P password secure.zip confidential.txt
6. tar – Command to Extract and Compress Files in Linux
The tar command creates and manipulates archive files, commonly used for backup and distribution purposes.
Description: Originally designed for tape archives, tar combines multiple files into a single archive and can work with various compression algorithms.
Example:
# Create compressed archive
tar -czvf backup.tar.gz /home/user
# Extract archive
tar -xzvf backup.tar.gz
# List archive contents
tar -tvf backup.tar.gz
# Extract specific files
tar -xzvf backup.tar.gz specific_file.txt
7. unzip – Unzip Files in Linux
The unzip command extracts files from ZIP archives, complementing the zip command functionality.
Description: This utility decompresses ZIP files and restores the original file structure, supporting various extraction options.
Example:
# Extract all files from ZIP archive
unzip archive.zip
# Extract to specific directory
unzip archive.zip -d /destination/path
# List archive contents without extracting
unzip -l archive.zip
# Extract with password
unzip -P password secure.zip
User and Permission Management
8. useradd and usermod – Add a New User or Change Existing User Data
The useradd and usermod commands manage user accounts, allowing administrators to create new users and modify existing accounts.
Description: These commands provide comprehensive user account management capabilities, including setting home directories, shells, and group memberships.
Example:
# Add new user
sudo useradd -m -s /bin/bash newuser
# Add user to specific group
sudo useradd -G sudo,developers -m johndoe
# Modify existing user
sudo usermod -aG docker existinguser
# Change user's shell
sudo usermod -s /bin/zsh username
9. passwd – Create or Update Passwords for Existing Users
The passwd command manages user passwords, providing essential security functionality for user authentication.
Description: This command allows users to change their passwords and enables administrators to set or reset passwords for system accounts.
Example:
# Change current user's password
passwd
# Change another user's password (as root)
sudo passwd username
# Lock user account
sudo passwd -l username
# Unlock user account
sudo passwd -u username
These Linux command is essential for maintaining account security and access control.
Process Management Commands
10. kill and killall – Kill Active Processes by Process ID or Name
The kill and killall commands terminate running processes, providing essential process management capabilities.
Description: These commands send signals to processes to terminate them gracefully or forcefully, helping maintain system stability and resource management.
Example:
# Kill process by PID
kill 1234
# Force kill process
kill -9 1234
# Kill all processes by name
killall firefox
# Send specific signal
kill -TERM 5678
11. ps – Display Active Processes
The ps command shows currently running processes with detailed information about their status and resource usage.
Description: This command provides snapshots of running processes, displaying process IDs, CPU usage, memory consumption, and command information.
Example:
# Show all processes for current user
ps aux
# Display process tree
ps auxf
# Show specific user processes
ps -u username
# Show processes with specific command
ps aux | grep nginx
12. top – View Active Processes Live with Their System Usage
The top command provides real-time monitoring of system processes and resource utilization.
Description: This interactive command displays a continuously updated list of processes, showing CPU usage, memory consumption, and system load in real-time.
Example:
# Launch top with default settings
top
# Sort by memory usage
top -o %MEM
# Show processes for specific user
top -u username
# Batch mode for scripts
top -b -n 1
Text Processing and Search Commands
13. grep – Search for a String Within an Output
The grep command searches for patterns within files or command output, providing powerful text filtering capabilities.
Description: This versatile command uses regular expressions to find and display lines containing specific patterns, essential for log analysis and data filtering.
Example:
# Search for pattern in file
grep "error" /var/log/syslog
# Case-insensitive search
grep -i "warning" logfile.txt
# Search recursively in directories
grep -r "TODO" /home/user/code
# Show line numbers
grep -n "pattern" file.txt
14. sort – Linux Command to Sort the Content of a File While Outputting
The sort command arranges lines in text files according to specified criteria, supporting various sorting options.
Description: This utility sorts file contents alphabetically, numerically, or by custom criteria, often used in data processing pipelines.
Example:
# Sort file alphabetically
sort names.txt
# Sort numerically
sort -n numbers.txt
# Reverse sort
sort -r file.txt
# Sort by specific column
sort -k2 data.txt
15. head – Return the Specified Number of Lines from the Top
The head command displays the first few lines of files, useful for quick file previews.
Description: This command shows the beginning portion of files, with configurable line counts for efficient content sampling.
Example:
# Show first 10 lines (default)
head file.txt
# Show first 5 lines
head -n 5 file.txt
# Show first 20 bytes
head -c 20 file.txt
16. tail – Return the Specified Number of Lines from the Bottom
The tail command displays the last few lines of files, particularly useful for monitoring log files.
Description: This command shows the end portion of files and can follow files in real-time, making it invaluable for log monitoring.
Example:
# Show last 10 lines (default)
tail file.txt
# Show last 20 lines
tail -n 20 file.txt
# Follow file changes in real-time
tail -f /var/log/syslog
# Follow multiple files
tail -f file1.log file2.log
File Operations and Management
17. touch – Create Blank/Empty Files
The touch command creates empty files or updates timestamps of existing files.
Description: This versatile command creates new files instantly and modifies access/modification times of existing files.
Example:
# Create new empty file
touch newfile.txt
# Create multiple files
touch file1.txt file2.txt file3.txt
# Update file timestamp
touch existing_file.txt
# Set specific timestamp
touch -t 202301011200 file.txt
18. cp – Similar Usage as mv but for Copying Files in Linux
The cp command creates copies of files and directories, preserving original content while duplicating it to new locations.
Description: This essential command duplicates files and directories with various options for preserving permissions, timestamps, and handling symbolic links.
Example:
# Copy file to new location
cp source.txt destination.txt
# Copy directory recursively
cp -r source_dir destination_dir
# Preserve permissions and timestamps
cp -p file.txt backup.txt
# Copy with verbose output
cp -v file1.txt file2.txt
19. mv – Move or Rename Files in Linux
The mv command moves files and directories to new locations or renames them within the same directory.
Description: This command performs both file moving and renaming operations efficiently, transferring files between directories or changing their names.
Example:
# Move file to different directory
mv file.txt /new/location/
# Rename file
mv oldname.txt newname.txt
# Move multiple files
mv file1.txt file2.txt /destination/
# Move with backup
mv -b file.txt /backup/location/
20. rm – Delete Files or Directories
The rm command removes files and directories permanently from the file system.
Description: This powerful command deletes files and directories with various safety options to prevent accidental removal of important data.
Example:
# Remove single file
rm file.txt
# Remove directory and contents
rm -r directory/
# Force remove without prompts
rm -f file.txt
# Remove with confirmation
rm -i important_file.txt
Directory Operations
21. mkdir – Command Used to Create Directories in Linux
The mkdir command creates new directories in the file system hierarchy.
Description: This command establishes new directory structures with options for creating parent directories and setting permissions.
Example:
# Create single directory
mkdir new_directory
# Create nested directories
mkdir -p path/to/nested/directory
# Create with specific permissions
mkdir -m 755 public_dir
# Create multiple directories
mkdir dir1 dir2 dir3
22. pwd – Print Working Directory Command in Linux
The pwd command displays the current working directory’s absolute path.
Description: This command shows the complete path from the root directory to your current location in the file system.
Example:
# Display current directory
pwd
# Show logical path (with symlinks)
pwd -L
# Show physical path (resolved symlinks)
pwd -P
File Content Display and Processing
33. cat – Display File Contents on the Terminal
The cat command displays file contents directly in the terminal, useful for viewing small to medium-sized files.
Description: This command reads files and displays their entire content on standard output, often used in command pipelines.
Example:
# Display file contents
cat file.txt
# Display multiple files
cat file1.txt file2.txt
# Number all lines
cat -n file.txt
# Show non-printing characters
cat -A file.txt
34. echo – Print Any Text That Follows the Command
The echo command outputs text to the terminal or redirects it to files.
Description: This command prints specified text strings and can be used to create simple text files or display variables and messages.
Example:
# Print simple message
echo "Hello, World!"
# Display variable value
echo $HOME
# Write to file
echo "New content" > file.txt
# Append to file
echo "Additional content" >> file.txt
35. less – Linux Command to Display Paged Outputs in the Terminal
The less command displays file contents page by page, allowing easy navigation through large files.
Description: This pager command provides interactive file viewing with search capabilities and memory-efficient handling of large files.
Example:
# View file with less
less large_file.txt
# View with line numbers
less -N file.txt
# Search within less (press /)
# /search_term
# View multiple files
less file1.txt file2.txt
Network and Remote Access Commands
35. ssh – Secure Shell Command in Linux
The ssh command establishes secure connections to remote Linux systems for administration and file transfer.
Description: This cryptographic network protocol provides encrypted communication channels for secure remote access and command execution.
Example:
# Connect to remote server
ssh user@remote-server.com
# Connect with specific port
ssh -p 2222 user@server.com
# Execute single command remotely
ssh user@server.com 'ls -la'
# Use private key for authentication
ssh -i ~/.ssh/private_key user@server.com
36. wget – Direct Download Files from the Internet
The wget command downloads files from web servers using HTTP, HTTPS, and FTP protocols.
Description: This non-interactive downloader retrieves files from the internet with support for resuming interrupted downloads and recursive downloading.
Example:
# Download single file
wget https://example.com/file.zip
# Download with custom filename
wget -O custom_name.zip https://example.com/file.zip
# Resume interrupted download
wget -c https://example.com/large_file.iso
# Download recursively
wget -r https://example.com/directory/
37. ifconfig – Display Network Interfaces and IP Addresses
The ifconfig command displays and configures network interface parameters.
Description: This command shows network interface information including IP addresses, netmasks, and interface statistics, essential for network troubleshooting.
Example:
# Display all interfaces
ifconfig
# Show specific interface
ifconfig eth0
# Configure IP address
sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0
# Bring interface up/down
sudo ifconfig eth0 up
sudo ifconfig eth0 down
38. traceroute – Trace All the Network Hops to Reach the Destination
The traceroute command traces the path packets take from source to destination across networks.
Description: This diagnostic tool shows each hop along the network route, helping identify network connectivity issues and routing problems.
Example:
# Trace route to destination
traceroute google.com
# Use numeric output (no DNS lookup)
traceroute -n 8.8.8.8
# Specify maximum hops
traceroute -m 15 destination.com
# Use UDP packets
traceroute -U target.com
System Control and Security Commands
39. sudo – Command to Escalate Privileges in Linux
The sudo command allows users to execute commands with elevated privileges while maintaining accountability.
Description: This security-focused command enables users to perform administrative tasks without switching to the root account permanently.
Example:
# Execute command as root
sudo systemctl restart nginx
# Run command as specific user
sudo -u www-data ls /var/www
# Edit file with elevated privileges
sudo nano /etc/hosts
# Switch to root shell
sudo -i
40. chmod – Command to Change File Permissions
The chmod command modifies file and directory permissions, controlling read, write, and execute access.
Description: This command uses numeric or symbolic notation to set permissions for owner, group, and other users, fundamental for system security.
Example:
# Set permissions using numeric notation
chmod 755 script.sh
# Add execute permission for owner
chmod u+x file.txt
# Remove write permission for group
chmod g-w document.txt
# Set permissions recursively
chmod -R 644 /web/content/
41. chown – Command for Granting Ownership of Files or Folders
The chown command changes file and directory ownership, transferring control between users and groups.
Description: This command modifies the user and group ownership of files and directories, essential for access control and security management.
Example:
# Change owner only
sudo chown newuser file.txt
# Change owner and group
sudo chown newuser:newgroup file.txt
# Change ownership recursively
sudo chown -R user:group /directory/
# Change group only
sudo chown :newgroup file.txt
System Utilities and Management
41. service – Linux Command to Start and Stop Services
The service command manages system services, providing control over background processes and daemons.
Description: This command interface controls system services, allowing administrators to start, stop, restart, and check service status.
Example:
# Start service
sudo service nginx start
# Stop service
sudo service apache2 stop
# Restart service
sudo service mysql restart
# Check service status
service --status-all
42. clear – Clear the Terminal Display
The clear command clears the terminal screen, providing a clean workspace for continued operations.
Description: This simple command removes all previous output from the terminal screen, improving readability and focus.
Example:
# Clear terminal screen
clear
# Alternative using keyboard shortcut
# Ctrl+L
# Clear and show current directory
clear && pwd
43. cal – View a Command-line Calendar
The cal command displays calendar information directly in the terminal.
Description: This utility shows monthly or yearly calendars with current date highlighting, useful for scheduling and date reference.
Example:
# Display current month calendar
cal
# Show specific month and year
cal 12 2024
# Display entire year
cal 2024
# Show three months (previous, current, next)
cal -3
File Comparison and Analysis
44. diff – Find the Difference Between Two Files
The diff command compares files line by line and displays differences between them.
Description: This command identifies and reports differences between files, essential for code review, configuration management, and data comparison.
Example:
# Compare two files
diff file1.txt file2.txt
# Show unified diff format
diff -u original.txt modified.txt
# Compare directories
diff -r dir1/ dir2/
# Ignore whitespace differences
diff -w file1.txt file2.txt
45. cmp – Allows You to Check if Two Files Are Identical
The cmp command compares two files byte by byte and reports the first difference found.
Description: This binary-safe comparison tool determines if files are identical and locates the first byte position where they differ.
Example:
# Compare two files
cmp file1.txt file2.txt
# Silent mode (exit code only)
cmp -s file1.bin file2.bin
# Show all differences
cmp -l binary1.bin binary2.bin
# Verbose output
cmp -v identical1.txt identical2.txt
46. comm – Combines the Functionality of diff and cmp
The comm command compares two sorted files line by line and displays lines that are unique or common.
Description: This command produces three-column output showing lines unique to each file and lines common to both files.
Example:
# Compare sorted files
comm file1.txt file2.txt
# Show only lines unique to first file
comm -23 file1.txt file2.txt
# Show only lines common to both files
comm -12 file1.txt file2.txt
# Suppress column output
comm -3 file1.txt file2.txt
Advanced System Commands
47. man – Access Manual Pages for All Linux Commands
The man command displays comprehensive documentation for Linux commands and system functions.
Description: This command provides detailed manual pages containing syntax, options, examples, and related information for virtually every Linux command.
Example:
# View manual for command
man ls
# Search manual pages
man -k "network"
# Show specific manual section
man 5 passwd
# Display manual page locations
man -w grep
48. whereis – Locate the Binary, Source, and Manual Pages for a Command
The whereis command locates the binary, source files, and manual pages for specified commands.
Description: This command searches standard directories to find executable files, source code, and documentation for system commands.
Example:
# Locate command files
whereis ls
# Show only binary location
whereis -b python
# Show only manual pages
whereis -m gcc
# Search in specific directories
whereis -B /usr/bin -f command
49. whatis – Find What a Command Is Used For
The whatis command displays brief descriptions of system commands from manual page databases.
Description: This command provides one-line summaries of command functionality, useful for quick reference and command discovery.
Example:
# Get command description
whatis ls
# Search multiple commands
whatis cp mv rm
# Update whatis database
sudo mandb
# Search with wildcards
whatis -w "net*"
50. alias – Create Custom Shortcuts for Your Regularly Used Commands
The alias command creates custom shortcuts for frequently used command sequences.
Description: This command defines short names for long commands or command combinations, improving efficiency and reducing typing effort.
Example:
# Create simple alias
alias ll='ls -la'
# Create complex alias
alias backup='tar -czvf backup_$(date +%Y%m%d).tar.gz'
# View all aliases
alias
# Remove alias
unalias ll
Specialized System Commands
51. ln – Create Symbolic Links (Shortcuts) to Other Files
The ln command creates links between files, both hard links and symbolic links.
Description: This command establishes file links that provide alternative pathways to access the same file data, useful for organization and accessibility.
Example:
# Create symbolic link
ln -s /path/to/original /path/to/link
# Create hard link
ln original_file hard_link
# Create symbolic link in current directory
ln -s /usr/local/bin/program ./program
# Force link creation (overwrite existing)
ln -sf target link_name
52. export – Export Environment Variables in Linux
The export command sets environment variables that are available to child processes.
Description: This command makes variables available to all subsequent commands and subprocesses in the current shell session.
Example:
# Export new variable
export PATH=$PATH:/new/directory
# Export with value
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk
# Export multiple variables
export VAR1=value1 VAR2=value2
# View all exported variables
export
53. dd – Majorly Used for Creating Bootable USB Sticks
The dd command performs low-level copying and conversion of raw data between devices and files.
Description: This powerful command copies data at the byte level, commonly used for creating disk images, bootable media, and forensic data recovery.
Example:
# Create bootable USB (DANGEROUS - verify device)
sudo dd if=ubuntu.iso of=/dev/sdb bs=4M status=progress
# Create disk image
dd if=/dev/sda of=backup.img bs=1M
# Wipe disk with zeros
sudo dd if=/dev/zero of=/dev/sdb bs=1M
# Copy with specific block size
dd if=input.file of=output.file bs=64K
Firewall and Security Management
54. ufw – Firewall Command
The ufw (Uncomplicated Firewall) command provides a simplified interface for managing iptables firewall rules.
Description: This user-friendly firewall management tool simplifies the process of configuring network security rules and access controls.
Example:
# Enable firewall
sudo ufw enable
# Allow specific port
sudo ufw allow 22
# Allow service by name
sudo ufw allow ssh
# Deny specific IP
sudo ufw deny from 192.168.1.100
# Check firewall status
sudo ufw status
55. iptables – Base Firewall for All Other Firewall Utilities to Interface With
The iptables command provides advanced firewall configuration through direct rule manipulation.
Description: This low-level firewall interface offers complete control over packet filtering, network address translation, and traffic routing.
Example:
# List current rules
sudo iptables -L
# Allow incoming SSH
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
# Block specific IP
sudo iptables -A INPUT -s 192.168.1.100 -j DROP
# Save rules (Ubuntu)
sudo iptables-save > /etc/iptables/rules.v4
56. apt, pacman, yum, rpm – Package Managers Depending on the Distribution
These package management commands handle software installation, updates, and removal across different Linux distributions.
Description: Package managers provide centralized software management, handling dependencies, updates, and system maintenance automatically.
Example:
# APT (Debian/Ubuntu)
sudo apt update && sudo apt upgrade
sudo apt install package-name
sudo apt remove package-name
# YUM (Red Hat/CentOS)
sudo yum update
sudo yum install package-name
sudo yum remove package-name
# Pacman (Arch Linux)
sudo pacman -Syu
sudo pacman -S package-name
sudo pacman -R package-name
Conclusion
Mastering these Linux commands you must know provides a solid foundation for effective system administration and daily Linux usage. Each command serves specific purposes, from basic file operations to advanced system management and security configuration. Regular practice with these commands will improve your efficiency and confidence when working with Linux systems.
These top 50 Linux commands cover essential areas including file management, process control, network operations, security, and system maintenance. Whether you’re managing servers, developing applications, or simply using Linux as your daily operating system, these commands form the core toolkit that every Linux user should master.
Remember that most commands offer extensive options and parameters beyond these basic examples. Use the man command to explore detailed documentation for any command, and practice regularly to build muscle memory for the most frequently used operations. With consistent use, these commands will become second nature, significantly enhancing your productivity and system administration capabilities.

Arch Linux Rolls Out “Bumpbuddy” to Fast-Track Package Updates