Disks & Filesystems: Complete Cheat Sheet
A comprehensive developer cheatsheet covering Linux storage and filesystem management, featuring essential CLI commands and operational workflows for disk partitioning (fdisk, gdisk, parted), filesystem creation (mkfs), monitoring space utilization (df, du, lsblk), managing mounts (mount, /etc/fstab), executing filesystem repairs (fsck), and handling swap space and file archiving.
Understanding Linux Storage
Filesystem Types
| Type | Description | Use Case |
|---|---|---|
ext4 | Fourth Extended Filesystem | Default for most Linux distros |
xfs | High-performance 64-bit journaling | Enterprise, large filesystems |
btrfs | B-tree Filesystem | Advanced features (snapshots, checksums) |
vfat | FAT32 | USB drives, compatibility with Windows |
ntfs | New Technology Filesystem | Windows drives (read/write with ntfs-3g) |
tmpfs | Temporary filesystem in RAM | /tmp, /run |
swap | Swap space | Virtual memory |
Device Naming Conventions
| Device Type | Name Format | Example |
|---|---|---|
| SATA/SAS/SCSI | /dev/sdX | /dev/sda, /dev/sdb |
| NVMe | /dev/nvmeXnY | /dev/nvme0n1, /dev/nvme1n2 |
| IDE | /dev/hdX | /dev/hda, /dev/hdb |
| Virtual (KVM) | /dev/vdX | /dev/vda, /dev/vdb |
| CD/DVD | /dev/srX | /dev/sr0, /dev/sr1 |
| Loop Device | /dev/loopX | /dev/loop0, /dev/loop1 |
Partition Table Types
| Type | Description | Max Size | Max Partitions |
|---|---|---|---|
| MBR | Master Boot Record | 2 TB | 4 primary (or 3 primary + 1 extended) |
| GPT | GUID Partition Table | 9.4 ZB | 128 (or more) |
Disk Space Monitoring
df — Display Disk Space Usage
Flags: -h (human-readable), -H (SI units), -T (show filesystem type), -i (inode usage), -x (exclude), --total (show total)
$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 50G 25G 23G 52% /
/dev/sdb1 500G 200G 300G 40% /home
tmpfs 7.8G 1.2M 7.8G 1% /tmpShows disk space usage for all mounted filesystems.
-hmakes it human-readable.
$ df -T
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda1 ext4 50G 25G 23G 52% /
/dev/sdb1 xfs 500G 200G 300G 40% /home
tmpfs tmpfs 7.8G 1.2M 7.8G 1% /tmp
-Tshows the filesystem type for each mounted device.
$ df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda1 3276800 234567 3042233 8% /
/dev/sdb1 26843545 123456 26720089 1% /home
tmpfs 2048000 123 2047877 1% /tmp
-ishows inode usage — important when you have many small files.
Inode Usage Alert: If inodes are 100% used, you can't create new files even if you have free space.
du — Estimate File/Directory Space Usage
Flags: -h (human), -s (summary), -a (all files), -c (grand total), -d N (max depth N), --exclude=PATTERN
$ du -sh /home/bob
456M /home/bobShows total size of a directory.
-s= summary,-h= human-readable.
$ du -sh /var/* | sort -hr | head -5
2.3G /var/log
1.2G /var/cache
456M /var/lib
123M /var/www
45M /var/tmpFind the largest directories in
/varsorted by size.
$ du -h --max-depth=1 /home
4.5G /home/alice
2.3G /home/bob
1.2G /home/charlie
8.0G /home
--max-depth=1shows sizes of immediate subdirectories only.
$ du -ah /home/bob | sort -hr | head -10
456M /home/bob
123M /home/bob/Videos
89M /home/bob/Downloads
45M /home/bob/Documents
-aincludes files, not just directories. Great for finding large files.
lsblk — List Block Devices
Flags: -f (show filesystems), -m (human-readable), -t (topology), -p (full path), -o (custom output)
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 100G 0 disk
├─sda1 8:1 0 50G 0 part /
├─sda2 8:2 0 2G 0 part [SWAP]
└─sda3 8:3 0 48G 0 part /home
sdb 8:16 0 500G 0 disk
└─sdb1 8:17 0 500G 0 part /backup
nvme0n1 259:0 0 250G 0 disk
└─nvme0n1p1 259:1 0 250G 0 part /dataShows all block devices in a tree structure. Easy to understand disk layout.
$ lsblk -f
NAME FSTYPE LABEL UUID MOUNTPOINT
sda
├─sda1 ext4 rootfs 12345678-1234-1234-1234-123456789012 /
├─sda2 swap swap abcd1234-abcd-1234-abcd-123456789012 [SWAP]
└─sda3 ext4 home 98765432-9876-9876-9876-987654321098 /home
sdb
└─sdb1 xfs backup 56789012-5678-5678-5678-567890123456 /backup
-fshows filesystem type, label, and UUID for each partition.
$ lsblk -o NAME,SIZE,TYPE,MOUNTPOINT,LABEL
NAME SIZE TYPE MOUNTPOINT LABEL
sda 100G disk
├─sda1 50G part / rootfs
├─sda2 2G part [SWAP] swap
└─sda3 48G part /home homeCustom output format — show only the columns you need.
blkid — Locate/Print Block Device Attributes
Flags: -s (show specific attribute), -o (output format), -p (probe)
$ blkid
/dev/sda1: UUID="12345678-1234-1234-1234-123456789012" TYPE="ext4" PARTUUID="abcd-1234"
/dev/sda2: UUID="abcd1234-abcd-1234-abcd-123456789012" TYPE="swap" PARTUUID="efgh-5678"
/dev/sda3: UUID="98765432-9876-9876-9876-987654321098" TYPE="ext4" PARTUUID="ijkl-9012"
/dev/sdb1: UUID="56789012-5678-5678-5678-567890123456" TYPE="xfs" PARTUUID="mnop-3456"Shows UUIDs and filesystem types for all block devices.
$ blkid -s UUID -o list
device uuid type
/dev/sda1 12345678-1234-1234-1234-123456789012 ext4
/dev/sda2 abcd1234-abcd-1234-abcd-123456789012 swap
/dev/sda3 98765432-9876-9876-9876-987654321098 ext4
/dev/sdb1 56789012-5678-5678-5678-567890123456 xfs
-s UUID -o listshows just UUIDs in a clean table.
Disk Partitioning
fdisk — Partition Table Manipulator (MBR & GPT)
Flags: -l (list partitions), /dev/sda (target disk)
Interactive Commands:
| Key | Action |
|---|---|
n | New partition |
d | Delete partition |
p | Print partition table |
w | Write changes and exit |
q | Quit without saving |
t | Change partition type |
$ fdisk -l /dev/sda
Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 sectors
Disk model: VBOX HARDDISK
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 12345678-1234-1234-1234-123456789012
Device Start End Sectors Size Type
/dev/sda1 2048 104857600 104855552 50G Linux filesystem
/dev/sda2 104857600 109051904 4194304 2G Linux swap
/dev/sda3 109051904 209715200 100663296 48G Linux filesystemLists all partitions on
/dev/sda.
Interactive Partitioning Session:
$ fdisk /dev/sdb
Command (m for help): p
Disk /dev/sdb: 500 GiB, 536870912000 bytes, 1048576000 sectors
...
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-1048575999, default 2048):
Last sector, +sectors or +size{K,M,G} (2048-1048575999, default 1048575999): +100G
Created a new partition 1 of type 'Linux' and of size 100 GiB.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.Creates a new 100GB partition on
/dev/sdb.
gdisk — GPT Partition Table Manipulator
Flags: -l (list partitions), /dev/sda (target disk)
Interactive Commands:
| Key | Action |
|---|---|
n | New partition |
d | Delete partition |
p | Print partition table |
w | Write changes and exit |
q | Quit without saving |
t | Change partition type |
$ gdisk -l /dev/nvme0n1
GPT fdisk (gdisk) version 1.0.9
Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: present
Found valid GPT with protective MBR; using GPT.
Disk /dev/nvme0n1: 488397168 sectors, 232.9 GiB
Sector size (logical): 512 bytes
Disk identifier (GUID): 12345678-1234-1234-1234-123456789012
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 488397134
Number Start (sector) End (sector) Size Code Name
1 2048 488397134 232.9 GiB 8300 Linux filesystem
gdiskis the modern tool for GPT disks (supports >2TB drives).
$ gdisk /dev/nvme0n1
Command (? for help): n
Partition number (1-128, default 1): 2
First sector (34-488397134, default = 2048) or {+-}size{KMGTP}:
Last sector (2048-488397134, default = 488397134) or {+-}size{KMGTP}: +50G
Current type is 8300 (Linux filesystem)
Hex code or GUID (L to show codes, Enter = 8300): 8300
Changed type of partition to 'Linux filesystem'
Command (? for help): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/nvme0n1.
The operation has completed successfully.Creates a new 50GB partition on an NVMe SSD.
parted — Command-line Partition Editor
Flags: mklabel (create partition table), mkpart (create partition), print, resizepart, rm
$ parted /dev/sdb print
Model: VBOX HARDDISK (scsi)
Disk /dev/sdb: 500GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 107GB 107GB ext4 primary
2 107GB 109GB 2147MB primary swapShows partition layout with sizes in human-readable format.
$ parted /dev/sdb mklabel gpt
(No output — creates a new GPT partition table)Creates a new GPT label (erases all existing partitions).
$ parted /dev/sdb mkpart primary ext4 1MiB 100GiB
(No output — creates a 100GB ext4 partition)Creates a new partition of type
primarywith ext4 filesystem.
$ parted /dev/sdb resizepart 1 200GiB
(Resizes partition 1 to 200GB — requires that the partition is not mounted)Resizes an existing partition (must be unmounted).
$ parted /dev/sdb rm 2
(Removes partition 2)Filesystem Creation
mkfs — Build a Filesystem
Common Filesystem Creation:
$ mkfs.ext4 /dev/sda1
mke2fs 1.46.5 (30-Dec-2021)
Creating filesystem with 13107200 4k blocks and 3276800 inodes
Filesystem UUID: 12345678-1234-1234-1234-123456789012
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: doneFormats
/dev/sda1as ext4 filesystem.
$ mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1 isize=512 agcount=4, agsize=6553600 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1 bigtime=0
data = bsize=4096 blocks=26214400, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=12800, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0Formats
/dev/sdb1as XFS filesystem.
$ mkfs.vfat /dev/sdc1
mkfs.fat 4.2 (2021-01-31)Formats
/dev/sdc1as FAT32 (vfat) — good for USB drives.
$ mkfs -t ext4 -L "DATA" /dev/sda3
-tspecifies filesystem type,-Lsets a label.
mkswap — Set Up a Swap Space
$ mkswap /dev/sda2
Setting up swapspace version 1, size = 2 GiB (2147479552 bytes)
no label, UUID=abcd1234-abcd-1234-abcd-123456789012Prepares a partition to be used as swap space.
$ mkswap -L SWAP /dev/sda2
-Lsets a label for the swap partition.
Mounting & Unmounting
mount — Mount a Filesystem
Flags: -t (type), -o (options), -a (mount all in /etc/fstab), -r (read-only)
$ mount /dev/sdb1 /mnt/backup
(No output — mounts /dev/sdb1 to /mnt/backup)Mounts a filesystem to a directory.
$ mount -t ext4 /dev/sda1 /mnt/data
-tspecifies the filesystem type (auto-detected if omitted).
$ mount -o ro /dev/sdb1 /mnt/readonly
(Mounts as read-only — prevents accidental writes)
-o romounts read-only. Useful for recovery or security.
Common Mount Options:
| Option | Meaning |
|---|---|
rw | Read-write (default) |
ro | Read-only |
noexec | Prevent execution of binaries |
nosuid | Ignore setuid bits |
nodev | Ignore device files |
remount | Remount with new options |
$ mount -o remount,rw /mnt/data
(Remounts /mnt/data as read-write without unmounting)
remountchanges mount options for an already mounted filesystem.
$ mount -a
(No output — mounts all filesystems defined in /etc/fstab)
-amounts all filesystems listed in/etc/fstab.
$ mount -o rw,noexec /dev/sdb1 /mnt/data
(Mounts with no execution allowed — good for /tmp or data directories)umount — Unmount a Filesystem
Flags: -l (lazy), -f (force), -a (unmount all)
$ umount /mnt/backup
(No output — unmounts /mnt/backup)Unmounts a mounted filesystem.
$ umount /dev/sdb1
(Can unmount by device name as well)$ umount -l /mnt/backup
(No output — lazy unmount: detaches now, cleans up later)
-llazy unmount — useful when a filesystem is busy.
$ umount -f /mnt/backup
(Force unmount — use when normal unmount fails)mountpoint — Check if a Directory is a Mount Point
$ mountpoint /mnt/data
/mnt/data is a mountpoint$ mountpoint /home
/home is not a mountpoint/etc/fstab — Filesystem Table
Format: <device> <mountpoint> <type> <options> <dump> <pass>
$ cat /etc/fstab
# <device> <mountpoint> <type> <options> <dump> <pass>
UUID=123456... / ext4 defaults,noatime 0 1
UUID=abcd12... /home ext4 defaults,noatime 0 2
UUID=efgh34... /boot ext4 defaults,noatime 0 1
UUID=ijkl56... swap swap defaults 0 0
/dev/sdb1 /backup xfs defaults,noatime 0 2
tmpfs /tmp tmpfs defaults,noexec,nosuid 0 0
/etc/fstabdefines how filesystems are mounted at boot.
Understanding fstab Fields:
| Field | Meaning |
|---|---|
| Device | UUID, LABEL, or device path |
| Mountpoint | Directory where it's mounted |
| Type | Filesystem type (ext4, xfs, swap, etc.) |
| Options | Mount options (defaults, noatime, etc.) |
| Dump | 0 = no backup, 1 = backup (for dump command) |
| Pass | 0 = skip check, 1 = root check, 2 = other check |
Filesystem Repair
fsck — Filesystem Consistency Check
Flags: -a (auto repair), -y (yes to all), -n (no to all), -f (force even if clean), -t (type)
** IMPORTANT:** The filesystem MUST BE UNMOUNTED before running fsck.
$ umount /dev/sda1
$ fsck /dev/sda1
fsck from util-linux 2.37.2
e2fsck 1.46.5 (30-Dec-2021)
/dev/sda1: clean, 123456/3276800 files, 2345678/13107200 blocksChecks and repairs a filesystem. Must be unmounted.
$ fsck -y /dev/sda1
e2fsck 1.46.5 (30-Dec-2021)
/dev/sda1 contains a file system with errors, check forced.
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/sda1: ***** FILE SYSTEM WAS MODIFIED *****
/dev/sda1: 123456/3276800 files (0.2% non-contiguous), 2345678/13107200 blocks
-yautomatically answers "yes" to all repair questions.
$ fsck -f /dev/sda1
(Forces check even if filesystem appears clean)$ fsck -n /dev/sda1
(Dry run — shows what would be fixed without making changes)tune2fs — Adjust Filesystem Parameters (ext2/ext3/ext4)
Flags: -l (list settings), -c (max mount count), -i (check interval), -m (reserved blocks)
$ tune2fs -l /dev/sda1 | head -15
tune2fs 1.46.5 (30-Dec-2021)
Filesystem volume name: rootfs
Last mounted on: /
Filesystem UUID: 12345678-1234-1234-1234-123456789012
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal ext_attr resize_inode dir_index
Filesystem flags: signed_directory_hash
Default mount options: user_xattr acl
Filesystem state: clean
Errors behavior: Continue
Filesystem OS type: Linux
Inode count: 3276800
Block count: 13107200
Reserved block count: 655360
Free blocks: 10754000
Free inodes: 3153344
First block: 0
Block size: 4096Shows detailed filesystem parameters.
$ tune2fs -c 30 /dev/sda1
tune2fs 1.46.5 (30-Dec-2021)
Setting maximal mount count to 30Forces a filesystem check every 30 mounts.
$ tune2fs -i 30d /dev/sda1
tune2fs 1.46.5 (30-Dec-2021)
Setting interval between checks to 30 daysForces a filesystem check every 30 days.
$ tune2fs -m 2 /dev/sda1
tune2fs 1.46.5 (30-Dec-2021)
Setting reserved blocks percentage to 2% (262144 blocks)Reserves 2% of blocks for root. Default is 5%.
xfs_repair — Repair XFS Filesystem
$ umount /dev/sdb1
$ xfs_repair /dev/sdb1
Phase 1 - find and verify superblock...
Phase 2 - using internal log
Phase 3 - for each AG...
Phase 4 - check for duplicate blocks...
Phase 5 - rebuild AG headers and trees...
Phase 6 - check inode connectivity...
Phase 7 - verify link counts...
No modifications to filesystemRepairs XFS filesystems. Must be unmounted.
$ xfs_repair -n /dev/sdb1
(Dry run — checks without making changes)Swap Management
swapon — Enable Swap
Flags: -s (show swap status), -a (enable all in /etc/fstab), --show (modern list)
$ swapon -s
Filename Type Size Used Priority
/dev/sda2 partition 2097148 234567 -2Shows current swap usage.
-sis deprecated — use--showinstead.
$ swapon --show
NAME TYPE SIZE USED PRIO
/dev/sda2 partition 2G 234M -2Modern way to show swap information.
$ swapon /dev/sda2
(No output — enables swap on /dev/sda2)$ swapon -a
(Enables all swap devices listed in /etc/fstab)swapoff — Disable Swap
$ swapoff /dev/sda2
(No output — disables swap on /dev/sda2)$ swapoff -a
(Disables all swap devices)Archiving & Compression
tar — Tape Archive (The Swiss Army Knife)
Common Flags:
| Flag | Meaning |
|---|---|
c | Create archive |
x | Extract archive |
t | List contents |
z | gzip compression |
j | bzip2 compression |
J | xz compression |
v | Verbose output |
f | File (must be last) |
p | Preserve permissions |
--exclude | Exclude patterns |
Create Archives:
$ tar -czvf archive.tar.gz /home/bob/Documents/
tar: Removing leading `/' from member names
/home/bob/Documents/
/home/bob/Documents/file1.txt
/home/bob/Documents/file2.pdf
/home/bob/Documents/subdir/Creates a compressed tarball with gzip (
-z).
$ tar -cjvf archive.tar.bz2 /home/bob/Documents/
(Similar but with bzip2 compression — slower but smaller)$ tar -cJvf archive.tar.xz /home/bob/Documents/
(xz compression — highest compression, slower)Extract Archives:
$ tar -xzvf archive.tar.gz
/home/bob/Documents/
/home/bob/Documents/file1.txt
/home/bob/Documents/file2.pdfExtracts a gzip-compressed tarball.
$ tar -xjvf archive.tar.bz2Extracts a bzip2-compressed tarball.
$ tar -xJvf archive.tar.xzList Archive Contents:
$ tar -tvf archive.tar.gz
drwxr-xr-x bob/staff 0 2026-01-15 10:30 home/bob/Documents/
-rw-r--r-- bob/staff 1234 2026-01-15 10:30 home/bob/Documents/file1.txt
-rw-r--r-- bob/staff 4567 2026-01-15 10:30 home/bob/Documents/file2.pdfExtract to Different Directory:
$ tar -xzvf archive.tar.gz -C /tmp/
(Extracts to /tmp/)Exclude Files:
$ tar -czvf backup.tar.gz /home/bob --exclude="*.tmp" --exclude=".cache"gzip — Compress Files
Flags: -d (decompress), -k (keep original), -v (verbose), -1 to -9 (compression level)
$ gzip -v file.txt
file.txt: 67.2% -- replaced with file.txt.gzCompresses a file (replaces original with .gz).
$ gzip -k file.txt
(Compresses but keeps the original file)$ gzip -d file.txt.gz
(Decompresses .gz file)Compression Levels:
$ gzip -1 file.txt # Fastest, least compression
$ gzip -6 file.txt # Default
$ gzip -9 file.txt # Slowest, best compressiongunzip — Decompress Files
$ gunzip -v file.txt.gz
file.txt.gz: 67.2% -- replaced with file.txtDecompresses .gz files.
$ gunzip -k file.txt.gz
(Decompresses but keeps the .gz file)zip — Create ZIP Archives (Windows Compatible)
Flags: -r (recursive), -d (delete from zip), -l (show contents), -u (update), -P (password)
$ zip -r archive.zip /home/bob/Documents/
adding: home/bob/Documents/ (stored 0%)
adding: home/bob/Documents/file1.txt (deflated 67%)
adding: home/bob/Documents/file2.pdf (deflated 45%)Creates a ZIP archive (compatible with Windows).
$ zip -r -P secret archive.zip /home/bob/secret/
(Adds password protection — use with caution!)$ zip -l archive.zip
Archive: archive.zip
Length Date Time Name
--------- ---------- ----- ----
0 2026-01-15 10:30 home/bob/Documents/
1234 2026-01-15 10:30 home/bob/Documents/file1.txt
4567 2026-01-15 10:30 home/bob/Documents/file2.pdf
--------- -------
5801 3 files
-llists contents without extracting.
unzip — Extract ZIP Archives
Flags: -l (list contents), -o (overwrite), -d (extract to directory), -n (never overwrite)
$ unzip -l archive.zip
Archive: archive.zip
Length Date Time Name
--------- ---------- ----- ----
0 2026-01-15 10:30 home/bob/Documents/
1234 2026-01-15 10:30 home/bob/Documents/file1.txt
4567 2026-01-15 10:30 home/bob/Documents/file2.pdf
--------- -------
5801 3 filesLists contents without extracting.
$ unzip archive.zip
(Extracts all files to current directory)$ unzip -d /tmp/ archive.zip
(Extracts to /tmp/)$ unzip -o archive.zip
(Overwrites existing files without prompting)Quick Reference — Most Used Commands
| Command | Description |
|---|---|
df -h | Show disk space usage (human-readable) |
df -i | Show inode usage |
du -sh /path | Show total size of a directory |
du -h --max-depth=1 | Show sizes of immediate subdirectories |
lsblk -f | List block devices with filesystem info |
blkid | Show UUIDs of all block devices |
fdisk -l /dev/sda | List partitions on /dev/sda |
parted /dev/sda print | Show partition layout (human-readable) |
mkfs.ext4 /dev/sda1 | Format partition as ext4 |
mount /dev/sda1 /mnt | Mount a filesystem |
umount /mnt | Unmount a filesystem |
fsck /dev/sda1 | Check and repair filesystem (must be unmounted) |
swapon --show | Show swap usage |
tar -czvf archive.tar.gz /path | Create compressed tarball |
tar -xzvf archive.tar.gz | Extract tarball |
gzip file | Compress file (replaces with .gz) |
gunzip file.gz | Decompress .gz file |
zip -r archive.zip /path | Create ZIP archive |
unzip archive.zip | Extract ZIP archive |
The Nuclear Commands — DO NOT TYPE
These commands will permanently destroy your data or system.
| Command | What it does |
|---|---|
dd if=/dev/zero of=/dev/sda | Wipes the entire disk (no recovery) |
dd if=/dev/urandom of=/dev/sda | Overwrites disk with random data (secure erase) |
mkfs.ext4 /dev/sda | Formats the whole disk (all partitions destroyed) |
rm -rf / | Deletes everything on the system |
fsck -y /dev/sda | Running fsck on a mounted filesystem (causes corruption) |
echo 1 > /proc/sys/kernel/panic | Forces kernel panic |
shred -f /dev/sda | Overwrites and deletes data irreversibly |
Keyboard Shortcuts
| Shortcut | Action |
|---|---|
Tab | Auto-complete file names and commands |
Ctrl+C | Cancel/kill the current running command |
Ctrl+D | Log out of the current terminal or exit a shell |
Ctrl+Z | Suspend the current command (put it in the background) |
!! | Re-run the last command (e.g., sudo !! re-runs with sudo) |
Ctrl+R | Reverse search through command history |
Additional Tips
-
The Man Pages: If you forget how a command works, type
man command(e.g.,man df). Pressqto exit the manual. -
Always Unmount Before
fsck: Runningfsckon a mounted filesystem can cause corruption. Always unmount first. -
Use UUIDs in
/etc/fstab: Device names (/dev/sda1) can change on reboot. UUIDs are persistent. Useblkidto find UUIDs. -
Inode Usage:
df -ishows inode usage. If inodes are 100% full, you cannot create new files even with free space. -
The 5% Reserved Space: By default, ext4 reserves 5% of space for root. For data drives, reduce this to 1-2% with
tune2fs -m 1. -
Mount Options for Security:
noexecon/tmpprevents executing malicious binariesnosuidon/homeprevents setuid exploitsnodevon/tmpprevents device file attacks
-
Check Disk Health: Use
smartctl -a /dev/sda(requiressmartmontools) to check disk health and predict failures. -
Extend Filesystem: To extend a partition and filesystem:
- Use
partedorgdiskto resize the partition - Use
resize2fs /dev/sda1(ext4) orxfs_growfs /mountpoint(XFS)
-
Find Large Files:
bashfind / -type f -size +1G -exec ls -lh {} \; 2>/dev/null -
Create a Swap File (instead of a partition):
bashdd if=/dev/zero of=/swapfile bs=1G count=4 chmod 600 /swapfile mkswap /swapfile swapon /swapfile echo "/swapfile none swap sw 0 0" >> /etc/fstab
