Linux Disk Management Commands Explained

Introduction

In Linux, managing disks and partitions is an important task for system administrators. Here we will learn about some useful commands: fdisk, mkfs, df, mount, e2fsck, stat, lsblk, and also about /etc/fstab file and Swap partition. These commands help us to check, create, and manage storage in Linux.

1. fdisk Command

  • fdisk is used to create, delete, or modify disk partitions.
  • Example: fdisk /dev/sda
  • With fdisk, you can check the partition table and create new partitions.

2. mkfs Command

  • mkfs means “make filesystem”.
  • After creating a partition, we need to format it with a filesystem like ext4, xfs, etc.
  • Example: mkfs.ext4 /dev/sda1

3. df Command

  • df means “disk free”.
  • It shows how much disk space is used and available.
  • Example: df -h (h means human-readable, like GB and MB)

4. mount Command

  • mount is used to attach a filesystem to a directory so we can access it.
  • Example: mount /dev/sda1 /mnt
  • After mounting, you can access files from /mnt directory.

5. e2fsck Command

  • e2fsck is used to check and repair ext2/ext3/ext4 filesystems.
  • It ensures that the filesystem is not corrupted.
  • Example: e2fsck /dev/sda1

6. stat Command

  • stat shows detailed information about a file.
  • Example: stat file.txt
  • It displays size, permissions, and last modified time of the file.

7. lsblk Command

  • lsblk means “list block devices”.
  • It shows all disks and partitions in a tree structure.
  • Example: lsblk

8. /etc/fstab File

  • The /etc/fstab file contains information about filesystems and their mount points.
  • It is used for automatic mounting during system boot.
  • Example line in fstab: /dev/sda1 /mnt ext4 defaults 0 0

9. Swap Partition

  • Swap space is like virtual memory used when RAM is full.
  • It can be a separate partition or a file.
  • Example to check swap: swapon --show

Conclusion

These commands are very important for Linux administrators and students. Practice them to understand how Linux handles disks and partitions.

Leave a Reply

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