Operations 48 min read

600 Essential Linux Commands You Must Know

This article provides a comprehensive, categorized reference of over 600 Linux commands covering basic system information, shutdown, file and directory management, searching, mounting, disk usage, user and group handling, permissions, special attributes, compression, package management, networking, system monitoring, VIM editing, and many other essential operations for everyday Linux use.

Linux Tech Enthusiast
Linux Tech Enthusiast
Linux Tech Enthusiast
600 Essential Linux Commands You Must Know

1. Basic Commands

uname -m               # display processor architecture
uname -r               # display kernel version
dmidecode -q           # display hardware components
hdparm -i /dev/hda     # list disk architecture features
hdparm -tT /dev/sda    # perform a test read on the disk
arch                   # display processor architecture
cat /proc/cpuinfo       # show CPU information
cat /proc/interrupts   # show interrupts
cat /proc/meminfo       # check memory usage
cat /proc/swaps         # show active swap devices
cat /proc/version       # display kernel version
cat /proc/net/dev       # show network adapters and statistics
cat /proc/mounts        # list mounted filesystems
lspci -tv              # list PCI devices
lsusb -tv              # list USB devices
date                    # show system date
cal 2007               # display calendar for 2007
date 041217002007.00   # set date and time (MMDDhhmmYYYY.ss)
clock -w               # write system time to BIOS

2. Shutdown and Reboot

shutdown -h now        # power off immediately (method 1)
init 0                # power off (method 2)
telinit 0             # power off (method 3)
shutdown -h HH:MM     # schedule shutdown at a specific time
shutdown -c           # cancel a scheduled shutdown
shutdown -r now      # reboot immediately (method 1)
reboot                # reboot (method 2)
logout                # log out of the session

3. Files and Directories

cd /home               # change to /home directory
cd ..                  # go up one level
cd ../..               # go up two levels
cd                     # go to the home directory
cd ~user1              # go to user1's home directory
cd -                   # return to the previous directory
pwd                    # print working directory
ls                     # list files in the current directory
ls -F                  # list files with type indicators
ls -l                  # detailed list of files and directories
ls -a                  # show hidden files
ls *[0-9]*             # show files/directories containing numbers
tree                   # display directory tree from root (method 1)
lstree                 # display directory tree from root (method 2)
mkdir dir1             # create a directory named dir1
mkdir dir1 dir2        # create two directories at once
mkdir -p /tmp/dir1/dir2 # create a directory tree
rm -f file1            # force delete file1
rmdir dir1             # remove empty directory dir1
rm -rf dir1            # recursively delete dir1 and its contents
rm -rf dir1 dir2       # delete two directories and their contents
mv dir1 new_dir        # rename or move a directory
cp file1 file2         # copy a file
cp dir/* .             # copy all files from a directory to the current directory
cp -a /tmp/dir1 .      # copy a directory preserving attributes
cp -a dir1 dir2        # copy a directory
ln -s file1 lnk1       # create a symbolic link
ln file1 lnk1          # create a hard link
touch -t 0712250000 file1 # modify timestamp (YYMMDDhhmm)
file file1             # output the MIME type of file1
iconv -l               # list known encodings
iconv -f fromEncoding -t toEncoding inputFile > outputFile # convert file encoding
find . -maxdepth 1 -name *.jpg -print -exec convert "{}" -resize 80x60 "thumbs/{}" \; # batch resize images

4. File Search

find / -name file1                     # search from root for file1
find / -user user1                    # search files owned by user1
find /home/user1 -name *.bin          # search for .bin files in /home/user1
find /usr/bin -type f -atime +100    # find executable files not accessed in the last 100 days
find /usr/bin -type f -mtime -10      # find files created/modified in the last 10 days
find / -name *.rpm -exec chmod 755 '{}' \; # find .rpm files and set permissions
find / -xdev -name *.rpm              # find .rpm files ignoring removable devices
locate *.ps                           # locate .ps files (run updatedb first)
whereis halt                          # show binary, source, and man page locations for halt
which halt                             # show full path of the executable

5. Mounting a Filesystem

mount /dev/hda2 /mnt/hda2               # mount partition hda2 (ensure /mnt/hda2 exists)
umount /dev/fd0 /mnt/floppy            # mount a floppy disk
mount /dev/cdrom /mnt/cdrom            # mount a CD-ROM or DVD-ROM
mount /dev/hdc /mnt/cdrecorder        # mount a CD-RW or DVD-RW
mount -o loop file.iso /mnt/cdrom       # mount an ISO image file
mount -t vfat /dev/hda5 /mnt/hda5       # mount a Windows FAT32 filesystem
mount /dev/sda1 /mnt/usbdisk            # mount a USB flash drive
mount -t smbfs -o username=user,password=pass //WinClient/share /mnt/share # mount a Windows network share

6. Disk Space

df -h                                 # display mounted partitions with human‑readable sizes
ls -lSr | more                        # list files sorted by size
du -sh dir1                           # estimate disk usage of dir1
du -sk * | sort -rn                  # list files/directories sorted by size
rpm -q -a --qf '%10{SIZE}t%{NAME}n' | sort -k1,1n # list installed RPM packages by size (Fedora/RedHat)
dpkg-query -W -f='${Installed-Size;10}t${Package}n' | sort -k1,1n # list installed DEB packages by size (Ubuntu/Debian)

7. Users and Groups

groupadd group_name                 # create a new group
groupdel group_name                 # delete a group
groupmod -n new_group_name old_group_name # rename a group
useradd -c "Name Surname" -g admin -d /home/user1 -s /bin/bash user1 # create user1 in group admin
useradd user1                       # create a new user
userdel -r user1                    # delete a user and its home directory
usermod -c "User FTP" -g system -d /ftp/user1 -s /nologin user1 # modify user attributes
passwd user1                        # change password for user1 (root only)
chage -E 2005-12-31 user1           # set password expiration date
pwck                                 # verify /etc/passwd syntax
grpck                                # verify /etc/group syntax
newgrp group_name                    # switch to a new group for file creation

8. File Permissions (use "+" to add, "-" to remove)

ls -lh                               # show permissions in long format with human‑readable sizes
chmod ugo+rwx directory1             # give read, write, execute to user, group, others
chmod go-rwx directory1              # remove read, write, execute from group and others
chown user1 file1                     # change file owner
chown -R user1 directory1            # recursively change owner of a directory tree
chgrp group1 file1                    # change group ownership
chown user1:group1 file1              # change both owner and group
chmod u+s /bin/file1                  # set SUID bit on a binary
chmod u-s /bin/file1                  # remove SUID bit
chmod g+s /home/public                # set SGID bit on a directory
chmod g-s /home/public                # remove SGID bit
chmod o+t /home/public                # set sticky bit on a directory
chmod o-t /home/public                # remove sticky bit
chmod +x file                         # add execute permission for all
chmod -x file                         # remove execute permission for all
chmod u+x file                        # add execute permission for owner
chmod g+x file                        # add execute permission for group
chmod o+x file                        # add execute permission for others
chmod ug+x file                       # add execute permission for owner and group
chmod =wx file                        # set write and execute for all, remove read
chmod ug=wx file                       # set write and execute for owner and group, remove read

9. Special File Attributes (use "+" to set, "-" to clear)

chattr +a file1   # allow only append writes
chattr +c file1   # enable automatic compression
chattr +d file1   # exclude from dump backups
chattr +i file1   # make immutable (cannot delete, modify, rename, or link)
chattr +s file1   # secure deletion
chattr +S file1   # sync changes to disk immediately after write
chattr +u file1   # allow undeletion of a deleted file
lsattr            # list special attributes

10. Archiving and Compression

bunzip2 file1.bz2                     # decompress a .bz2 file
bzip2 file1                           # compress a file with bzip2
gunzip file1.gz                       # decompress a .gz file
gzip file1                             # compress a file with gzip
gzip -9 file1                          # maximum compression
rar a file1.rar test_file              # create a .rar archive
rar a file1.rar file1 file2 dir1       # add multiple files/directories to a .rar archive
rar x file1.rar                       # extract a .rar archive
unrar x file1.rar                     # extract a .rar archive
tar -cvf archive.tar file1             # create an uncompressed tarball
tar -cvf archive.tar file1 file2 dir1 # create a tarball with multiple items
tar -tf archive.tar                    # list contents of a tarball
tar -xvf archive.tar                   # extract a tarball
tar -xvf archive.tar -C /tmp            # extract to /tmp
tar -cvfj archive.tar.bz2 dir1        # create a bzip2‑compressed tarball
tar -xvfj archive.tar.bz2              # extract a bzip2‑compressed tarball
tar -cvfz archive.tar.gz dir1          # create a gzip‑compressed tarball
tar -xvfz archive.tar.gz               # extract a gzip‑compressed tarball
zip file1.zip file1                    # create a zip archive
zip -r file1.zip file1 file2 dir1       # recursively zip multiple items
unzip file1.zip                         # extract a zip archive

11. RPM Packages

rpm -ivh package.rpm                     # install an RPM package
rpm -ivh --nodeps package.rpm            # install ignoring dependency warnings
rpm -U package.rpm                        # upgrade without changing config files
rpm -F package.rpm                        # upgrade an already‑installed package
rpm -e package_name.rpm                  # erase a package
rpm -qa                                 # list all installed RPMs
rpm -qa | grep httpd                    # filter installed RPMs containing "httpd"
rpm -qi package_name                    # query detailed info about a package
rpm -qg "System Environment/Daemons"    # list RPMs belonging to a group
rpm -ql package_name                    # list files provided by an installed package
rpm -qc package_name                    # list configuration files of a package
rpm -q package_name --whatrequires      # show packages that depend on this one
rpm -q package_name --whatprovides      # show what provides this package
rpm -q package_name --scripts           # show install/remove scripts
rpm -q package_name --changelog         # show changelog
rpm -qf /etc/httpd/conf/httpd.conf      # find which RPM provides a file
rpm -qp package.rpm -l                   # list files in an uninstalled RPM
rpm --import /media/cdrom/RPM-GPG-KEY  # import a GPG key
rpm --checksig package.rpm               # verify package signature
rpm -V package_name                      # verify file size, permissions, MD5, etc.
rpm -Va                                 # verify all installed RPMs (use with care)
rpm -Vp package.rpm                     # verify an uninstalled RPM
rpm2cpio package.rpm | cpio --extract --make-directories *bin* # extract executable from RPM
rpm -ivh /usr/src/redhat/RPMS/`arch`/package.rpm # install a built RPM from source
rpmbuild --rebuild package_name.src.rpm  # rebuild an RPM from source

12. YUM Package Manager

yum install package_name                 # download and install an RPM package
yum localinstall package_name.rpm       # install an RPM using local repository for dependencies
yum update package_name.rpm              # update all installed RPMs
yum update package_name                  # update a specific package
yum remove package_name                 # erase a package
yum list                                 # list all installed packages
yum search package_name                  # search for a package in repositories
yum clean packages                       # clean downloaded package files
yum clean headers                        # clean header files
yum clean all                            # clean all caches

13. DEB Packages

dpkg -i package.deb                     # install or upgrade a DEB package
dpkg -r package_name                    # remove a DEB package
dpkg -l                                 # list all installed DEB packages
dpkg -l | grep httpd                    # filter installed DEBs containing "httpd"
dpkg -s package_name                    # show status information for a package
dpkg -L package_name                    # list files provided by an installed DEB
dpkg --contents package.deb              # list files in an uninstalled DEB
dpkg -S /bin/ping                       # find which DEB provides a file
apt-get install package_name             # install or upgrade a DEB package
apt-cdrom install package_name          # install from a CD-ROM
apt-get update                          # refresh package lists
apt-get upgrade                         # upgrade all installed packages
apt-get remove package_name             # remove a DEB package
apt-get check                           # verify package dependencies
apt-get clean                           # clean downloaded package cache
apt-cache search searched-package       # search package names containing a string

14. Viewing File Contents

cat file1                               # display file from beginning
tac file1                               # display file in reverse order
more file1                              # paginate long file output
less file1                              # paginate with forward and backward navigation
head -2 file1                           # show first two lines
tail -2 file1                           # show last two lines
tail -f /var/log/messages               # follow a file as it grows (real‑time log view)

15. Text Processing

cat file1 file2 ... | command > file1_in.txt_or_file1_out.txt   # pipe data through commands
cat file1 | sed 's/string1/string2/g' > result.txt          # replace text using sed
cat file1 | grep pattern > result.txt                     # filter lines containing pattern
grep Aug /var/log/messages                                 # find lines containing "Aug"
grep ^Aug /var/log/messages                               # lines starting with "Aug"
grep [0-9] /var/log/messages                             # lines containing digits
grep Aug -R /var/log/*                                    # recursive search for "Aug"
sed 's/string1/string2/g' example.txt                     # replace all occurrences
sed '/^$/d' example.txt                                    # delete empty lines
sed '/ *#/d; /^$/d' example.txt                            # delete comments and empty lines
echo 'example' | tr '[:lower:]' '[:upper:]'                # convert to uppercase
sed -e '1d' result.txt                                     # delete first line
sed -n '/string1/p' result.txt                            # print lines containing "string1"
sed -e 's/ *$//' example.txt                              # trim trailing spaces
sed -e 's/string1//g' example.txt                           # delete all occurrences of "string1"
sed -n '1,5p;5q' example.txt                              # print lines 1‑5 then quit
sed -n '5p;5q' example.txt                                 # print line 5 then quit
sed -e 's/00*/0/g' example.txt                            # replace multiple zeros with a single zero
cat -n file1                                               # number lines
cat example.txt | awk 'NR%2==1'                            # keep odd‑numbered lines
echo a b c | awk '{print $1}'                             # print first column
echo a b c | awk '{print $1,$3}'                          # print first and third columns
paste file1 file2                                          # merge files column‑wise
paste -d '+' file1 file2                                  # merge with '+' as delimiter
sort file1 file2                                           # sort combined files
sort file1 file2 | uniq                                    # unique lines (remove duplicates)
sort file1 file2 | uniq -u                               # show lines that appear only once
sort file1 file2 | uniq -d                               # show duplicate lines
comm -1 file1 file2                                       # show lines only in file2
comm -2 file1 file2                                       # show lines only in file1
comm -3 file1 file2                                       # show common lines

16. Character Set Conversion and File Format

dos2unix filedos.txt fileunix.txt   # convert DOS line endings to UNIX
unix2dos fileunix.txt filedos.txt   # convert UNIX line endings to DOS
recode ..HTML < page.txt > page.html # convert text file to HTML
recode -l | more                    # list all supported conversion formats

17. Filesystem Analysis

badblocks -v /dev/hda1               # check for bad blocks on a disk
fsck /dev/hda1                        # check/repair filesystem integrity
fsck.ext2 /dev/hda1                   # check/repair ext2 filesystem
e2fsck /dev/hda1                     # check/repair ext2 filesystem
e2fsck -j /dev/hda1                  # check/repair ext3 filesystem (with journal)
fsck.ext3 /dev/hda1                  # check/repair ext3 filesystem
fsck.vfat /dev/hda1                  # check/repair FAT filesystem
fsck.msdos /dev/hda1                 # check/repair DOS filesystem
dosfsck /dev/hda1                    # check/repair DOS filesystem

18. Initialise a Filesystem

mkfs /dev/hda1                       # create a generic filesystem
mke2fs /dev/hda1                     # create an ext2 filesystem
mke2fs -j /dev/hda1                  # create an ext3 (journaled) filesystem
mkfs -t vfat -F 32 /dev/hda1         # create a FAT32 filesystem
fdformat -n /dev/fd0                 # format a floppy disk
mkswap /dev/hda3                     # create a swap partition

19. SWAP Filesystem

mkswap /dev/hda3                     # create a swap area
swapon /dev/hda3                     # enable the swap area
swapon /dev/hda2 /dev/hdb3           # enable two swap partitions

20. Backup

dump -0aj -f /tmp/home0.bak /home                # full backup of /home
dump -1aj -f /tmp/home0.bak /home                # interactive backup of /home
restore -if /tmp/home0.bak                       # restore an interactive backup
rsync -rogpav --delete /home /tmp                # sync two directories
rsync -rogpav -e ssh --delete /home ip_address:/tmp # sync over SSH
rsync -az -e ssh --delete ip_addr:/home/public /home/local # remote to local sync with compression
rsync -az -e ssh --delete /home/local ip_addr:/home/public # local to remote sync with compression
dd bs=1M if=/dev/hda | gzip | ssh user@ip_addr 'dd of=hda.gz' # backup a disk over SSH
dd if=/dev/sda of=/tmp/file1                     # copy raw disk to a file
tar -Puf backup.tar /home/user                  # incremental backup of a directory
( cd /tmp/local/ && tar c . ) | ssh -C user@ip_addr 'cd /home/share/ && tar x -p' # copy a directory over SSH
( tar c /home ) | ssh -C user@ip_addr 'cd /home/backup-home && tar x -p' # copy a local directory over SSH
tar cf - . | (cd /tmp/backup ; tar xf - )        # local copy preserving permissions and links
find /home/user1 -name '*.txt' | xargs cp -av --target-directory=/home/backup/ --parents # copy all .txt files preserving directory structure
find /var/log -name '*.log' | tar cv --files-from=- | bzip2 > log.tar.bz2 # archive log files and compress
dd if=/dev/hda of=/dev/fd0 bs=512 count=1      # copy MBR to a floppy
dd if=/dev/fd0 of=/dev/hda bs=512 count=1      # restore MBR from a floppy

21. Optical Discs

cdrecord -v gracetime=2 dev=/dev/cdrom -eject blank=fast -force # erase a rewritable CD
mkisofs /dev/cdrom > cd.iso                     # create an ISO image from a disc
mkisofs /dev/cdrom | gzip > cd_iso.gz          # create a compressed ISO image
mkisofs -J -allow-leading-dots -R -V "Label CD" -iso-level 4 -o ./cd.iso data_cd # create ISO from a directory
cdrecord -v dev=/dev/cdrom cd.iso               # burn an ISO image to CD
gzip -dc cd_iso.gz | cdrecord dev=/dev/cdrom - # burn a compressed ISO image
mount -o loop cd.iso /mnt/iso                    # mount an ISO image
cd-paranoia -B                                   # extract audio tracks from a CD to WAV files
cd-paranoia -- "-3"                             # extract with parameter -3
cdrecord --scanbus                               # scan SCSI bus for devices
dd if=/dev/hdc | md5sum                         # compute MD5 checksum of a CD

22. Network (Ethernet and Wi‑Fi)

ifconfig eth0                                 # show Ethernet configuration
ifup eth0                                     # bring up eth0
ifdown eth0                                   # bring down eth0
ifconfig eth0 192.168.1.1 netmask 255.255.255.0 # set static IP address
ifconfig eth0 promisc                         # enable promiscuous mode for sniffing
dhclient eth0                                 # obtain IP via DHCP
route -n                                      # display routing table
route add -net 0/0 gw IP_Gateway             # set default gateway
route add -net 192.168.0.0 netmask 255.255.0.0 gw 192.168.1.1 # add static route
route del 0/0 gw IP_gateway                  # delete default route
echo "1" > /proc/sys/net/ipv4/ip_forward    # enable IP forwarding
hostname                                      # show system hostname
host www.example.com                         # resolve hostname to IP
nslookup www.example.com                     # DNS lookup
ip link show                                 # list all network interfaces
mii-tool eth0                                 # show link status of eth0
ethtool eth0                                 # show detailed statistics of eth0
netstat -tup                                 # list active connections with PID
netstat -tupl                                # list listening services with PID
tcpdump tcp port 80                          # capture HTTP traffic
iwlist scan                                   # scan for wireless networks
iwconfig eth1                                 # show wireless interface configuration
whois www.example.com                       # query WHOIS database

23. List Directory Contents

ls -a                                         # show all files, including hidden
ls -l                                         # long format with details
ls -R                                         # recursive listing
ls -ld                                        # show directory and link info
pwd                                           # print working directory

24. Determine File Type

file file1                                   # display file type

25. Copy Files and Directories

cp file1 file2                               # copy a file
cp -r source_dir target_dir                 # recursively copy a directory tree
cp -a /tmp/dir1 .                           # copy preserving attributes
cp -a dir1 dir2                             # copy a directory
cp -r source_folder target_folder            # copy folder recursively

26. Common System Commands

26.1 Display Commands

date                                         # show current date and time
date -s "YYYY-MM-DD HH:MM:SS"               # set system date and time
hwclock                                      # show hardware clock (requires root)
cal                                          # display calendar
cal 2004                                      # show calendar for 2004
cal -y 2003                                  # show calendar for 2003
uptime                                       # show system uptime

26.2 Output and Viewing Commands

echo "text"                                 # display text or append to a file
cat file1                                    # display file contents
cat file1 file2 > combined.txt                # concatenate files
cat file1 | more                             # paginate output
cat file1 | less                             # paginate with backward navigation
head -n 2 file1                              # first two lines
tail -n 2 file1                              # last two lines
tail -f /var/log/messages                    # follow file growth

26.3 Hardware Information

lspci -v                                    # list PCI devices with details
lsusb -v                                    # list USB devices with details
lsmod                                        # list loaded kernel modules

26.4 Shutdown and Reboot

shutdown -h now                             # immediate shutdown
shutdown -h +10                             # shutdown after 10 minutes
shutdown -h 23:30                           # shutdown at 23:30
shutdown -r now                             # immediate reboot
poweroff                                     # power off immediately
reboot                                       # reboot immediately

26.5 Archiving and Compression

zip file.zip file1                           # create zip archive
unzip file.zip                               # extract zip archive
gzip file1                                   # compress with gzip
gunzip file1.gz                              # decompress gzip file
tar -cvf archive.tar file1                   # create tar archive
tar -xvf archive.tar                         # extract tar archive
tar -cvzf archive.tar.gz dir1                # create gzip‑compressed tarball
tar -xvzf archive.tar.gz                     # extract gzip‑compressed tarball

26.6 Search

locate pattern                               # fast file name search (requires updatedb)
find . -name "*.txt"                       # find files by name
find / -perm 777                            # find files with permission 777
find / -type d                              # list all directories
find . -name "a*" -exec ls -l {} \;        # find and list matching files

26.7 Ctrl+C

Ctrl+C                                      # terminate the current command

26.8 Who / w

who                                          # list logged‑in users
w                                            # detailed list of logged‑in users

26.9 dmesg

dmesg                                        # display kernel ring buffer (diagnostic info)

26.10 df

df -h                                        # show filesystem usage

26.11 du

du -sh dir                                   # summarize disk usage of a directory

26.12 free

free -h                                      # display memory and swap usage

27. VIM Editor

vim file               # open file in VIM (creates if not existent)
:q                     # quit VIM
:q!                    # force quit without saving
:w                     # write (save) changes
:wq or :x              # write and quit
:set number            # show line numbers

VIM has three modes: command mode (default), insert mode (press i to enter), and ex mode (press : to enter). Common commands include dd (delete line), yy (yank line), p (paste), u (undo), /pattern (search), and many others for navigation and editing.

28. RPM Package Management Commands

28.1 Install Packages

rpm -ivh package.rpm                         # install package with progress bar

28.2 Remove Packages

rpm -e package_name                         # erase package (configuration files may remain)

28.3 Upgrade Packages

rpm -Uvh package.rpm                         # upgrade to newer version

28.4 Update Packages

rpm -Fvh package.rpm                         # update if newer, otherwise do nothing

28.5 Query Packages

rpm -q package_name                         # query installed package
rpm -ql package_name                        # list files provided by package
rpm -qi package_name                        # detailed info about package

End of the comprehensive Linux command reference.

LinuxshellCommand LineNetworkingUnixSystem AdministrationPackage ManagementFile Management
Linux Tech Enthusiast
Written by

Linux Tech Enthusiast

Focused on sharing practical Linux technology content, covering Linux fundamentals, applications, tools, as well as databases, operating systems, network security, and other technical knowledge.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.