Operations 34 min read

Master Linux System Commands: Essential Tools for Sysadmins

This comprehensive guide presents essential Linux system commands covering hardware inspection, date handling, shutdown/reboot, file and directory management, searching, mounting, disk usage, user/group administration, permissions, packaging, backup, and network utilities, providing a practical reference for system administrators.

Open Source Linux
Open Source Linux
Open Source Linux
Master Linux System Commands: Essential Tools for Sysadmins

System Information

arch                # Show machine architecture (1)
uname -m            # Show machine architecture (2)
uname -r            # Show running kernel version
 dmidecode -q       # Display hardware components (SMBIOS/DMI)
 hdparm -i /dev/hda # List disk architecture features
 hdparm -tT /dev/sda# Perform test read on disk
 cat /proc/cpuinfo  # Show CPU info
 cat /proc/interrupts# Show interrupts
 cat /proc/meminfo  # Verify memory usage
 cat /proc/swaps    # Show used swap
 cat /proc/version  # Show kernel version
 cat /proc/net/dev # Show network adapters and stats
 cat /proc/mounts   # Show mounted filesystems
 lspci -tv          # List PCI devices
 lsusb -tv          # Show USB devices

date – Display System Date

cal 2007                # Show calendar for 2007
 date 041217002007.00   # Set date/time: MMDDhhmmYY.ss
 clock -w                # Save time to BIOS

Shutdown, Reboot, Logout

shutdown -h now   # Power off (1)
 init 0           # Power off (2)
 telinit 0        # Power off (3)
 shutdown -h 02:00& # Schedule shutdown
 shutdown -c      # Cancel scheduled shutdown
 shutdown -r now  # Reboot (1)
 reboot           # Reboot (2)
 logout           # Logout

Files and Directories

cd /home          # Enter /home directory
 cd ..            # Go up one level
 cd ../..         # Go up two levels
 cd               # Go to home directory
 cd ~user1         # Go to user1's home
 cd -              # Return to previous directory
 pwd               # Show current path

 ls                # List files
 ls -F             # List files with type indicators
 ls -l             # Detailed list
 ls -a             # Show hidden files
 ls *[0-9]*        # Show files containing numbers
 tree              # Tree view of files (1)
 lstree            # Tree view of files (2)

 mkdir dir1        # Create directory dir1
 mkdir dir1 dir2   # Create two directories
 mkdir -p /tmp/dir1/dir2 # Create directory tree
 rm -f file1       # Delete file1
 rmdir dir1        # Remove empty directory
 rm -rf dir1       # Delete directory and its contents
 rm -rf dir1 dir2  # Delete two directories
 mv dir1 new_dir   # Rename/move directory

 cp file1 file2    # Copy file
 cp dir/* .        # Copy all files from dir to current directory
 cp -a /tmp/dir1 . # Copy directory preserving attributes
 cp -a dir1 dir2   # Copy directory

 ln -s file1 lnk1  # Create symbolic link
 ln file1 lnk1      # Create hard link

 touch -t 0712250000 file1 # Change timestamp (YYMMDDhhmm)
 file file1 outputs the mime type of the file as text
 iconv -l           # List known encodings
 iconv -f fromEncoding -t toEncoding inputFile > outputFile

File Search

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

Mount a Filesystem

mount /dev/hda2 /mnt/hda2          # Mount partition hda2 (ensure mount point exists)
 umount /dev/hda2                  # Unmount partition hda2
 fuser -km /mnt/hda2               # Force unmount if busy
 umount -n /mnt/hda2               # Unmount without writing /etc/mtab
 mount /dev/fd0 /mnt/floppy        # Mount floppy
 mount /dev/cdrom /mnt/cdrom       # Mount CD/DVD
 mount /dev/hdc /mnt/cdrecorder    # Mount CDRW/DVD
 mount /dev/hdb /mnt/cdrecorder    # Mount another CDRW/DVD
 mount -o loop file.iso /mnt/cdrom # Mount ISO image
 mount -t vfat /dev/hda5 /mnt/hda5 # Mount Windows FAT32 filesystem
 mount /dev/sda1 /mnt/usbdisk      # Mount USB flash drive
 mount -t smbfs -o username=user,password=pass //WinClient/share /mnt/share # Mount Windows network share

Disk Space

df -h               # Show mounted partitions
 ls -lSr | more      # List files/directories sorted by size
 du -sh dir1          # Estimate disk usage of dir1
 du -sk * | sort -rn # List files/directories by size descending
 rpm -qa --qf '%10{SIZE}t%{NAME}n' | sort -k1,1n # Show RPM package sizes (Fedora/RedHat)
 dpkg-query -W -f '${Installed-Size;10}t${Package}n' | sort -k1,1n # Show DEB package sizes (Ubuntu/Debian)

Users and Groups

groupadd group_name   # Create new group
 groupdel group_name   # Delete group
 groupmod -n new_group_name old_group_name # Rename group
 useradd -c "Name Surname" -g admin -d /home/user1 -s /bin/bash user1 # Create user in admin group
 useradd user1        # Create new user
 userdel -r user1     # Delete user and home directory
 usermod -c "User FTP" -g system -d /ftp/user1 -s /bin/nologin user1 # Modify user attributes

 passwd               # Change password
 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 new group for file creation defaults

File Permissions

ls -lh                # Show permissions in human readable form
 chmod ugo+rwx directory1   # Grant read/write/execute to user, group, others
 chmod go-rwx directory1   # Remove rwx from group and others
 chown user1 file1          # Change file owner
 chown -R user1 directory1 # Recursively change owner
 chgrp group1 file1         # Change group ownership
 chown user1:group1 file1   # Change owner and group
 find / -perm -u+s         # List files with SUID bit set
 chmod u+s /bin/file1      # Set SUID on binary
 chmod u-s /bin/file1      # Remove SUID
 chmod g+s /home/public    # Set SGID on directory
 chmod g-s /home/public    # Remove SGID
 chmod o+t /home/public    # Set sticky bit on directory
 chmod o-t /home/public    # Remove sticky bit

Special File Attributes

chattr +a file1   # Append-only attribute
 chattr +c file1   # Enable automatic compression
 chattr +d file1   # Exclude from backup dumps
 chattr +i file1   # Immutable; cannot delete/modify/rename/link
 chattr +s file1   # Secure deletion
 chattr +S file1   # Write changes immediately to disk
 chattr +u file1   # Undelete capability
 lsattr             # List special attributes

Packaging and Compression

bunzip2 file1.bz2   # Decompress .bz2 file
 bzip2 file1        # Compress file with bzip2
 gunzip file1.gz    # Decompress .gz file
 gzip file1         # Compress file with gzip
 gzip -9 file1      # Maximum compression

 rar a file1.rar test_file   # Create RAR archive
 rar a file1.rar file1 file2 dir1 # Add multiple items to RAR
 rar x file1.rar            # Extract RAR archive
 unrar x file1.rar          # Extract RAR archive

 tar -cvf archive.tar file1            # Create uncompressed tarball
 tar -cvf archive.tar file1 file2 dir1 # Create tarball with multiple items
 tar -tf archive.tar                  # List contents of tarball
 tar -xvf archive.tar                  # Extract tarball
 tar -xvf archive.tar -C /tmp          # Extract to /tmp
 tar -cvfj archive.tar.bz2 dir1       # Create bzip2-compressed tarball
 tar -jxvf archive.tar.bz2            # Extract bzip2-compressed tarball
 tar -cvfz archive.tar.gz dir1        # Create gzip-compressed tarball
 tar -zxvf archive.tar.gz             # Extract gzip-compressed tarball

 zip file1.zip file1          # Create zip archive
 zip -r file1.zip file1 file2 dir1 # Recursively add items to zip
 unzip file1.zip              # Extract zip archive

RPM Packages (Fedora/RedHat)

rpm -ivh package.rpm               # Install RPM package
 rpm -ivh --nodeps package.rpm     # Install ignoring dependencies
 rpm -U package.rpm                 # Upgrade without changing config files
 rpm -F package.rpm                 # Refresh already installed package
 rpm -e package_name.rpm           # Remove RPM package
 rpm -qa                           # List all installed RPMs
 rpm -qa | grep httpd              # Find RPMs containing "httpd"
 rpm -qi package_name              # Query detailed info of installed package
 rpm -qg "System Environment/Daemons" # List RPMs in a group
 rpm -ql package_name              # List files provided by installed RPM
 rpm -qc package_name              # List config files of installed RPM
 rpm -q --whatrequires package_name # Show packages that require this RPM
 rpm -q --whatprovides package_name # Show what this RPM provides
 rpm -q --scripts package_name     # Show install/remove scripts
 rpm -q --changelog package_name   # 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 GPG key
 rpm --checksig package.rpm        # Verify RPM integrity
 rpm -qa gpg-pubkey               # List installed GPG keys
 rpm -V package_name               # Verify package files
 rpm -Va                           # Verify all installed packages (use with care)
 rpm -Vp package.rpm               # Verify an uninstalled package
 rpm2cpio package.rpm | cpio --extract --make-directories *bin* # Run executable from RPM
 rpm -ivh /usr/src/redhat/RPMS/`arch`/package.rpm # Install built RPM from source
 rpmbuild --rebuild package_name.src.rpm # Rebuild RPM from source

YUM Package Manager (Fedora/RedHat)

yum install package_name          # Download and install RPM
 yum localinstall package_name.rpm # Install RPM using local repository for dependencies
 yum update package_name.rpm      # Update all installed RPMs
 yum update package_name          # Update a specific RPM
 yum remove package_name          # Remove RPM package
 yum list                         # List all installed packages
 yum search package_name          # Search for packages in repositories
 yum clean packages               # Clean package cache
 yum clean headers                # Remove header files
 yum clean all                    # Remove all cached data

DEB Packages (Debian/Ubuntu)

dpkg -i package.deb               # Install/upgrade DEB package
 dpkg -r package_name             # Remove DEB package
 dpkg -l                         # List installed DEB packages
 dpkg -l | grep httpd           # Find DEB packages containing "httpd"
 dpkg -s package_name            # Show detailed info of installed package
 dpkg -L package_name            # List files provided by installed DEB
 dpkg --contents package.deb      # List files in an uninstalled DEB
 dpkg -S /bin/ping               # Find which DEB provides a file

APT Tools (Debian/Ubuntu)

apt-get install package_name      # Install/upgrade DEB package
 apt-cdrom install package_name   # Install/upgrade from CD-ROM
 apt-get update                   # Update package list
 apt-get upgrade                  # Upgrade all installed packages
 apt-get remove package_name       # Remove DEB package
 apt-get check                    # Verify repository dependencies
 apt-get clean                    # Clean downloaded package cache
 apt-cache search searched-package # Search package names containing a string

Viewing File Contents

cat file1                # View file from start
 tac file1                # View file in reverse order
 more file1               # Paginated view of long file
 less file1               # Paginated view with backward navigation
 head -2 file1            # Show first two lines
 tail -2 file1            # Show last two lines
 tail -f /var/log/messages # Follow file updates in real time

Text Processing

cat file1 file2 ... | command > result.txt   # General PIPE syntax for text manipulation
 cat file1 | grep pattern > result.txt          # Filter and write to file
 cat file1 | grep pattern >> result.txt         # Append filtered output
 grep Aug /var/log/messages                     # Find lines containing "Aug"
 grep ^Aug /var/log/messages                    # Find lines starting with "Aug"
 grep [0-9] /var/log/messages                  # Find lines containing digits
 grep Aug -R /var/log/*                        # Recursive search for "Aug"

 sed 's/stringa1/stringa2/g' example.txt       # Replace stringa1 with stringa2
 sed '/^$/d' example.txt                        # Delete empty lines
 sed '/ *#/d; /^$/d' example.txt               # Delete comments and empty lines
 echo 'esempio' | tr '[:lower:]' '[:upper:]'    # Convert to uppercase
 sed -e '1d' result.txt                         # Delete first line
 sed -n '/stringa1/p' example.txt               # Print lines containing stringa1
 sed -e 's/ *$//' example.txt                    # Trim trailing spaces
 sed -e 's/stringa1//g' example.txt            # Remove stringa1
 sed -n '1,5p;5q' example.txt                  # Print lines 1-5
 sed -n '5p;5q' example.txt                    # Print line 5
 sed -e 's/00*/0/g' example.txt                 # Collapse multiple zeros to single zero

 cat -n file1               # Number lines
 cat example.txt | awk 'NR%2==1'   # Print odd-numbered lines
 echo a b c | awk '{print $1}'    # Print first field
 echo a b c | awk '{print $1,$3}' # Print first and third fields
 paste file1 file2                # Merge files column-wise
 paste -d '+' file1 file2         # Merge with '+' delimiter

 sort file1 file2                 # Sort combined files
 sort file1 file2 | uniq          # Unique lines (union)
 sort file1 file2 | uniq -u      # Lines only in one file (difference)
 sort file1 file2 | uniq -d      # Lines common to both files (intersection)

 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

Character Set Conversion and File Format

dos2unix filedos.txt fileunix.txt   # Convert DOS to UNIX format
 unix2dos fileunix.txt filedos.txt   # Convert UNIX to DOS format
 recode ..HTML < page.txt > page.html # Convert text to HTML
 recode -l | more                  # List supported conversions

Filesystem Analysis

badblocks -v /dev/hda1   # Check for bad blocks
 fsck /dev/hda1           # Check/repair filesystem
 fsck.ext2 /dev/hda1     # Check/repair ext2 filesystem
 e2fsck /dev/hda1        # Check/repair ext2 filesystem
 e2fsck -j /dev/hda1     # Check/repair ext3 filesystem
 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

Initialize a Filesystem

mkfs /dev/hda1                # Create filesystem on partition
 mke2fs /dev/hda1             # Create ext2 filesystem
 mke2fs -j /dev/hda1          # Create ext3 (journaled) filesystem
 mkfs -t vfat 32 -F /dev/hda1 # Create FAT32 filesystem
 fdformat -n /dev/fd0         # Format floppy disk
 mkswap /dev/hda3             # Create swap area

SWAP Filesystem

mkswap /dev/hda3            # Create swap area
 swapon /dev/hda3           # Enable swap
 swapon /dev/hda2 /dev/hdb3 # Enable multiple swap partitions

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 interactive backup

 rsync -rogpav --delete /home /tmp    # Synchronize directories
 rsync -rogpav -e ssh --delete /home user@host:/tmp   # Sync over SSH
 rsync -az -e ssh --delete user@host:/home/public /home/local   # Pull remote directory
 rsync -az -e ssh --delete /home/local host:/home/public   # Push local directory

 dd bs=1M if=/dev/hda | gzip | ssh user@host 'dd of=hda.gz'   # Remote backup via SSH
 dd if=/dev/sda of=/tmp/file1                               # Backup disk to file
 tar -Puf backup.tar /home/user                               # Incremental backup
 (cd /tmp/local && tar c .) | ssh -C user@host 'cd /home/share && tar x -p' # Remote copy via SSH
 (tar c /home) | ssh -C user@host 'cd /home/backup-home && tar x -p' # Remote copy of directory
 tar cf - . | (cd /tmp/backup && tar xf -)                     # Local copy preserving permissions

 find /home/user1 -name '*.txt' | xargs cp -av --target-directory=/home/backup/ --parents # Copy .txt files preserving hierarchy
 find /var/log -name '*.log' | tar cv --files-from=- | bzip2 > log.tar.bz2 # Archive logs

 dd if=/dev/hda of=/dev/fd0 bs=512 count=1   # Copy MBR to floppy
 dd if=/dev/fd0 of=/dev/hda bs=512 count=1   # Restore MBR from floppy

Optical Discs

cdrecord -v gracetime=2 dev=/dev/cdrom -eject -blank fast -force   # Erase rewritable CD
 mkisofs /dev/cdrom > cd.iso                                 # Create ISO image from CD
 mkisofs /dev/cdrom | gzip > cd_iso.gz                       # Create compressed ISO image
 mkisofs -J -allow-leading-dots -R -V "Label CD" -iso-level 4 -o ./cd.iso data_cd # Create ISO from directory
 cdrecord -v dev=/dev/cdrom cd.iso                           # Burn ISO to CD
 gzip -dc cd_iso.gz | cdrecord dev=/dev/cdrom -            # Burn compressed ISO
 mount -o loop cd.iso /mnt/iso                               # Mount ISO image

 cd-paranoia -B                                            # Extract audio tracks to WAV
 cd-paranoia -- "-3"                                      # Extract with parameter -3
 cdrecord --scanbus                                        # Scan SCSI bus
 dd if=/dev/hdc | md5sum                                   # Compute MD5 of CD device

Network – Ethernet and Wi‑Fi

ifconfig eth0               # Show Ethernet configuration
 ifup eth0                  # Enable eth0
 ifdown eth0                # Disable eth0
 ifconfig eth0 192.168.1.1 netmask 255.255.255.0 # Set IP address
 ifconfig eth0 promisc      # Enable promiscuous mode for sniffing
 dhclient eth0              # Obtain IP via DHCP

 route -n                  # Show 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 static route

 hostname                    # Show host name
 host www.example.com        # Resolve host name to IP
 nslookup www.example.com   # DNS query for troubleshooting
 ip link show                # Show network interfaces
 mii-tool                    # Show/manage media interface status
 ethtool                     # Query and set NIC parameters
 netstat -tupl               # Show TCP/UDP socket status
 tcpdump tcp port 80         # Capture HTTP traffic

JPS Tool

jps                         # List Java processes (PID and class name)
 jps -q                      # Show only PIDs
 jps -m                      # Show arguments passed to main method
 jps -l                      # Show full package name or JAR path
 jps -v                      # Show JVM arguments
 jps 192.168.0.77            # List Java processes on remote host via RMI (default port 1099)
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

linuxUnixSystem Administration
Open Source Linux
Written by

Open Source Linux

Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional 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.