Linux Cheat Sheets & Command References
Quick, practical Linux cheat sheets for system administrators and DevOps engineers. Bookmarkable command references covering filesystems, LVM, systemctl, storage, networking, and everyday Linux operations.
⬇️ Jump To
File & Directory Management
| Command | Description |
|---|---|
ls |
List files and directories in the current location |
ls -l |
Display files with permissions, owner, size, and timestamp |
ls -a |
Include hidden files starting with dot |
ls -lh |
Show file sizes in human-readable format |
tree |
Display directory structure in a tree format |
cd /path |
Change current working directory |
pwd |
Print the absolute path of the current directory |
mkdir dir |
Create a new directory |
mkdir -p a/b/c |
Create nested directories in one command |
rmdir dir |
Remove an empty directory |
cp src dest |
Copy file from source to destination |
cp -r src dest |
Copy directories recursively |
mv src dest |
Move or rename files or directories |
rm file |
Delete a file |
rm -r dir |
Delete directory and its contents recursively |
rm -f file |
Force delete file without confirmation |
touch file |
Create an empty file or update timestamp |
stat file |
Show detailed file metadata |
ln src link |
Create a hard link |
ln -s src link |
Create a symbolic (soft) link |
File Searching
| Command | Description |
|---|---|
find /path -name file |
Search files by name in the specified directory path |
find /path -iname file |
Search filenames without considering letter case |
find /path -type f |
Find only regular files, excluding directories and links |
find /path -perm /4000 |
Locate files that have the SUID permission bit set |
find /path -size +10M |
Find files larger than the specified size |
find /path -mtime -1 |
Find files modified within the last 24 hours |
find /path -empty |
Locate empty files and empty directories |
find /path -links +1 |
Find files that have more than one hard link |
locate file |
Quickly find files using the system locate database |
locate -i file |
Perform case-insensitive file search using locate |
locate -r regex |
Search files using regular expression patterns |
updatedb |
Update the database used by the locate command |
Viewing & Paging Files
| Command | Description |
|---|---|
cat file |
Display the entire contents of a file on the terminal |
less file |
View file content page by page with scroll and search support |
more file |
View file content one screen at a time with limited navigation |
head file |
Show the first 10 lines of a file by default |
head -n 20 file |
Display the first 20 lines of the specified file |
tail file |
Show the last 10 lines of a file by default |
tail -n 20 file |
Display the last 20 lines of the specified file |
tail -f file |
Continuously monitor a file as new lines are appended, commonly used for logs |
Text Processing
| Command | Description |
|---|---|
grep pattern file | Search for a specific text pattern inside a file |
grep -i pattern file | Perform case-insensitive text search |
grep -r pattern dir | Search recursively through all files in a directory |
grep -v pattern file | Display lines that do not match the given pattern |
grep -A 3 pattern file | Show three lines after each matching line |
grep -B 3 pattern file | Show three lines before each matching line |
awk '{print $1}' file | Print the first column from each line of a file |
awk -F: '{print $1}' file | Use a custom field delimiter to extract columns |
sed 's/a/b/' file | Replace the first occurrence of a pattern in each line |
sed -i 's/a/b/g' file | Replace all occurrences in a file and save changes |
cut -d: -f1 file | Extract a specific column using a delimiter |
sort file | Sort the contents of a file alphabetically |
uniq | Remove duplicate adjacent lines from sorted input |
wc -l file | Count the number of lines in a file |
diff f1 f2 | Compare two files and show line-by-line differences |
tee file | Write command output to both the terminal and a file |
Permissions & Ownership
| Command | Description |
|---|---|
chmod 755 file |
Set read, write, and execute permissions using numeric mode |
chmod -R 755 dir |
Recursively change permissions for all files and directories |
chmod u+x file |
Add execute permission for the file owner |
chown user file |
Change the owner of a file to the specified user |
chown user:group file |
Change both owner and group of a file |
chown -R user:group dir |
Recursively change ownership for a directory and its contents |
chgrp group file |
Change the group ownership of a file |
umask |
Display the default permission mask for new files and directories |
Archiving & Compression
| Command | Description |
|---|---|
tar -cvf a.tar files |
Create a tar archive containing specified files |
tar -xvf a.tar |
Extract files from a tar archive |
tar -czvf a.tar.gz files |
Create a gzip-compressed tar archive |
tar -xzvf a.tar.gz |
Extract files from a gzip-compressed tar archive |
gzip file |
Compress a file using the gzip compression algorithm |
gunzip file.gz |
Decompress a gzip-compressed file |
zip a.zip files |
Create a zip archive from one or more files |
zip -r a.zip dir |
Compress a directory recursively into a zip archive |
unzip a.zip |
Extract files from a zip archive |
Networking
| Command | Description |
|---|---|
ping host |
Test network connectivity to a remote host |
ip a |
Display IP addresses and network interface details |
ip link |
Show available network interfaces and their state |
ip r |
Display the system routing table |
ip neigh |
Show ARP or neighbor cache entries |
ip route get IP |
Show the network route used to reach a destination |
ss -tuln |
List all listening TCP and UDP ports |
ss -tanp |
Show active TCP connections with associated processes |
netstat -tulnp |
Display network connections using the legacy netstat tool |
ifconfig |
Display network interface configuration (deprecated) |
nmcli device status |
Show NetworkManager device connection status |
curl URL |
Fetch data from a URL or test HTTP endpoints |
wget URL |
Download files from a URL to the local system |
scp src dest |
Securely copy files between local and remote systems |
ssh user@host |
Log in to a remote system securely using SSH |
traceroute host |
Trace the network path packets take to a destination |
nslookup domain |
Query DNS servers for domain name information |
host domain |
Perform a simple DNS lookup for a domain |
nmcli con show |
List all configured network connections |
nmcli con show <name> |
Show detailed settings of a specific network connection |
nmcli con add ... |
Create a new NetworkManager connection profile |
nmcli con mod <name> ... |
Modify configuration settings of an existing connection |
nmcli con up <name> |
Activate and bring up a network connection |
nmcli dev disconnect <device> |
Disconnect or disable a specific network device |
nmcli con del <name> |
Delete an existing network connection profile |
nmcli con reload |
Reload NetworkManager connection configuration files |
Process & System Monitoring
| Command | Description |
|---|---|
ps aux |
Display all running processes with detailed information |
top |
Show a real-time, continuously updating process list |
htop |
Enhanced interactive process viewer with color and controls |
uptime |
Display system run time and average system load |
watch cmd |
Execute a command repeatedly and display the output |
jobs |
List jobs currently running in the background |
bg %job |
Resume a stopped job and run it in the background |
fg %job |
Bring a background or stopped job to the foreground |
kill PID |
Send a termination signal to gracefully stop a process |
kill -9 PID |
Forcefully terminate a process using SIGKILL |
nice -n 10 cmd |
Start a command with a lower CPU scheduling priority |
renice PID |
Change the priority of an already running process |
Performance & Resource Monitoring
| Command | Description |
|---|---|
free |
Display current system memory usage statistics |
free -h |
Show memory usage in human-readable format |
vmstat |
Report memory, CPU, and I/O performance statistics |
vmstat 1 |
Refresh system statistics every second |
iostat |
Display disk input and output statistics |
iostat -xz 1 |
Show extended disk performance metrics with live updates |
mpstat |
Display CPU usage statistics for each processor core |
pidstat |
Report performance statistics for individual processes |
sar |
View historical system performance data collected over time |
nproc |
Show the number of CPU cores available to the system |
nproc --all |
Display the total number of installed CPU cores |
RPM Package Management
| Command | Description |
|---|---|
rpm -qa |
List all RPM packages currently installed on the system |
rpm -q NAME |
Display the installed version of a specific package |
rpm -qi NAME |
Show detailed information about an installed package |
rpm -ql NAME |
List all files installed by a package |
rpm -qc NAME |
Display configuration files provided by the package |
rpm -qd NAME |
List documentation files included with the package |
rpm -q --changelog NAME |
Show the change history of the specified package |
rpm -q --scripts NAME |
Display scripts executed during package install or removal |
rpm -qf FILE |
Identify which installed package owns a given file |
rpm -qlp FILE.rpm |
List files contained inside an RPM package file |
YUM Package Management
| Command | Description |
|---|---|
yum list |
List all available and installed packages from configured repositories |
yum group list |
Display available package groups for bulk installation |
yum search KEYWORD |
Search repositories for packages matching a keyword |
yum info PACKAGENAME |
Show detailed information about a specific package |
yum install PACKAGENAME |
Install a package along with all required dependencies |
yum group install GROUPNAME |
Install a predefined group of related packages |
yum update |
Update all installed packages to their latest versions |
yum remove PACKAGENAME |
Remove an installed package from the system |
yum history |
Display the transaction history of package operations |
Disk & Filesystem
| Command | Description |
|---|---|
df -h | Show disk usage per filesystem in human-readable format |
df -i | Display inode usage for each mounted filesystem |
du -sh dir | Show total disk space used by a directory |
du -x | Display disk usage only on the same filesystem |
lsblk | List block devices and their hierarchy |
lsblk -f | Show filesystem type, UUID, and mount points |
blkid | Display block device attributes such as UUID and type |
mount dev dir | Mount a filesystem to a directory |
mount | column -t | Display mounted filesystems in a readable table format |
mount | grep ext4 | Filter and show only ext4 mounted filesystems |
mount UUID="<uuid>" /mnt/point | Mount a filesystem using its UUID instead of the device name |
lsof /mnt/point | Identify processes that are currently using a mount point |
umount dir | Unmount a mounted filesystem |
findmnt | Display mounted filesystems in a tree view |
fdisk -l | List disk partitions and partition details |
parted print | Show partition table information |
fsck dev | Check and repair a filesystem |
resize2fs dev | Resize an ext2/ext3/ext4 filesystem |
Swap Management
| Command | Description |
|---|---|
mkswap dev | Create a swap area on the specified block device |
swapon dev | Enable the specified swap device or partition |
swapoff dev | Disable the specified swap device or partition |
LVM (Logical Volume Management)
| Command | Description |
|---|---|
pvs |
List all physical volumes |
pvcreate dev |
Initialize a block device as a physical volume |
pvdisplay |
Show detailed information about physical volumes |
vgs |
List all volume groups |
vgcreate vg pv |
Create a new volume group using a physical volume |
vgextend vg pv |
Add a physical volume to an existing volume group |
vgreduce vg pv |
Remove a physical volume from a volume group |
vgdisplay |
Display detailed information about volume groups |
lvs |
List all logical volumes |
lvcreate -L -n lv vg |
Create a logical volume with specified size and name |
lvextend -l +100%FREE /dev/vg01/lv01 |
Extend the logical volume using all remaining free space in the volume group |
lvextend -L 10G /dev/vg01/lv01 |
Resize the logical volume to a total size of 10 GiB |
lvextend -l +128 /dev/vg01/lv01 |
Increase the logical volume by 128 physical extents |
resize2fs /dev/vg01/lv01 |
Resize an ext4 filesystem to match the logical volume size |
xfs_growfs /mount/point |
Expand an XFS filesystem after extending the logical volume |
lvreduce -L 5G /dev/vg01/lv01 |
Reduce the logical volume size to 5 GiB (filesystem must be resized first) |
lvreduce -L -2G /dev/vg01/lv01 |
Shrink the logical volume by 2 GiB |
lvdisplay |
Show detailed information about logical volumes |
lvremove lv |
Delete a logical volume |
Firewalld
| Command | Description |
|---|---|
firewall-cmd --get-default-zone |
Display the default firewall zone |
firewall-cmd --get-active-zones |
Show all currently active firewall zones |
firewall-cmd --add-service=http |
Allow an HTTP service temporarily until reboot |
firewall-cmd --add-port=80/tcp |
Open TCP port 80 temporarily in the active zone |
firewall-cmd --permanent --add-port=80/tcp |
Open TCP port 80 permanently across reboots |
firewall-cmd --runtime-to-permanent |
Save current runtime firewall rules permanently |
firewall-cmd --reload |
Reload firewall rules without interrupting connections |
firewall-cmd --zone=public --list-all |
Display full configuration of the public firewall zone |
SELinux
| Command | Description |
|---|---|
getenforce |
Display the current SELinux mode (Enforcing, Permissive, or Disabled) |
setenforce 0 |
Switch SELinux to permissive mode temporarily |
setenforce 1 |
Enable SELinux enforcing mode immediately |
semanage port -l |
List all ports and their associated SELinux types |
semanage fcontext -l |
Display SELinux file context rules |
restorecon -Rv /path |
Restore default SELinux security labels recursively |
systemd, Logs & Boot
| Command | Description |
|---|---|
systemctl status svc |
Check the current status of a system service |
systemctl start svc |
Start a system service immediately |
systemctl stop svc |
Stop a running system service |
systemctl restart svc |
Restart a system service |
systemctl enable svc |
Enable a service to start automatically at boot |
systemctl disable svc |
Disable a service from starting at boot |
systemctl is-enabled svc |
Check whether a service is enabled at boot |
systemctl list-units --type=service |
List all active system services |
systemctl get-default |
Show the default system boot target |
systemctl set-default target |
Set the default boot target |
loginctl list-users |
List users currently logged into the system |
loginctl session-status |
Display detailed information about user sessions |
systemd Journal (journalctl)
| Command | Description |
|---|---|
journalctl |
Display the complete systemd journal containing all available logs |
journalctl -n |
Show the most recent log entries using the default count |
journalctl -n 5 |
Display only the last five log entries |
journalctl -f |
Follow journal logs in real time, similar to tail -f |
journalctl -p err |
Show log messages with error priority and higher |
journalctl -xe |
View recent critical logs with detailed explanations |
journalctl -u svc |
View logs related to a specific service |
journalctl --since today |
Show logs generated since the beginning of today |
journalctl --since "YYYY-MM-DD HH:MM:SS" |
Display logs starting from a specific date and time |
journalctl --until "YYYY-MM-DD HH:MM:SS" |
Display logs up to a specific date and time |
journalctl --since "-1 hour" |
Show logs generated within the last one hour |
journalctl -o verbose |
Display logs with detailed metadata and fields |
journalctl _COMM=sshd |
Filter logs by command or process name |
journalctl _EXE=/usr/sbin/sshd |
Filter logs by full executable path |
journalctl _PID=1182 |
Show logs generated by a specific process ID |
journalctl _UID=0 |
Show logs generated by a specific user ID |
journalctl _SYSTEMD_UNIT=sshd.service |
Display logs for a specific systemd service |
journalctl _SYSTEMD_UNIT=sshd.service _PID=1182 |
Combine multiple filters for precise log searching |
journalctl -p debug |
Show debug-level log messages and above |
journalctl -p info |
Show informational log messages and above |
journalctl -p notice |
Show normal but significant log messages |
journalctl -p warning |
Show warning-level log messages |
journalctl -p crit |
Show critical condition log messages |
journalctl -p alert |
Show alert-level logs requiring immediate attention |
journalctl -p emerg |
Show emergency-level logs when the system is unusable |
/run/log/journal |
Default volatile journal storage location on RHEL 8 (cleared on reboot) |
Debugging & Tracing
| Command | Description |
|---|---|
strace cmd | Trace system calls made by a command |
strace -p PID | Attach strace to an already running process |
strace -f cmd | Trace system calls of child processes as well |
strace -c cmd | Display a summary of system call usage |
strace -o file cmd | Save system call trace output to a file |
lsof | List all open files and associated processes |
lsof -i | Show open network connections |
lsof -i :80 | Display processes using TCP or UDP port 80 |
lsof -u user | List files opened by a specific user |
lsof +D /path | Show open files under a given directory |
time cmd | Measure the execution time of a command |
/usr/bin/time -v cmd | Display detailed resource usage statistics |
perf stat cmd | Show performance counter statistics for a command |
perf top | Display real-time CPU performance profiling |
perf record cmd | Record performance data for later analysis |
perf report | Analyze and display recorded performance data |
Containers (Podman)
| Command | Description |
|---|---|
podman pull image | Download a container image from a registry |
podman images | List all container images stored locally |
podman run | Create and run a new container from an image |
podman ps -a | List all containers, including stopped ones |
podman stop ctr | Stop a running container gracefully |
podman rm ctr | Remove a stopped container |
podman logs ctr | View logs generated by a container |
podman exec -it ctr bash | Open an interactive shell inside a running container |
podman inspect ctr | Display detailed configuration and status information |
podman generate systemd | Generate a systemd service unit for a container |
Shell, Bash & Environment
| Command | Description |
|---|---|
echo text |
Print text or variables to standard output |
env |
Display all current environment variables |
export VAR=value |
Set and export an environment variable |
unset VAR |
Remove an environment variable |
alias ll='ls -l' |
Create a shell alias for a command |
source file |
Execute a script in the current shell session |
bash script.sh |
Run a Bash script in a new shell process |
read var |
Read user input and store it in a variable |
history |
Display previously executed commands |
history | grep cmd |
Search command history for a specific command |
!! |
Repeat the most recently executed command |
!$ |
Reuse the last argument from the previous command |
set -x |
Enable shell debug mode to trace command execution |
set +x |
Disable shell debug mode |
exit |
Exit the current shell session |
I/O Redirection
| Command | Description |
|---|---|
cmd > file | Redirect standard output to a file, overwriting existing content |
cmd >> file | Append standard output to the end of a file |
cmd 2> file | Redirect standard error output to a file |
cmd &> file | Redirect both standard output and standard error to a file |
Linux (Bash) Keyboard Shortcuts
| Shortcut | Description |
|---|---|
Ctrl + A | Move cursor to beginning of the line |
Ctrl + E | Move cursor to end of the line |
Ctrl + B | Move cursor back one character |
Ctrl + F | Move cursor forward one character |
Alt + B | Move cursor back one word |
Alt + F | Move cursor forward one word |
Ctrl + U | Delete from cursor to start of the line |
Ctrl + K | Delete from cursor to end of the line |
Ctrl + W | Delete the word before the cursor |
Ctrl + Y | Paste the last deleted text |
Ctrl + L | Clear the terminal screen |
Ctrl + C | Terminate the currently running command |
Ctrl + R | Search command history in reverse |
Ctrl + G | Exit history search mode |
Ctrl + P | Show the previous command |
Ctrl + N | Show the next command |
VI / VIM – Essential Command
| Command | Description |
|---|---|
i | Insert text before the cursor |
a | Insert text after the cursor |
A | Insert text at the end of the line |
o | Insert a new line below the current line |
Esc | Return to normal mode |
R | Enter replace mode (overwrite text) |
r<char> | Replace a single character |
[N]r<char> | Replace N characters |
s | Replace character and enter insert mode |
[N]s | Replace N characters and enter insert mode |
/pattern | Search forward for pattern |
x | Delete the character under the cursor |
[N]x | Delete N characters |
dd | Delete the current line |
[N]dd | Delete N lines |
D | Delete from cursor to end of the line |
dw | Delete the next word |
[N]dw | Delete the next N words |
cw | Change (replace) the current word |
[N]cw | Change the next N words |
S | Delete the current line and enter insert mode |
[N]S | Delete N lines and enter insert mode |
C | Change text from cursor to end of the line |
yy | Yank (copy) the current line |
[N]yy | Yank N lines |
p | Paste text below the cursor |
P | Paste text above the cursor |
u | Undo the last change |
[N]u | Undo the last N changes |
Ctrl + R | Redo the last undone change |
[N]Ctrl + R | Redo N changes |
U | Restore the current line to its original state |
v | Enter visual mode to select text |
y | Yank (copy) selected text |
d | Delete selected text |
~ | Toggle case of the character |
[N]~ | Toggle case for N characters |
:w | Save the file |
:q | Quit Vim |
:q! | Quit without saving changes |
:wq | Save the file and quit |
:x | Save and quit (same as :wq) |
:set nu | Show line numbers |
:set nonu | Hide line numbers |
:%s/old/new/g | Replace all occurrences of a word in the file |
:N | Go to line number N |
Stratis Storage Management
| Command | Description |
|---|---|
yum install stratis-cli stratisd |
Install Stratis management tools and the Stratis daemon |
systemctl enable --now stratisd |
Enable and start the Stratis daemon immediately and at boot |
stratis pool create pool1 /dev/vdb |
Create a new Stratis storage pool using a block device |
stratis pool add-data pool1 /dev/vdc |
Add an additional block device to an existing Stratis pool |
stratis pool list |
Display all configured Stratis storage pools |
stratis filesystem create pool1 fs1 |
Create a filesystem inside a Stratis storage pool |
stratis filesystem list |
List all Stratis filesystems |
stratis filesystem snapshot pool1 fs1 snap1 |
Create a snapshot of an existing Stratis filesystem |
lsblk --output=UUID /stratis/pool1/fs1 |
Display the UUID of a Stratis filesystem |
VDO (Virtual Data Optimizer)
| Command | Description |
|---|---|
yum install vdo kmod-kvdo |
Install VDO software and the required kernel module |
vdo create --name=vdo1 --device=/dev/vdd --vdoLogicalSize=50G |
Create a VDO volume with a logical size larger than the physical device |
vdo status --name=vdo1 |
Display the current status of a VDO volume |
vdo list |
List all configured VDO volumes |
vdo start --name=vdo1 |
Start a VDO volume |
vdo stop --name=vdo1 |
Stop a VDO volume |
vdostats --verbose |
Show detailed VDO space usage, compression, and deduplication savings |
autofs (Automatic Mounting)
| Command / Configuration | Description |
|---|---|
/shares /etc/auto.demo |
Indirect map that dynamically creates directories under /shares |
/- /etc/auto.direct |
Direct map defining absolute mount points |
* -rw server:/path/& |
Wildcard map for dynamically mounting multiple directories |
Power & System Control
| Command | Description |
|---|---|
shutdown -h now | Shut down the system immediately and power it off |
reboot | Reboot the system immediately |
poweroff | Power off the machine safely |
0
0
votes
Article Rating
0 Comments
Oldest
Newest
Most Voted
Inline Feedbacks
View all comments
