Linux Commands Cheat Sheet: A Quick Reference Guide

ADVERTISEMENT

Mastering Linux starts with knowing the right commands. This Linux Commands Cheat Sheet is your go-to guide, offering quick access to essential commands that can simplify your tasks. From file management to system checks, this cheat sheet ensures you’re always equipped to get things done efficiently. Whether you’re just starting or looking to boost your command line skills, these key commands will streamline your workflow and save you time.

1. File and Directory Management

# File and Directory Management

ls [-a] [-l] [-h] [-t] [-r] [-R] [directory]  
# List directory contents  
# -a : show hidden files  
# -l : long listing format  
# -h : human-readable sizes  
# -t : sort by modification time  
# -r : reverse order  
# -R : list subdirectories recursively  
# Example:  
ls -lh /home/user  

cd [directory]  
# Change directory  
# Example:  
cd /var/www/html  

pwd  
# Print working directory  
# Example:  
pwd  

cp [-r] [-i] [-u] [-v] source destination  
# Copy files and directories  
# -r : copy directories recursively  
# -i : prompt before overwrite  
# -u : copy only when source is newer than destination  
# -v : verbose output  
# Example:  
cp -r /source/directory /destination/directory  

mv [-i] [-n] [-v] source destination  
# Move or rename files and directories  
# -i : prompt before overwrite  
# -n : do not overwrite an existing file  
# -v : verbose output  
# Example:  
mv -i oldfile.txt newfile.txt  

rm [-r] [-f] [-i] [-v] file  
# Remove files or directories  
# -r : remove directories and contents recursively  
# -f : force remove without confirmation  
# -i : prompt before every removal  
# -v : verbose output  
# Example:  
rm -rf /unwanted/directory  

mkdir [-p] [-v] directory  
# Make directories  
# -p : create parent directories if needed  
# -v : verbose output  
# Example:  
mkdir -p /new/parent/directory  

rmdir [-p] directory  
# Remove empty directories  
# -p : remove parent directories if empty  
# Example:  
rmdir -p /empty/parent/directory  

touch [-c] [-d time] [-t timestamp] filename  
# Change file timestamps or create empty files  
# -c : do not create file if it does not exist  
# -d time : set modification time  
# -t timestamp : use a specific timestamp  
# Example:  
touch -t 202401011230 file.txt  

find [directory] [-name "filename"] [-type f/d] [-size +100M] [-mtime -7] [-exec command {} \;]  
# Search for files in a directory hierarchy  
# -name "filename" : search by filename  
# -type f/d : search for files (f) or directories (d)  
# -size +100M : find files larger than 100MB  
# -mtime -7 : find files modified in the last 7 days  
# -exec command {} \; : execute a command on found files  
# Example:  
find /home -type f -name "*.log" -size +50M  

locate [-i] filename  
# Find files by name (uses a prebuilt database)  
# -i : case-insensitive search  
# Example:  
locate -i config.php  

tree [-L level] [-d] [-f] [directory]  
# Display directories in a tree-like format  
# -L : limit depth of directory tree  
# -d : show directories only  
# -f : show full file path  
# Example:  
tree -L 2 -d /var/www  

chmod [-R] mode file  
# Change file permissions  
# -R : apply changes recursively  
# Example:  
chmod -R 755 /var/www/html  

chown [-R] owner:group file  
# Change file owner and group  
# -R : apply changes recursively  
# Example:  
chown -R user:group /var/www/html  

chgrp [-R] group file  
# Change group ownership  
# -R : apply changes recursively  
# Example:  
chgrp -R developers /var/www/html  

stat [-c format] file  
# Display file or file system status  
# -c : specify custom output format  
# Example:  
stat -c "%U %G %s %y" file.txt  

2. File Viewing and Editing

# File Viewing and Editing

cat [options] filename  
# Concatenate and display file content  
# -n : number all output lines  
# -E : display `$` at the end of each line  
# Example:  
cat -n file.txt  

tac [options] filename  
# Concatenate and display file content in reverse  
# Example:  
tac file.txt  

more [options] filename  
# View file content interactively (page by page)  
# -num : specify number of lines per page  
# Example:  
more -20 file.txt  

less [options] filename  
# View file content interactively (scrollable)  
# -N : show line numbers  
# Example:  
less -N file.txt  

head [options] filename  
# Output the first part of a file  
# -n num : display the first ‘num’ lines  
# Example:  
head -n 10 file.txt  

tail [options] filename  
# Output the last part of a file  
# -n num : display the last ‘num’ lines  
# -f : continuously monitor a file for updates  
# Example:  
tail -f /var/log/syslog  

nano filename  
# Open nano text editor (terminal-based)  
# Example:  
nano file.txt  

vim filename  
# Open Vim text editor  
# Example:  
vim file.txt  

vi filename  
# Open Vi text editor  
# Example:  
vi file.txt  

emacs filename  
# Open Emacs text editor  
# Example:  
emacs file.txt  

grep [options] "pattern" filename  
# Search text using patterns  
# -i : case-insensitive search  
# -v : invert match (exclude lines matching pattern)  
# -r : search recursively in directories  
# Example:  
grep -i "error" /var/log/syslog  

sed [options] 'script' filename  
# Stream editor for filtering and transforming text  
# -i : edit files in place  
# -e : add a script to execute  
# Example:  
sed -i 's/oldword/newword/g' file.txt  

awk ['pattern {action}'] filename  
# Pattern scanning and processing language  
# Example:  
awk '{print $1, $3}' file.txt  

cut [options] filename  
# Remove sections from each line of files  
# -d : specify a delimiter  
# -f : specify field numbers  
# Example:  
cut -d':' -f1 /etc/passwd  

sort [options] filename  
# Sort lines of text files  
# -r : reverse the sorting order  
# -n : numeric sort  
# Example:  
sort -n file.txt  

uniq [options] filename  
# Report or omit repeated lines  
# -c : prefix lines with the number of occurrences  
# Example:  
uniq -c file.txt  

3. Process Management

# Process Management

ps [options]  
# Report a snapshot of current processes  
# -e : show all processes  
# -f : full-format listing  
# -u user : show processes for a specific user  
# Example:  
ps -ef  

top [options]  
# Display Linux tasks dynamically  
# -u user : show processes for a specific user  
# -n num : update display ‘num’ times before exiting  
# Example:  
top -u root  

htop  
# Interactive process viewer (advanced top)  
# Example:  
htop  

kill [options] PID  
# Send a signal to a process, typically to terminate  
# -9 : force kill a process  
# -15 : terminate a process gracefully  
# Example:  
kill -9 1234  

killall [options] process_name  
# Terminate processes by name  
# -9 : force kill all processes with the given name  
# Example:  
killall -9 firefox  

bg [job_id]  
# Resume a suspended job in the background  
# Example:  
bg %1  

fg [job_id]  
# Bring a job to the foreground  
# Example:  
fg %1  

jobs  
# List active jobs  
# Example:  
jobs  

nice [-n adjustment] command  
# Run a program with modified scheduling priority  
# Default priority is 0, lower values give higher priority  
# Example:  
nice -n 10 myscript.sh  

renice priority -p PID  
# Alter priority of running processes  
# Example:  
renice 5 -p 1234  

uptime  
# Show how long the system has been running  
# Example:  
uptime  

time command  
# Measure program running time  
# Example:  
time ls -l  

4. Disk Management

# Disk Management

df [options]  
# Report file system disk space usage  
# -h : human-readable format  
# -T : show file system type  
# -i : display inode usage  
# Example:  
df -h  

du [options] [directory]  
# Estimate file space usage  
# -h : human-readable format  
# -s : show total size of a directory  
# -c : display grand total  
# Example:  
du -sh /var/log  

fdisk [options] device  
# Partition table manipulator for Linux  
# -l : list partition tables  
# Example:  
fdisk -l  

lsblk [options]  
# List information about block devices  
# -f : show file system type  
# -o : specify columns to display  
# Example:  
lsblk -f  

mount [options] device mount_point  
# Mount a file system  
# -t type : specify file system type  
# -o options : mount with specific options  
# Example:  
mount -t ext4 /dev/sdb1 /mnt  

umount [options] device/mount_point  
# Unmount a file system  
# -l : lazy unmount  
# -f : force unmount  
# Example:  
umount /mnt  

parted [options] device  
# A partition manipulation program  
# -l : list partition details  
# Example:  
parted -l  

mkfs [options] -t type device  
# Create a file system  
# -t type : specify file system type (ext4, xfs, etc.)  
# Example:  
mkfs -t ext4 /dev/sdb1  

fsck [options] device  
# File system consistency check and repair  
# -y : automatically repair issues  
# -n : check only, do not repair  
# Example:  
fsck -y /dev/sdb1  

blkid [options]  
# Locate/print block device attributes  
# Example:  
blkid /dev/sdb1  

5. Networking

# Networking

ifconfig [interface] [options]  
# Configure network interfaces (deprecated, use 'ip' instead)  
# -a : display all interfaces  
# up : enable interface  
# down : disable interface  
# Example:  
ifconfig eth0 up  

ip [options] object [command]  
# Show/manipulate routing, devices, and tunnels  
# addr : show IP addresses  
# route : show routing table  
# link : show network interfaces  
# Example:  
ip addr show  

ping [options] host  
# Send ICMP Echo requests to network hosts  
# -c count : send a specific number of packets  
# -i interval : set interval between packets  
# Example:  
ping -c 5 google.com  

netstat [options]  
# Display network statistics (deprecated, use 'ss' instead)  
# -t : show TCP connections  
# -u : show UDP connections  
# -a : show all connections  
# Example:  
netstat -tulnp  

ss [options]  
# Show socket statistics (faster alternative to netstat)  
# -t : show TCP connections  
# -u : show UDP connections  
# -l : show listening ports  
# Example:  
ss -tulnp  

traceroute [options] host  
# Trace the route packets take to a network host  
# -n : show numeric addresses only  
# -m max_hops : set max number of hops  
# Example:  
traceroute -n google.com  

nslookup [options] domain  
# Query Internet name servers interactively  
# Example:  
nslookup example.com  

dig [options] domain  
# DNS lookup utility  
# +short : show concise output  
# Example:  
dig google.com  

wget [options] URL  
# Non-interactive network downloader  
# -O filename : specify output file  
# -q : quiet mode  
# Example:  
wget -O file.html https://example.com  

curl [options] URL  
# Transfer data with URLs  
# -o filename : specify output file  
# -I : fetch headers only  
# Example:  
curl -o file.html https://example.com  

scp [options] source destination  
# Secure copy files between hosts  
# -r : copy directories recursively  
# Example:  
scp file.txt user@192.168.1.10:/home/user/  

ssh [options] user@host  
# Secure shell for remote login  
# -p port : specify port  
# Example:  
ssh -p 22 user@192.168.1.10  

ftp [options] host  
# File Transfer Protocol client  
# Example:  
ftp ftp.example.com  

6. User and Group Management

# User and Group Management

useradd [options] username  
# Add a user to the system  
# -m : create the user's home directory  
# -s shell : specify default shell  
# Example:  
useradd -m -s /bin/bash john  

usermod [options] username  
# Modify a user account  
# -aG group : add user to a group  
# -s shell : change the user's shell  
# Example:  
usermod -aG sudo john  

userdel [options] username  
# Delete a user account  
# -r : remove the user's home directory and mail spool  
# Example:  
userdel -r john  

groupadd [options] groupname  
# Add a group to the system  
# -g gid : specify group ID  
# Example:  
groupadd developers  

groupdel groupname  
# Delete a group  
# Example:  
groupdel developers  

passwd [options] username  
# Change user password  
# -e : expire the user's password immediately  
# Example:  
passwd john  

chage [options] username  
# Change user password expiry information  
# -l : list password expiration info  
# -M max_days : set max days between password changes  
# Example:  
chage -M 30 john  

whoami  
# Print the current logged-in user  
# Example:  
whoami  

who [options]  
# Show who is logged in  
# -u : show idle time  
# Example:  
who -u  

w [options]  
# Show who is logged in and what they’re doing  
# -h : suppress header  
# Example:  
w -h  

id [options] username  
# Display user and group information  
# -u : display user ID  
# -g : display group ID  
# -G : display all groups the user belongs to  
# Example:  
id john  

groups [username]  
# Show user’s groups  
# Example:  
groups john  

7. System Information and Monitoring

# System Information and Monitoring

uname [options]  
# Print system information  
# -a : show all system information  
# -r : show the kernel release  
# Example:  
uname -a  

hostname [options]  
# Show or set the system’s hostname  
# -i : show the system's IP address  
# -f : show the fully qualified domain name  
# Example:  
hostname -i  

uptime  
# How long the system has been running  
# Example:  
uptime  

dmesg [options]  
# Boot and system messages  
# -T : show human-readable timestamps  
# -n level : set the level of messages to display  
# Example:  
dmesg -T  

free [options]  
# Display memory usage  
# -h : human-readable format  
# -m : display in megabytes  
# Example:  
free -h  

top [options]  
# Display Linux tasks dynamically  
# -u user : show processes for a specific user  
# -n num : update display ‘num’ times before exiting  
# Example:  
top -u root  

vmstat [options]  
# Report virtual memory statistics  
# -s : display summary statistics  
# -a : show active memory  
# Example:  
vmstat -s  

lscpu  
# Display information about the CPU architecture  
# Example:  
lscpu  

lsusb  
# List USB devices  
# Example:  
lsusb  

lspci  
# List PCI devices  
# Example:  
lspci  

lshw [options]  
# List hardware configuration  
# -short : display in a shorter format  
# -html : generate HTML output  
# Example:  
lshw -short  

8. Archiving and Compression

# Archiving and Compression

tar [options] [archive] [file(s)]  
# Archive files  
# -c : create an archive  
# -x : extract an archive  
# -f : specify the archive file  
# -z : compress with gzip  
# -j : compress with bzip2  
# -J : compress with xz  
# Example:  
tar -czf archive.tar.gz /path/to/directory  # Compress files using gzip  
tar -xzf archive.tar.gz  # Extract gzipped tarball  
tar -cf archive.tar /path/to/directory  # Create a tarball  
tar -xf archive.tar  # Extract tarball  

zip [options] archive.zip [file(s)]  
# Package and compress files into a ZIP archive  
# -r : recursively zip directories  
# -9 : set the compression level (1-9, where 9 is the highest)  
# Example:  
zip -r archive.zip /path/to/directory  

unzip [options] archive.zip  
# Extract files from a ZIP archive  
# -d directory : extract to a specific directory  
# Example:  
unzip archive.zip -d /path/to/extract  

gzip [options] file  
# Compress files using the gzip algorithm  
# -d : decompress the file  
# -k : keep the original file after compression  
# Example:  
gzip file.txt  # Compress file  
gzip -d file.txt.gz  # Decompress file  

gunzip [options] file.gz  
# Decompress files compressed with gzip  
# Example:  
gunzip file.txt.gz  

bzip2 [options] file  
# Compress files using the bzip2 algorithm  
# -d : decompress the file  
# -k : keep the original file after compression  
# Example:  
bzip2 file.txt  # Compress file  
bzip2 -d file.txt.bz2  # Decompress file  

bunzip2 [options] file.bz2  
# Decompress files compressed with bzip2  
# Example:  
bunzip2 file.txt.bz2  

xz [options] file  
# Compress files using the xz algorithm  
# -d : decompress the file  
# -k : keep the original file after compression  
# Example:  
xz file.txt  # Compress file  
xz -d file.txt.xz  # Decompress file  

unxz [options] file.xz  
# Decompress files compressed with xz  
# Example:  
unxz file.txt.xz  

9. Package Management (Depends on Distribution)

# Package Management (Depends on Distribution)

# Debian-based (e.g., Ubuntu)

apt-get [options] command  
# APT package handling utility  
# install : install a package  
# update : update package list  
# upgrade : upgrade installed packages  
# remove : remove a package  
# Example:  
apt-get install vim  # Install a package  
apt-get update  # Update package list  
apt-get upgrade  # Upgrade installed packages  
apt-get remove vim  # Remove a package  

apt-cache [options] command  
# Query APT cache  
# search : search for a package  
# show : show package details  
# Example:  
apt-cache search vim  # Search for a package  
apt-cache show vim  # Show package details  

# Red Hat-based (e.g., CentOS, Fedora)

yum [options] command  
# Package manager for RPM-based systems  
# install : install a package  
# update : update installed packages  
# remove : remove a package  
# Example:  
yum install vim  # Install a package  
yum update  # Update installed packages  
yum remove vim  # Remove a package  

dnf [options] command  
# Next-generation package manager (Fedora, CentOS 8+)  
# install : install a package  
# update : update installed packages  
# remove : remove a package  
# Example:  
dnf install vim  # Install a package  
dnf update  # Update installed packages  
dnf remove vim  # Remove a package  

10. General Commands

# General Commands

rpm [options] <package>  
# RPM package manager  
# -i : install an RPM package  
# -e : remove an RPM package  
# Example:  
rpm -i package.rpm  # Install an RPM package  
rpm -e package  # Remove an RPM package  

dpkg [options] <package>  
# Debian package manager  
# -i : install a Debian package  
# -r : remove a Debian package  
# Example:  
dpkg -i package.deb  # Install a Debian package  
dpkg -r package  # Remove a Debian package  

11. System Services and Daemon Management

# System Services and Daemon Management

systemctl [options] <service>  
# Control the systemd system and service manager  
# start : start a service  
# stop : stop a service  
# restart : restart a service  
# enable : enable a service to start on boot  
# disable : disable a service from starting on boot  
# status : check service status  
# Example:  
systemctl start apache2  # Start a service  
systemctl stop apache2  # Stop a service  
systemctl restart apache2  # Restart a service  
systemctl enable apache2  # Enable a service to start on boot  
systemctl disable apache2  # Disable a service from starting on boot  
systemctl status apache2  # Check service status  

service [options] <service>  
# Older service management command (used in non-systemd systems)  
# start : start a service  
# stop : stop a service  
# restart : restart a service  
# status : check service status  
# Example:  
service apache2 start  # Start a service  
service apache2 stop  # Stop a service  
service apache2 restart  # Restart a service  
service apache2 status  # Check service status  

12. Scheduling Tasks

# Scheduling Tasks

cron  
# Daemon for running scheduled commands  
# Example:  
# Edit, list, or remove cron jobs using the crontab command (listed below).  

crontab [options]  
# Manage cron jobs for the current user  
# -e : edit cron jobs  
# -l : list the current user’s cron jobs  
# -r : remove the current user's cron jobs  
# Example:  
crontab -e  # Edit cron jobs for the current user  
crontab -l  # List the current user’s cron jobs  
crontab -r  # Remove the current user's cron jobs  

at [time]  
# Run commands at a specified time  
# Example:  
at 09:00  # Schedule a command to run at 09:00 AM  

batch  
# Run commands when the system load is low  
# Example:  
batch  # Run commands when the system load is low  

sleep [time]  
# Delay for a specified time  
# Example:  
sleep 5s  # Sleep for 5 seconds  

13. File Permissions and Security

# File Permissions and Security

chmod [options] <file>  
# Change file permissions  
# -r : recursively change permissions for directories and their contents  
# Example:  
chmod 755 file.txt  # Change file permissions to rwx-r-xr-x  
chmod -r 755 /path/to/directory  # Change permissions recursively  

chown [options] <user>:<group> <file>  
# Change file owner and group  
# -R : recursively change ownership for directories and their contents  
# Example:  
chown user:group file.txt  # Change file owner and group  
chown -R user:group /path/to/directory  # Change ownership recursively  

chgrp [options] <group> <file>  
# Change the group ownership of a file  
# -R : recursively change group ownership for directories and their contents  
# Example:  
chgrp group file.txt  # Change group ownership of a file  
chgrp -R group /path/to/directory  # Change group ownership recursively  

umask [mode]  
# Set default permissions for new files  
# Example:  
umask 022  # Set default permissions for new files  

setfacl [options] <file>  
# Set file access control lists (ACL)  
# -m : modify ACL  
# -x : remove an ACL  
# Example:  
setfacl -m u:username:rw file.txt  # Set ACL to allow a user read/write access  

getfacl [options] <file>  
# Get file access control lists (ACL)  
# Example:  
getfacl file.txt  # Get the ACL of a file  

sudo [command]  
# Execute a command as another user (usually root)  
# Example:  
sudo apt-get update  # Execute command as root  

visudo  
# Edit the sudoers file safely  
# Example:  
visudo  # Edit the sudoers file safely  

passwd [options] <user>  
# Change a user’s password  
# Example:  
passwd  # Change the password of the current user  
passwd username  # Change the password for a specific user  

sudoers  
# Manage sudo access for users  
# Example:  
# This is typically edited using visudo (listed above).  

gpasswd [options] <group>  
# Administer group password  
# Example:  
gpasswd groupname  # Administer password for a group  

ss [options]  
# Display socket statistics (for secure network connections)  
# -t : show TCP sockets  
# -u : show UDP sockets  
# Example:  
ss -tuln  # Show listening sockets for TCP and UDP  

14. System Backup and Restore

# System Backup and Restore

rsync [options] <source> <destination>  
# Remote file and directory synchronization  
# -a : archive mode (preserve symbolic links, permissions, timestamps, etc.)  
# -v : verbose  
# -z : compress file data during transfer  
# Example:  
rsync -avz source/ destination/  # Synchronize files  
rsync -avz -e ssh source/ user@remote:/destination/  # Sync over SSH  

cpio [options]  
# Copy files to and from archives  
# Example:  
# cpio is typically used in conjunction with other commands like find for backup and restore  
find /path/to/files | cpio -ov > backup.cpio  # Create a backup archive  
cpio -iv < backup.cpio  # Extract files from the archive  

dd [options]  
# Low-level copying and backup of entire filesystems  
# if : input file or device  
# of : output file or device  
# Example:  
dd if=/dev/sda of=/path/to/backup.img  # Backup a disk/partition  
dd if=/path/to/backup.img of=/dev/sda  # Restore a disk/partition  

15. System Diagnostics and Troubleshooting

# System Diagnostics and Troubleshooting

dmesg [options]  
# Print the kernel ring buffer messages (system boot and hardware-related messages)  
# Example:  
dmesg  # View kernel ring buffer messages  

journalctl [options]  
# Query and view logs from systemd’s journal  
# Example:  
journalctl  # View all systemd logs  
journalctl -u apache2  # View logs for a specific service  

strace [options] <command>  
# Trace system calls and signals  
# Example:  
strace ls  # Trace the system calls of the ls command  

lsof [options]  
# List open files (useful for debugging)  
# Example:  
lsof  # List all open files  
lsof /path/to/file  # Show processes using a specific file  

vmstat [options]  
# Report virtual memory statistics  
# Example:  
vmstat 1  # Report every second  

iostat [options]  
# Report CPU and I/O statistics  
# Example:  
iostat  # Report CPU and I/O statistics  

mpstat [options]  
# Report CPU usage statistics  
# Example:  
mpstat 1  # Report CPU usage every second  

pidstat [options]  
# Report statistics by process  
# Example:  
pidstat 1  # Report process statistics every second  

free [options]  
# Display memory usage  
# Example:  
free -h  # Display memory usage in human-readable format  

uptime  
# How long the system has been running  
# Example:  
uptime  # Show system uptime  

watch [options] <command>  
# Execute a program periodically, showing output  
# -n : interval in seconds  
# Example:  
watch -n 1 free  # Watch memory usage every second  

lshw [options]  
# List hardware configuration  
# Example:  
lshw  # List detailed hardware configuration  

htop  
# Interactive process viewer (better than top)  
# Example:  
htop  # Launch the interactive process viewer  

netstat [options]  
# Network statistics (deprecated in favor of ss)  
# Example:  
netstat  # Show network statistics  

ss [options]  
# Show socket statistics (more efficient than netstat)  
# Example:  
ss -tuln  # Show listening TCP/UDP sockets  

16. Networking & Remote Management

# Networking & Remote Management

ifconfig [options]  
# Configure network interfaces (older command, replaced by ip)  
# Example:  
ifconfig  # View or configure network interfaces  

ip [options]  
# A more modern alternative for managing network interfaces and routing  
# ip addr : Show IP addresses  
# ip link : Show or manipulate network interfaces  
# ip route : Show or manipulate routing tables  
# Example:  
ip addr  # Show IP addresses  
ip link  # Show or manipulate network interfaces  
ip route  # Show or manipulate routing tables  

ss [options]  
# Display socket statistics (useful for diagnosing network issues)  
# Example:  
ss -tuln  # Show listening TCP/UDP sockets  

nmap [options]  
# Network exploration tool (can be used for security auditing)  
# Example:  
nmap -sP 192.168.1.0/24  # Scan a network range  

telnet [options]  
# User interface to the TELNET protocol (less common nowadays)  
# Example:  
telnet <host>  # Connect to a remote host via TELNET  

nc (Netcat) [options]  
# Network utility for reading and writing from network connections  
# -l : listen mode  
# -p : port  
# Example:  
nc -l -p 1234  # Listen on port 1234  
nc <host> <port>  # Connect to a host and port  

iptables [options]  
# Administration tool for IPv4 packet filtering and NAT (Network Address Translation)  
# Example:  
iptables -L  # List current iptables rules  

firewalld [options]  
# Frontend for managing firewall rules (used in some distros like Fedora and CentOS)  
# Example:  
firewalld --zone=public --add-port=80/tcp  # Allow HTTP traffic  

ufw [options]  
# Uncomplicated firewall (front-end for iptables)  
# -enable : enable firewall  
# -allow <port> : allow traffic on a specific port  
# Example:  
ufw enable  # Enable firewall  
ufw allow 80  # Allow HTTP traffic  

tcpdump [options]  
# Command-line packet analyzer  
# Example:  
tcpdump -i eth0  # Capture packets on interface eth0  

curl [options]  
# Transfer data from or to a server using various protocols (HTTP, FTP, etc.)  
# Example:  
curl -O http://example.com/file.txt  # Download a file  

wget [options]  
# Download files from the web via HTTP, HTTPS, FTP  
# Example:  
wget http://example.com/file.txt  # Download a file  

scp [options]  
# Secure copy over SSH (used to copy files between systems)  
# Example:  
scp file.txt user@remote:/path/to/destination/  # Copy file to remote server  

rsync [options]  
# Remote file and directory synchronization (often used for backups)  
# Example:  
rsync -avz /local/path/ remote:/remote/path/  # Sync directories  

17. Text Processing Utilities

# Text Processing Utilities

grep [options] 'pattern' [file]  
# Search for patterns within files  
# -r : recursively search in directories  
# Example:  
grep 'pattern' file.txt  # Search for a pattern in a file  
grep -r 'pattern' /dir/  # Recursively search for a pattern  

sed [options]  
# Stream editor for filtering and transforming text  
# s/old/new/g : replace 'old' with 'new' globally  
# Example:  
sed 's/old/new/g' file.txt  # Replace old with new globally  

awk [options]  
# A powerful text processing language  
# {print $1} : print the first column of each line in a file  
# Example:  
awk '{print $1}' file.txt  # Print the first column of each line in a file  

cut [options]  
# Remove sections from each line of a file  
# -d : delimiter  
# -f : field(s) to extract  
# Example:  
cut -d ':' -f 1 /etc/passwd  # Print the first field of each line, delimited by ":"  

sort [options]  
# Sort lines of text files  
# Example:  
sort file.txt  # Sort file content in ascending order  

uniq [options]  
# Report or omit repeated lines in a file  
# Example:  
sort file.txt | uniq  # Sort and remove duplicate lines  

tee [options]  
# Read from standard input and write to standard output and files  
# Example:  
echo "text" | tee file.txt  # Write to file and show output on screen  

tr [options]  
# Translate or delete characters  
# Example:  
echo "hello" | tr 'a-z' 'A-Z'  # Convert lowercase to uppercase  

paste [options]  
# Merge lines of files  
# Example:  
paste file1.txt file2.txt  # Combine lines of file1 and file2 side by side  

wc [options]  
# Word, line, character, and byte count  
# -l : count lines  
# -w : count words  
# Example:  
wc -l file.txt  # Count lines in a file  
wc -w file.txt  # Count words in a file  

18. System Shutdown and Reboot

# System Shutdown and Reboot

shutdown [options]  
# Shut down the system  
# -h : halt the system  
# -r : reboot the system  
# +<time> : shut down after specified minutes  
# Example:  
shutdown -h now  # Immediately shut down  
shutdown -r now  # Reboot the system  
shutdown -h +10  # Shut down after 10 minutes  

reboot  
# Reboot the system  
# Example:  
reboot  # Reboot the system  

halt  
# Halt the system immediately (equivalent to turning off power)  
# Example:  
halt  # Stop all system processes  

poweroff  
# Power off the system  
# Example:  
poweroff  # Turn off the system  

init [runlevel]  
# Change the runlevel (old-style system manager)  
# 0 : shutdown  
# 6 : reboot  
# Example:  
init 0  # Shutdown  
init 6  # Reboot

19. File System Mounting and Management

# File System Mounting and Management

mount [options] [device] [mount-point]  
# Mount a file system  
# Example:  
mount /dev/sda1 /mnt  # Mount partition to a directory  

umount [options] [mount-point]  
# Unmount a file system  
# Example:  
umount /mnt  # Unmount the file system mounted at /mnt  

fstab  
# File system table (configuration file for mounting file systems)  
# /etc/fstab : View and configure persistent mount points  
# Example:  
cat /etc/fstab  # View fstab configuration  

blkid  
# Display block device attributes  
# Example:  
blkid  # Show attributes of all block devices  

fsck [options] [device]  
# Check and repair a file system  
# Example:  
fsck /dev/sda1  # Check and repair /dev/sda1  

20. Filesystem Permissions and Security

# Filesystem Permissions and Security

chmod [options] [permissions] [file]  
# Change file permissions  
# Example:  
chmod 755 file.txt  # Give read, write, and execute permissions to owner, and read-execute permissions to others  

chown [options] [owner][:group] [file]  
# Change file owner and group  
# Example:  
chown user:group file.txt  # Change owner and group of a file  

chgrp [options] [group] [file]  
# Change group ownership of a file  
# Example:  
chgrp group file.txt  # Change the group of a file  

umask [permissions]  
# Set default permissions for new files  
# Example:  
umask 022  # Set default permissions for newly created files to 755  

setfacl [options] [file]  
# Set access control lists (ACL) for file permissions  
# Example:  
setfacl -m u:user:rwx file.txt  # Set ACL to give 'user' read, write, execute permissions  

getfacl [file]  
# Get access control lists (ACL) for file permissions  
# Example:  
getfacl file.txt  # View ACL for a file  

21. Containerization and Orchestration

Docker

docker [options] [command]  
# Docker command-line interface (CLI) for managing containers

docker run [options] <image>  
# Run a container from an image  
# Example:  
docker run ubuntu  # Run a container from the Ubuntu image  

docker ps [options]  
# List running containers  
# Example:  
docker ps  # List all running containers  

docker ps -a [options]  
# List all containers, including stopped ones  
# Example:  
docker ps -a  # List all containers  

docker build -t <image_name> .  
# Build an image from a Dockerfile  
# Example:  
docker build -t my-image .  # Build an image named 'my-image' from the Dockerfile in the current directory  

docker exec -it <container_id> bash  
# Start an interactive bash shell inside a running container  
# Example:  
docker exec -it container_id bash  # Access bash shell in a running container  

docker stop <container_id>  
# Stop a container  
# Example:  
docker stop container_id  # Stop the container with the specified ID  

docker rm <container_id>  
# Remove a container  
# Example:  
docker rm container_id  # Remove the specified container  

docker logs <container_id>  
# View logs of a container  
# Example:  
docker logs container_id  # View logs from the container  

docker images [options]  
# List available images  
# Example:  
docker images  # List all Docker images  

docker rmi <image_name>  
# Remove an image  
# Example:  
docker rmi my-image  # Remove the 'my-image' image  

docker network ls  
# List Docker networks  
# Example:  
docker network ls  # List all Docker networks  

docker-compose [options]  
# Manage multi-container Docker applications

docker-compose up [options]  
# Start up a multi-container environment  
# Example:  
docker-compose up  # Start up the environment defined in the docker-compose.yml file  

docker-compose down [options]  
# Stop and remove containers created by docker-compose  
# Example:  
docker-compose down  # Stop and remove the containers  

docker-compose logs [options]  
# View logs from containers managed by docker-compose  
# Example:  
docker-compose logs  # View logs from containers in the docker-compose environment  

Kubernetes (k8s)

# Kubernetes (k8s)

kubectl [options] [command]  
# Command-line tool for interacting with Kubernetes clusters

kubectl get pods [options]  
# List pods in the current namespace  
# Example:  
kubectl get pods  # List all pods in the current namespace

kubectl get nodes [options]  
# List nodes in the cluster  
# Example:  
kubectl get nodes  # List all nodes in the cluster

kubectl get services [options]  
# List services in the cluster  
# Example:  
kubectl get services  # List all services in the cluster

kubectl apply -f <file>.yaml [options]  
# Apply configuration from a file (e.g., a deployment or pod configuration)  
# Example:  
kubectl apply -f deployment.yaml  # Apply configuration from the deployment.yaml file

kubectl create -f <file>.yaml [options]  
# Create a resource from a file  
# Example:  
kubectl create -f pod.yaml  # Create a pod from the pod.yaml file

kubectl delete -f <file>.yaml [options]  
# Delete a resource defined in a file  
# Example:  
kubectl delete -f service.yaml  # Delete the service defined in service.yaml

kubectl exec -it <pod_name> -- bash  
# Execute a command inside a pod (e.g., open a shell)  
# Example:  
kubectl exec -it my-pod -- bash  # Open a bash shell inside the 'my-pod' pod

kubectl logs <pod_name>  
# View the logs of a pod  
# Example:  
kubectl logs my-pod  # View logs of the 'my-pod' pod

kubectl describe pod <pod_name>  
# Get detailed information about a pod  
# Example:  
kubectl describe pod my-pod  # Get detailed information about the 'my-pod' pod

kubectl scale deployment <deployment_name> --replicas=<number>  
# Scale a deployment to the desired number of replicas  
# Example:  
kubectl scale deployment my-deployment --replicas=3  # Scale 'my-deployment' to 3 replicas

kubectl rollout restart deployment <deployment_name>  
# Restart a deployment  
# Example:  
kubectl rollout restart deployment my-deployment  # Restart the 'my-deployment' deployment

kubectl port-forward pod <pod_name> <local_port>:<remote_port>  
# Forward a port from a pod to localhost  
# Example:  
kubectl port-forward pod my-pod 8080:80  # Forward port 80 from 'my-pod' to local port 8080

Helm – Kubernetes package manager for deploying applications

# Helm - Kubernetes package manager for deploying applications

helm [options] [command]  
# Helm CLI for managing Kubernetes applications

helm install <release_name> <chart_name> [options]  
# Install a Helm chart  
# Example:  
helm install my-release stable/mysql  # Install the 'mysql' chart with the release name 'my-release'

helm upgrade <release_name> <chart_name> [options]  
# Upgrade a Helm release  
# Example:  
helm upgrade my-release stable/mysql  # Upgrade the 'my-release' release to the latest 'mysql' chart version

helm list [options]  
# List all Helm releases  
# Example:  
helm list  # List all the installed Helm releases

helm delete <release_name> [options]  
# Delete a Helm release  
# Example:  
helm delete my-release  # Delete the 'my-release' Helm release

helm search <chart_name> [options]  
# Search for a Helm chart  
# Example:  
helm search mysql  # Search for Helm charts related to 'mysql'

Ansible

ansible [options] [command]  
# Ansible CLI for automation and configuration management

ansible all -m ping  
# Ping all hosts defined in the inventory  
# Example:  
ansible all -m ping  # Test connectivity to all hosts

ansible-playbook playbook.yml  
# Run an Ansible playbook  
# Example:  
ansible-playbook deploy_app.yml  # Execute the specified playbook

ansible -m command -a 'command' <host>  
# Run a single command on a target host  
# Example:  
ansible -m command -a 'uptime' server01  # Run 'uptime' on 'server01'

ansible-playbook --check playbook.yml  
# Dry-run a playbook to see what would change  
# Example:  
ansible-playbook --check deploy_app.yml  # Preview changes without actually applying

ansible-playbook --limit <host> playbook.yml  
# Run a playbook on a specific host or group  
# Example:  
ansible-playbook --limit server01 deploy_app.yml  # Run the playbook only on 'server01'

ansible-playbook --extra-vars "key=value"  
# Pass extra variables to a playbook  
# Example:  
ansible-playbook -e "env=production" deploy_app.yml  # Pass 'env=production' to the playbook

Terraform

terraform [options] [command]  
# Terraform CLI for infrastructure as code

terraform init  
# Initialize a working directory for Terraform configuration  
# Example:  
terraform init  # Initialize the directory containing Terraform configuration files

terraform plan  
# Show an execution plan (preview of what changes will be made)  
# Example:  
terraform plan  # Preview the changes that will be made to infrastructure

terraform apply  
# Apply the changes described in a Terraform configuration  
# Example:  
terraform apply  # Apply the planned changes to infrastructure

terraform destroy  
# Destroy infrastructure created by Terraform  
# Example:  
terraform destroy  # Destroy all infrastructure managed by Terraform

terraform validate  
# Validate the configuration files  
# Example:  
terraform validate  # Check for any syntax or logical errors in Terraform files

terraform show  
# Show the current state of the infrastructure  
# Example:  
terraform show  # Display the current infrastructure state

Puppet

puppet [options] [command]  
# Puppet CLI for configuration management

puppet apply <manifest.pp>  
# Apply a Puppet manifest locally  
# Example:  
puppet apply site.pp  # Apply the local Puppet manifest 'site.pp'

puppet agent --test  
# Test the Puppet agent (can be used to run a one-off run)  
# Example:  
puppet agent --test  # Run a one-time agent run for configuration management

puppet resource  
# Show the current state of resources (files, services, etc.)  
# Example:  
puppet resource service apache  # Show the current state of the Apache service

22. CI / CD Tool and Commands

Jenkins

java -jar jenkins.war  
# Start Jenkins from a WAR file  
# Example:  
java -jar jenkins.war  # Launch Jenkins server from the 'jenkins.war' file

# Access Jenkins through http://localhost:8080 by default

GitLab CI

.gitlab-ci.yml  
# Configuration file for GitLab CI/CD pipelines (typically resides in your repository)  
# Example:  
# .gitlab-ci.yml file defines the pipeline stages and jobs

gitlab-runner register  
# Register a new runner with GitLab  
# Example:  
gitlab-runner register --url https://gitlab.com/ --registration-token <token>  # Register a runner

gitlab-runner run  
# Run the GitLab Runner to process jobs  
# Example:  
gitlab-runner run  # Run the registered runner to execute jobs

GitHub Actions

# GitHub Actions uses YAML configuration files (typically located in .github/workflows/)
# Example of GitHub Action YAML file:

name: CI Pipeline  
on:  
  push:
    branches: [main]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2  # Checkout the repository code in your CI pipeline
      
      - name: Setup Node.js  
        uses: actions/setup-node@v2  # Setup Node.js for use in a pipeline
      
      - name: Set up Docker Buildx  
        uses: docker/setup-buildx-action@v1  # Set up Docker Buildx for building multi-platform images

23. Cloud Services

AWS CLI

aws [service] [operation] [options]  
# Command-line tool for managing AWS services

aws configure  
# Configure AWS CLI with your credentials  
# Example:  
aws configure  # Set up AWS access credentials (Access Key, Secret Key, region)

aws s3 cp file.txt s3://bucket-name/  
# Copy a file to an S3 bucket  
# Example:  
aws s3 cp file.txt s3://my-bucket/  # Upload 'file.txt' to S3 bucket

aws ec2 describe-instances  
# Describe EC2 instances  
# Example:  
aws ec2 describe-instances  # Get details of EC2 instances

aws ec2 start-instances --instance-ids <id>  
# Start an EC2 instance  
# Example:  
aws ec2 start-instances --instance-ids i-0123456789abcde  # Start an EC2 instance with the given ID

aws ec2 stop-instances --instance-ids <id>  
# Stop an EC2 instance  
# Example:  
aws ec2 stop-instances --instance-ids i-0123456789abcde  # Stop an EC2 instance with the given ID

aws s3 sync  
# Sync directories with an S3 bucket  
# Example:  
aws s3 sync /local/directory/ s3://my-bucket/  # Sync local directory to S3 bucket

Azure CLI

az [service] [operation] [options]  
# Command-line tool for managing Azure services

az login  
# Log in to your Azure account  
# Example:  
az login  # Log in to Azure

az vm list  
# List all virtual machines  
# Example:  
az vm list  # Get a list of all VMs in Azure

az vm start --name <vm_name> --resource-group <resource_group>  
# Start an Azure VM  
# Example:  
az vm start --name myVM --resource-group myResourceGroup  # Start a VM named 'myVM'

az storage blob upload  
# Upload files to an Azure blob storage  
# Example:  
az storage blob upload --container-name mycontainer --file file.txt --name file.txt  # Upload file to Azure blob storage

az group create  
# Create a new resource group in Azure  
# Example:  
az group create --name myResourceGroup --location eastus  # Create a new resource group

Google Cloud SDK (gcloud)

gcloud [service] [operation] [options]  
# Command-line tool for Google Cloud Platform

gcloud auth login  
# Log in to Google Cloud  
# Example:  
gcloud auth login  # Log in to your Google Cloud account

gcloud compute instances list  
# List compute instances  
# Example:  
gcloud compute instances list  # Get a list of VM instances in Google Cloud

gcloud compute instances stop <instance_name>  
# Stop a Google Cloud VM instance  
# Example:  
gcloud compute instances stop my-instance  # Stop the VM 'my-instance'

gcloud app browse  
# Open the current Google App Engine application in a browser  
# Example:  
gcloud app browse  # Open the app hosted in Google Cloud

24. Logging and Monitoring

Prometheus (System Monitoring and Alerting Toolkit)

prometheus  
# Start Prometheus server (usually runs as a service in the background)  
# Example:  
prometheus  # Starts Prometheus monitoring system

prometheus --config.file=<config_file>  
# Start Prometheus with a specific config file  
# Example:  
prometheus --config.file=/etc/prometheus/prometheus.yml  # Run Prometheus with custom configuration file

Grafana (Open-Source Data Visualization)

grafana-cli  
# Command-line interface for managing Grafana plugins

grafana-cli plugins install <plugin-name>  
# Install a plugin in Grafana  
# Example:  
grafana-cli plugins install grafana-clock-panel  # Install Grafana clock panel plugin

ELK Stack (Elasticsearch, Logstash, Kibana)

Elasticsearch (Search Engine for Logging and Data Analytics)

curl -XGET 'localhost:9200/_cluster/health?pretty'  
# Get cluster health status  
# Example:  
curl -XGET 'localhost:9200/_cluster/health?pretty'  # Check the health of your Elasticsearch cluster

Logstash (Server-Side Data Processing Pipeline)

logstash -f <config_file>  
# Run Logstash with the specified configuration file  
# Example:  
logstash -f /etc/logstash/conf.d/logstash.conf  # Run Logstash with a specific configuration file

Kibana (Web Interface for Visualizing Elasticsearch Data)

# Kibana is generally accessed through a web browser
# Access Kibana interface at:
http://localhost:5601  
# Example:  
# Open Kibana dashboard in the web browser to visualize data

ADVERTISEMENT

You might like

Leave a Reply

Your email address will not be published. Required fields are marked *