There are many easy-to-use commands for disk management in Linux. I will add them in different batches. First will come the most commonly used commands that you need to know enough to get a tattoo if needed.

Most Commonly Used Basic Disk Commands

Df Command

The df command shows the usage status of the file systems on the system. The most commonly used parameters to use this command are:

-h: This parameter displays data in a readable way. For example, units such as MB and GB are used.

-T: This parameter displays the types of file systems. For example like ext4, ntfs or xfs.

-x: Does not show the filesystems specified with this parameter.

--total: This parameter displays the total usage of all file systems.

As an example, the command df -hT --total shows the types and use cases of all filesystems in a readable way and also adds the total usage of all filesystems.

Using the df -h | grep ^/dev command, you can see the devices connected to the /dev folder and your partitions.

The command df -h --output=source,fstype,size,used,avail,pcent,target -x tmpfs -x devtmpfs shows the use cases of filesystems written to disk. This command shows the following information:

  • source: The source device of the file system. For example, like /dev/sda1.
  • fstype: The type of the file system. For example, like ext4.
  • size: The total size of the file system.
  • used: The space used in the file system.
  • avail: Space available on the filesystem.
  • pcent: The percentage of space used on the file system.
  • target: The directory where the filesystem is mounted.

This command does not show filesystems created in RAM memory such as tmpfs and devtmpfs (?).

Du Command 

The du command displays the amount of space used up by a directory and its subdirectories. The following are the most typically used parameters for this command:

-h: This parameter displays data in a readable way. For example, units such as MB and GB are used.

-s: This parameter shows the space occupied by the specified directory and does not show its subdirectories.

-c: This parameter displays the total space occupied by all directories.

 For example, the du -hsc /mnt command shows the space occupied by the /mnt directory and the total space occupied by its subdirectories. It feels great to bellow Du Hast Miş Gefrağt with Rammstein while trying this command.

Fdisk Command

The fdisk command is used to create, delete, and change disk partitions. It alters the partition table of the disk while doing these operations, and these modifications are applied upon system restart.

You can view all the disks running on the system with the fdisk -l command.

To use the fdisk command, you can start a process by giving the filename of a disk. For example, the fdisk /dev/sda command starts waiting for an input from you for the /dev/sda disk. You can then do whatever you want using one of the following fdisk commands:

p: Shows available partitions.
n: Creates a new partition.
d: Deletes a partition.
t: Changes the type of a partition.
w: Writes changes to disk.

Here are some points to consider when using the fdisk command:

You cannot completely erase the disk or reset the size of its partitions using the fdisk command. Other tools such as gparted can be used to perform these operations.

You should be careful when changing disk partitions using the fdisk command, as these operations are irreversible. In particular, it is important not to delete or modify the boot partition of the disk, as the boot partition is used during system startup and may affect system startup.

Using fdisk is not easy. You must be very careful. I recommend you to use cfdisk, which is interactive and simpler to use on the terminal, for disk creation and deletion.

Blkid Command

The blkid command is a Linux command that lists the UUID (universally unique identifier) (?) and types of partitions in the system. For example, it shows all the floppy disks (such as disks, USB sticks) in the system and what type of file system these floppy disks are partitioned.

An example of output can be given as follows:

/dev/sda1: UUID="48c3-1234" TYPE="vfat"
/dev/sda2: UUID="b9a7-56e3" TYPE="ext4"
/dev/sda3: UUID="c7a2-f8b9" TYPE="swap"

In this output, the /dev/sda1 partition is split with the vfat file system and its UUID is specified as "48c3-1234". Similarly, /dev/sda2 partition is partitioned with ext4 file system and its UUID is specified as "b9a7-56e3".

The output of the blkid command can be used to detect which file system the partitions on the system are partitioned with and to learn the UUID of these partitions. You can also change the UUID of a partition on the system with the blkid command.

Other Disk Commands

Let's speed up a little. Since you can see the details with the -h or --help parameters, let's quickly look at the definitions of other frequently used commands;

mount: This command is used to mount a disk to the system. For example, the mount /dev/sda1 /mnt command mounts the /dev/sda1 partition to /mnt.

umount: This command is used to unmount a disk from the system. For example, the umount /dev/sda1 command unmounts the /dev/sda1 partition.

mkfs: This command is used to format a disk as a file system. For example, the mkfs.ext4 /dev/sda1 command formats the /dev/sda1 partition with the ext4 file system.

lsblk: This command shows the list of block devices (disks) available in the system.

hdparm: This command is used to show and change the performance and other properties of a disk.

smartctl: This command returns a disk to S.M.A.R.T. It is used to display and test (Self-Monitoring, Analysis and Reporting Technology) data. S.M.A.R.T. is a technology used to predict the life of a disk and detect potential failures.

gparted: This is a graphical tool and is used for partitioning disks, redoing partitions, creating file systems, and other disk management operations.

fstab: This file specifies which devices will be automatically mounted on the system. By editing the /etc/fstab file, you can specify the devices you want to be mounted automatically at system boot.

parted: This command is used to partition a disk and edit existing partitions. This command is an alternative to the fdisk command and provides more advanced options.

sysfs: This file system holds the information of devices present in the system. For example, under the /sys/block directory you can find the information of the disk.

mdadm: This command is used to manage RAID (Redundant Array of Independent Disks) systems. RAID is a data protection system consisting of several disks and prevents data loss by duplicating data between disks.

pvcreate, vgcreate, lvcreate: These commands are used to install LVM (Logical Volume Manager) systems. LVM converts one or more physical disks to one or more logical disks, making it easier to move and partition data between disks.

badblocks: This command scans a disk for bad areas and returns a list of badblocks found. This command can be used to predict the life of the disk and detect potential errors.

fsck: This command scans a filesystem and fixes bad files. It runs automatically at system startup and is used to ensure that the file systems on the system are healthy.

resize2fs: This command resizes an ext2, ext3, or ext4 filesystem. For example, the command resize2fs /dev/sda1 100G resizes the partition /dev/sda1 to 100GB.