1. Understanding File Systems

What is a File System?

A file system controls how data is stored and retrived. Without a file system, the OS wouldn’t know where a file starts or ends.

Common Linux File Systems

File SystemDescription
ext4Default for many Linux distros; journaling support
xfsHigh-performance; good for large files
btrfsCopy-on-write, snapshots, RAID built-in
vfatCompatible with Windows, for USB drives
ntfsWindows file system; needs special driver in Linux

2.Listing Disks and Paritions

This displays all disks and partitions in a tree-like format, showing relationships between devices and their mount points.

Command ExampleWhat it does
lsblkList all block devices (tree format)
lsblk -aInclude empty devices
lsblk -fShow filesystem info (type, label, UUID)
lsblk -bShow sizes in bytes
lsblk -lOutput as a list (not tree)
lsblk --output NAME,SIZE,TYPEShow only specific columns

Example Output:

iamyaash@fedora:~/ $ lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
zram0       251:0    0     8G  0 disk [SWAP]
nvme0n1     259:0    0 476.9G  0 disk 
├─nvme0n1p1 259:1    0   100M  0 part /boot/efi
├─nvme0n1p2 259:2    0    16M  0 part 
├─nvme0n1p3 259:3    0 174.7G  0 part 
├─nvme0n1p4 259:4    0     1G  0 part 
├─nvme0n1p5 259:5    0     1G  0 part /boot
└─nvme0n1p6 259:6    0 300.1G  0 part /home
                                      /

nvme0n1 is your disk and nvme0n1p1nvme0n1p6 are partitions of a single disk.

3. Checking Disk Usage

df (Disk Free)

The df (disk free) command is used to display information about the available and used disk space on all mounted filesystems.

Shows mounted file systems in human readable output and their usage:

df -h

Example Output:

iamyaash@fedora:~ $ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/nvme0n1p6  301G   38G  262G  13% /
devtmpfs        4.0M     0  4.0M   0% /dev
tmpfs           7.6G   32K  7.6G   1% /dev/shm
efivarfs        128K   46K   78K  38% /sys/firmware/efi/efivars
tmpfs           3.1G  2.2M  3.1G   1% /run
tmpfs           1.0M     0  1.0M   0% /run/credentials/systemd-journald.service
tmpfs           7.6G  2.9M  7.6G   1% /tmp
/dev/nvme0n1p6  301G   38G  262G  13% /home
/dev/nvme0n1p5  974M  474M  433M  53% /boot
/dev/nvme0n1p1   96M   47M   50M  49% /boot/efi
tmpfs           1.0M     0  1.0M   0% /run/credentials/systemd-resolved.service
tmpfs           1.6G  3.8M  1.5G   1% /run/user/1000

List of df Commands

Command ExampleWhat it does
dfShows disk space for all mounted filesystems
df -hHuman-readable output (KB, MB, GB)
df -ThHuman-readable with filesystem type
df /home/userFilesystem info for /home/user
df -iShows inode usage
df -x tmpfsExcludes tmpfs filesystems
df -Tt ext4Only shows ext4 filesystems
df --output=source,avail,pcentCustom columns (filesystem, available, use%)
df -aThAll filesystems, with type and human-readable

Note: The df command shows information about the filesystem’s available and used space, not the size or usage of individual files. If you use df filename.ext, it will display which filesystem contains the file and how much space is available on that filesystem, but it never shows properties or the actual size of the file itself.

du (Disk Usage)

The du (disk usage) command is a fundamental Linux tool for checking how much space files and directories occupy.

#top space-consuming directories
#folder-by-folder view
du -sh * 
# use .(dot), *(asterisk), (~)tilde... as exercise
#output
iamyaash@fedora:~$ du -sh *
4.0K    Desktop
208M    Documents
2.5G    Downloads
660M    Games
3.1G    go
238M    KDE Vaults
0       Music
134M    Pictures
4.4G    Projects
0       Public
4.0K    Scripts
0       Templates
0       Videos

List of du Commands

CommandWhat it does
duUsage of current directory
du /home/userUsage of /home/user
du -h /home/userUsage in human-readable format
du -sh /home/userTotal usage of /home/user
du -ah /home/userAll files/dirs (including hidden) in /home/user
du -c /home/userTotal for all listed directories
du -d 1 /home/userFirst-level subdirectories only
du --exclude="*.log" /home/userExclude .log files
du -BM directory_nameDisplays the size in megabytes(MB)
du -h file.txtShows the size of a single file
du -h /home/user | sort -hPipe to sort for sorted results

4. Mounting and Unmounting Drives

Mounting connects a storage device (like a hard drive partition) to a directory in Linux so you can access its contents.

Example:

sudo mount /dev/nvme0n1p6 /mnt

This makes /dev/nvme0n1p6 available at /mnt.
You can use any empty directory instead of /mnt.

Unmounting safely removes access:

sudo umount /mnt

Tip: Always unmount before removing the device!

5. Creating File Systems

To format a partition with a file system:

ext4:

sudo mkfs.ext4 /dev/nvme0n1p6

xfs:

sudo mkfs.xfs /dev/nvme0n1p6

Obviously, it’s gonna erase all the data on the partition.

6. Mount On Boot Using /etc/fstab

To mount partitions automatically at boot: /etc/fstab

The /etc/fstab file is a configuration file that tells your Linux system which partitions to mount automatically at boot, where to mount them, and with what options. Each line in the file describes one filesystem and its mounting details.

Format of an /etc/fstab Entry

Each line has six fields, separated by spaces or tabs:

<device> <mount point> <filesystem type> <options> <dump> <pass>
  • Device: The storage device (e.g., /dev/sda1, UUID=..., or LABEL=...)
  • Mount point: Directory where the device will be mounted (e.g., /mnt/data)
  • Filesystem type: Type of filesystem (e.g., ext4, ntfs, xfs)
  • Options: Mount options (e.g., defaults, ro, noatime)
  • Dump: Backup flag (use 0 if you don’t use the dump tool)
  • Pass: Filesystem check order (use 0 to disable, 1 for root, 2 for others)

Example Entry

Suppose you want to automatically mount an ext4 partition with UUID 1234-5678 to /mnt/data at boot. Add this line to /etc/fstab:

UUID=1234-5678 /mnt/data ext4 defaults 0 2

Note: Always use UUID or LABEL instead of /dev/sdXY to avoid issues if device names change. You can find the UUID of your partitions with lsblk -f or blkid.

7. Checking Disk Health

It needs smartmontools, which is installed on most of the Linux distros.

sudo smartctl -a /dev/nvme0n1p6

List of Commands

CommandPurpose
lsblkList block devices
df -hDisk space usage
mount/umountMount and unmount partitions
mkfs.ext4Format with ext4
lsblk -fShow FS type, UUID
blkidShow UUID and label
/etc/fstabPersistent mount config
du -sh *Directory sizes