Linux powers everything from personal computers to enterprise servers, cloud infrastructure, and even Android smartphones. Whether you're a system administrator, developer, or curious user looking to expand your technical skills, mastering Linux commands is essential for efficiently managing and navigating Linux systems.
This comprehensive guide covers 100 of the most useful Linux commands, organized by category to help you find exactly what you need. Each command includes a clear explanation, common use cases, and practical examples to enhance your understanding. By the end of this guide, you'll have a powerful toolkit of commands to tackle almost any task in your Linux environment.
Table of Contents:
The ls
command is one of the most frequently used commands in Linux. It lists the contents of a directory.
Basic usage:
ls
Common options:
ls -l
: Long format listing (shows permissions, owner, size, date)ls -a
: List all files (including hidden files)ls -la
: Combine long format and all filesls -lh
: Human-readable file sizes (KB, MB, GB)The cd
command is used to navigate between directories.
Basic usage:
cd /path/to/directory
Common uses:
cd ..
: Move to parent directorycd ~
: Move to home directorycd -
: Move to previous directorycd /
: Move to root directorypwd
displays the full path of your current directory.
Basic usage:
pwd
The mkdir
command creates new directories.
Basic usage:
mkdir new_directory
Common options:
mkdir -p parent/child/grandchild
: Create nested directoriesrmdir
removes empty directories.
Basic usage:
rmdir directory_name
The rm
command deletes files or directories.
Basic usage:
rm filename
Common options:
rm -r directory
: Remove directory and its contents recursivelyrm -f file
: Force removal without confirmationrm -i file
: Interactive mode (asks for confirmation)Warning: Be extremely careful with rm -rf
as it can delete files and directories without confirmation!
cp
copies files and directories from one location to another.
Basic usage:
cp source destination
Common options:
cp -r source_dir destination_dir
: Copy directories recursivelycp -i source destination
: Interactive mode (asks before overwriting)cp -p source destination
: Preserve file attributes (permissions, timestamps)The mv
command moves or renames files and directories.
Basic usage:
mv source destination
Common uses:
mv file1 file2
: Rename file1 to file2mv file directory/
: Move file to directorymv -i source destination
: Interactive mode (asks before overwriting)touch
creates empty files or updates the access and modification times of existing files.
Basic usage:
touch filename
Common options:
touch -a filename
: Update only access timetouch -m filename
: Update only modification timetouch -c filename
: Don't create file if it doesn't existThe ln
command creates links between files.
Basic usage:
ln -s target_file link_name
Common options:
ln -s
: Create symbolic link (soft link)ln
: Create hard linkcat
displays the contents of files.
Basic usage:
cat filename
Common options:
cat -n filename
: Show line numberscat file1 file2
: Concatenate multiple filescat > file
: Create a new file (end with Ctrl+D)The less
command allows you to view file contents page by page.
Basic usage:
less filename
Navigation in less:
head
displays the first part of a file.
Basic usage:
head filename
Common options:
head -n 20 filename
: Display first 20 linestail
displays the last part of a file.
Basic usage:
tail filename
Common options:
tail -n 20 filename
: Display last 20 linestail -f logfile
: Follow mode (continuously update as file grows)nano
is a user-friendly text editor for beginners.
Basic usage:
nano filename
Common shortcuts:
vim
is a powerful text editor with a steeper learning curve.
Basic usage:
vim filename
Basic commands in vim:
The diff
command compares files line by line.
Basic usage:
diff file1 file2
Common options:
diff -u file1 file2
: Unified formatdiff -y file1 file2
: Side-by-side comparisonThe tar
command creates and extracts archives.
Basic usage:
# Create archive
tar -cvf archive.tar files
# Extract archive
tar -xvf archive.tar
Common options:
c
: Create archivex
: Extract archivev
: Verbose (show progress)f
: Specify filenamez
: Compress with gzipj
: Compress with bzip2gzip
compresses files using the gzip algorithm.
Basic usage:
gzip filename
Common options:
gzip -d file.gz
: Decompress (same as gunzip)gzip -k file
: Keep original filegzip -9 file
: Best compressionThe zip
and unzip
commands work with ZIP archives.
Basic usage:
# Create zip archive
zip archive.zip files
# Extract zip archive
unzip archive.zip
Common options:
zip -r archive.zip directory
: Recursively zip directoryunzip -l archive.zip
: List contents without extractingThe chmod
command changes file permissions.
Basic usage:
chmod permissions filename
Permission examples:
chmod 755 file
: rwx for owner, rx for group and otherschmod +x file
: Add execute permission for allchmod u+w file
: Add write permission for ownerchmod g-w file
: Remove write permission for groupchown
changes the owner and group of files and directories.
Basic usage:
chown owner:group filename
Examples:
chown user file
: Change owner to userchown user:group file
: Change owner and groupchown -R user:group directory
: Recursively change ownershipThe chgrp
command changes the group ownership of files.
Basic usage:
chgrp group filename
Common options:
chgrp -R group directory
: Recursively change groupThe ps
command shows information about active processes.
Basic usage:
ps
Common options:
ps aux
: Show all processes for all usersps -ef
: Full format listingps --forest
: Show process treetop
provides a dynamic, real-time view of running processes.
Basic usage:
top
Interactive commands in top:
The kill
command sends signals to processes, often used to terminate them.
Basic usage:
kill PID
Common signals:
kill -9 PID
: Force kill (SIGKILL)kill -15 PID
: Graceful termination (SIGTERM, default)kill -1 PID
: Reload configuration (SIGHUP)killall
terminates processes by name.
Basic usage:
killall process_name
Example:
killall firefox
The pkill
command allows killing processes based on name and other attributes.
Basic usage:
pkill process_name
Common options:
pkill -u username
: Kill processes owned by usernamepkill -9 process_name
: Force killbg
continues execution of suspended jobs in the background.
Basic usage:
bg [job_spec]
The fg
command brings background jobs to the foreground.
Basic usage:
fg [job_spec]
jobs
lists the active jobs in the current shell.
Basic usage:
jobs
Common options:
jobs -l
: Include process IDsThe nice
command runs a program with modified scheduling priority.
Basic usage:
nice -n priority command
Example:
nice -n 10 ./cpu_intensive_task
uname
displays system information.
Basic usage:
uname
Common options:
uname -a
: All informationuname -r
: Kernel releaseuname -m
: Machine hardware nameThe whoami
command displays the current username.
Basic usage:
whoami
who
shows who is logged on.
Basic usage:
who
The date
command displays or sets the system date and time.
Basic usage:
date
Common formats:
date "+%Y-%m-%d"
: Display date as YYYY-MM-DDdate "+%H:%M:%S"
: Display time as HH:MM:SSuptime
shows how long the system has been running.
Basic usage:
uptime
The free
command displays the amount of free and used memory.
Basic usage:
free
Common options:
free -h
: Human-readable outputfree -m
: Display in megabytesfree -g
: Display in gigabytesdf
reports file system disk space usage.
Basic usage:
df
Common options:
df -h
: Human-readable outputdf -T
: Show file system typeThe du
command estimates file space usage.
Basic usage:
du directory
Common options:
du -h
: Human-readable sizesdu -s
: Summary (only total)du -a
: Include all files, not just directoriesuseradd
creates a new user account.
Basic usage:
sudo useradd username
Common options:
useradd -m username
: Create home directoryuseradd -G group1,group2 username
: Add to supplementary groupsuseradd -s /bin/bash username
: Specify shellThe userdel
command deletes a user account.
Basic usage:
sudo userdel username
Common options:
userdel -r username
: Remove home directory and mail spoolusermod
modifies a user account.
Basic usage:
sudo usermod options username
Common options:
usermod -aG group username
: Add to supplementary groupusermod -L username
: Lock accountusermod -U username
: Unlock accountThe passwd
command changes user passwords.
Basic usage:
passwd
Common options:
passwd username
: Change another user's password (as root)passwd -l username
: Lock accountpasswd -u username
: Unlock accountgroupadd
creates a new group.
Basic usage:
sudo groupadd groupname
The groupdel
command deletes a group.
Basic usage:
sudo groupdel groupname
su
allows you to switch to another user.
Basic usage:
su username
Common options:
su -
: Switch to root with environmentsu - username
: Switch to user with environmentThe sudo
command executes a command as another user (typically root).
Basic usage:
sudo command
Common options:
sudo -u username command
: Run as specified usersudo -i
: Start a shell as rootping
sends ICMP echo requests to network hosts.
Basic usage:
ping hostname
Common options:
ping -c 5 hostname
: Send 5 packets onlyping -i 2 hostname
: Wait 2 seconds between packetsThe ifconfig
command configures network interfaces.
Basic usage:
ifconfig
Common options:
ifconfig interface
: Show specific interfaceifconfig interface up/down
: Enable/disable interfaceNote: On newer systems, ip
command is preferred.
The ip
command is the modern replacement for ifconfig.
Basic usage:
ip addr show
Common subcommands:
ip link
: Network device operationsip addr
: Protocol address managementip route
: Routing table managementnetstat
displays network connections, routing tables, and more.
Basic usage:
netstat
Common options:
netstat -tuln
: Show listening TCP and UDP portsnetstat -r
: Show routing tablenetstat -i
: Show network interfacesThe ss
command is a newer alternative to netstat.
Basic usage:
ss
Common options:
ss -tuln
: Show listening TCP and UDP portsss -ta
: Show all TCP connectionswget
downloads files from the web.
Basic usage:
wget URL
Common options:
wget -O filename URL
: Save with different filenamewget -c URL
: Continue interrupted downloadwget -r URL
: Recursive downloadThe curl
command transfers data from or to a server.
Basic usage:
curl URL
Common options:
curl -o filename URL
: Save output to filecurl -I URL
: Fetch HTTP headers onlycurl -X POST URL -d "data"
: Send POST requestssh
is a secure shell client for remote login.
Basic usage:
ssh user@hostname
Common options:
ssh -p port user@hostname
: Connect to specific portssh -i key_file user@hostname
: Use specific identity fileThe scp
command securely copies files between hosts.
Basic usage:
scp source user@host:destination
Examples:
scp file.txt user@remote:/path/
: Copy local file to remotescp user@remote:/path/file.txt local/
: Copy remote file to localscp -r directory user@remote:/path/
: Copy directory recursivelyrsync
synchronizes files and directories between locations.
Basic usage:
rsync options source destination
Common options:
rsync -avz source/ destination/
: Archive mode with compressionrsync -avz --delete source/ destination/
: Delete files in destination not in sourcersync -avz -e ssh source/ user@host:destination/
: Use SSH as transportapt
manages packages on Debian-based systems.
Basic usage:
sudo apt update
sudo apt install package
Common commands:
apt update
: Update package listsapt upgrade
: Upgrade installed packagesapt install package
: Install packageapt remove package
: Remove packageapt search package
: Search for packageapt-get
is a command-line tool for handling packages.
Basic usage:
sudo apt-get update
sudo apt-get install package
Common commands:
apt-get update
: Update package listsapt-get upgrade
: Upgrade packagesapt-get dist-upgrade
: Upgrade with dependency handlingapt-get autoremove
: Remove unnecessary packagesThe dpkg
command manages Debian packages.
Basic usage:
sudo dpkg -i package.deb
Common options:
dpkg -i package.deb
: Install packagedpkg -r package
: Remove packagedpkg -l
: List installed packagesdpkg -S file
: Find which package a file belongs toyum
manages packages on Red Hat-based systems.
Basic usage:
sudo yum install package
Common commands:
yum update
: Update packagesyum install package
: Install packageyum remove package
: Remove packageyum search keyword
: Search for packagesdnf
is the next-generation version of yum.
Basic usage:
sudo dnf install package
Common commands:
dnf update
: Update packagesdnf search term
: Search for packagesdnf list installed
: List installed packagesThe rpm
command manages RPM packages.
Basic usage:
sudo rpm -i package.rpm
Common options:
rpm -i package.rpm
: Install packagerpm -e package
: Erase (remove) packagerpm -q package
: Query if package is installedrpm -qa
: List all installed packagesfdisk
is a dialog-driven program for partition manipulation.
Basic usage:
sudo fdisk /dev/sdX
Common commands within fdisk:
p
: Print partition tablen
: Add a new partitiond
: Delete a partitionw
: Write changes and exitq
: Quit without saving changesThe mount
command mounts a filesystem.
Basic usage:
sudo mount device directory
Examples:
mount /dev/sdb1 /mnt
: Mount partition to /mntmount -t type device directory
: Specify filesystem typeumount
unmounts a filesystem.
Basic usage:
sudo umount directory
Common options:
umount -f directory
: Force unmountumount -l directory
: Lazy unmountThe lsblk
command lists information about all block devices.
Basic usage:
lsblk
Common options:
lsblk -f
: Show filesystem informationlsblk -m
: Show permissionsblkid
displays attributes of block devices.
Basic usage:
sudo blkid
Common options:
blkid /dev/sdX
: Show specific deviceThe mkfs
command builds a Linux filesystem.
Basic usage:
sudo mkfs -t type device
Examples:
mkfs.ext4 /dev/sdb1
: Create ext4 filesystemmkfs.ntfs /dev/sdc1
: Create NTFS filesystemfind
searches for files in a directory hierarchy.
Basic usage:
find path -name pattern
Common options:
find /home -name "*.txt"
: Find .txt files in /homefind / -type f -size +100M
: Find files larger than 100MBfind /var -mtime -7
: Find files modified in the last 7 daysfind . -type f -exec command {} \;
: Execute command on each fileThe locate
command finds files by name, using a database.
Basic usage:
locate pattern
Common options:
locate -i pattern
: Case-insensitive searchupdatedb
: Update the locate databasewhereis
locates the binary, source, and manual page files for a command.
Basic usage:
whereis command
Common options:
whereis -b command
: Search only for binariesThe which
command shows the full path of shell commands.
Basic usage:
which command
Example:
which python
grep
searches text for patterns.
Basic usage:
grep pattern file
Common options:
grep -i pattern file
: Case-insensitive searchgrep -r pattern directory
: Recursive searchgrep -v pattern file
: Invert match (lines NOT matching)grep -n pattern file
: Show line numbersThe egrep
command is like grep but uses extended regular expressions.
Basic usage:
egrep "pattern1|pattern2" file
sed
is a stream editor for filtering and transforming text.
Basic usage:
sed 's/old/new/' file
Common uses:
sed 's/old/new/g' file
: Replace all occurrencessed -i 's/old/new/g' file
: Edit file in placesed '5d' file
: Delete line 5sed '/pattern/d' file
: Delete lines matching patternThe awk
command is a powerful text processing tool.
Basic usage:
awk 'pattern {action}' file
Examples:
awk '{print $1}' file
: Print first columnawk -F: '{print $1}' /etc/passwd
: Set field separator to ":"awk '/pattern/ {print $0}'
: Print lines matching patternsort
sorts lines of text files.
Basic usage:
sort file
Common options:
sort -r file
: Reverse ordersort -n file
: Numeric sortsort -k 2 file
: Sort by second fieldsort -u file
: Remove duplicatesThe uniq
command filters adjacent matching lines.
Basic usage:
uniq file
Common options:
uniq -c file
: Count occurrencesuniq -d file
: Only print duplicate lineswc
prints newline, word, and byte counts.
Basic usage:
wc file
Common options:
wc -l file
: Count lines onlywc -w file
: Count words onlywc -c file
: Count bytes onlyThe cut
command removes sections from lines of files.
Basic usage:
cut options file
Common options:
cut -d: -f1 /etc/passwd
: Cut field 1 using ":" as delimitercut -c1-5 file
: Cut characters 1-5 from each lineecho
displays a line of text.
Basic usage:
echo "Hello, World!"
Common options:
echo -n "text"
: No trailing newlineecho -e "line1\nline2"
: Interpret backslash escapesThe read
command reads a line from standard input.
Basic usage:
read variable
Common options:
read -p "Prompt: " variable
: Display promptread -s variable
: Silent mode (for passwords)read -t 10 variable
: Timeout after 10 secondstest
evaluates expressions.
Basic usage:
test expression
Alternative syntax:
[ expression ]
Common tests:
[ -f file ]
: True if file exists and is regular file[ -d directory ]
: True if directory exists[ string1 = string2 ]
: True if strings are equal[ $num1 -eq $num2 ]
: True if numbers are equalThe if
command performs conditional execution.
Basic syntax:
if condition; then
commands
elif condition; then
commands
else
commands
fi
for
loops over a list of values.
Basic syntax:
for variable in list; do
commands
done
Example:
for i in 1 2 3; do
echo $i
done
The while
command loops while a condition is true.
Basic syntax:
while condition; do
commands
done
Example:
i=1
while [ $i -le 5 ]; do
echo $i
i=$((i+1))
done
case
provides conditional branching based on pattern matching.
Basic syntax:
case expression in
pattern1) commands ;;
pattern2) commands ;;
*) default commands ;;
esac
The source
command runs commands from a file in the current shell.
Basic usage:
source filename
Alternative:
. filename
htop
is an interactive process viewer.
Basic usage:
htop
Features:
The iostat
command reports CPU and I/O statistics.
Basic usage:
iostat
Common options:
iostat -d
: Device utilization reportiostat -x
: Extended statisticsiostat 2 5
: Report every 2 seconds, 5 timesvmstat
reports virtual memory statistics.
Basic usage:
vmstat
Common options:
vmstat 2 5
: Report every 2 seconds, 5 timesvmstat -S M
: Display in megabytesThe mpstat
command reports processors statistics.
Basic usage:
mpstat
Common options:
mpstat -P ALL
: Show statistics for all CPUsmpstat 2 5
: Report every 2 seconds, 5 timesThe netstat
command displays network connections, routing tables, and more.
Basic usage:
netstat
Common options:
netstat -a
: Show all socketsnetstat -r
: Show routing tablenetstat -s
: Show statistics by protocolpasswd
changes user passwords.
Basic usage:
passwd
Common options:
passwd username
: Change another user's password (as root)passwd -l username
: Lock user accountpasswd -u username
: Unlock user accountThe chmod
command changes file permissions.
Basic usage:
chmod permissions file
Examples:
chmod 755 file
: rwx for owner, rx for group and otherschmod +x file
: Add execute permissionchmod -R 750 directory
: Recursively change permissionschown
changes file owner and group.
Basic usage:
chown owner:group file
Common options:
chown -R user:group directory
: Recursively change ownershipThe ssh-keygen
command generates, manages, and converts authentication keys.
Basic usage:
ssh-keygen
Common options:
ssh-keygen -t rsa
: Generate RSA key pairssh-keygen -t ed25519
: Generate Ed25519 key (more secure)ssh-keygen -p
: Change passphrasesudo
executes a command as another user, typically as root.
Basic usage:
sudo command
Common options:
sudo -l
: List allowed commandssudo -i
: Start a login shell as the target usersudo -u username command
: Run as specified usersudo lets you execute a single command with root privileges, while su switches your entire user session to another user (typically root). sudo is generally preferred as it:
You can use the following command:
sudo lsof -i :port_number
Alternatively:
sudo netstat -tuln | grep port_number
Use the cron system:
crontab -e
minute hour day month weekday command
Example to run a script every day at 3 AM:
0 3 * * * /path/to/script.sh
On Debian/Ubuntu:
dpkg -S command_name
On Red Hat/CentOS:
yum provides */command_name
Use the df
command to check disk space:
df -h
To find the largest directories in the current location:
du -h --max-depth=1 | sort -hr
Mastering these 100 essential Linux commands will significantly enhance your productivity and control over Linux systems. Whether you're managing servers, developing applications, or simply exploring Linux as a user, these commands provide the foundation for efficient system administration and usage.
Remember that Linux commands often have many more options than we've covered here. The man pages (man command_name
) are your best friend for discovering all available options. Practice these commands regularly in a safe environment, and you'll quickly become proficient in Linux command-line operations.
For more in-depth information on Linux commands and system administration, consider exploring official Linux documentation, distribution-specific resources, and community forums where you can learn from experienced Linux users and administrators.
Are you ready to take your Linux skills to the next level? Start by practicing these commands in your own Linux environment today!
DevOps Engg
A metallurgist by education, tech enthusiast by passion. I've transformed my curiosity into expertise in web hosting, DevOps, and web development. With hands-on experience in Linux administration, cPanel, WordPress, and Node.js.
View more posts by Shaik VahidDiscover everything about web hosting in 2025. Learn about hosting types, costs, and features in this comprehensive guide that breaks down web hosting into simple terms for both beginners and experts.