Common Linux Disk Commands
Linux provides a wide range of commands for managing disks and file systems. Here are some of the most common and useful disk commands in Linux:
fdisk
The fdisk
command is used to create, delete, and modify disk partitions. It allows you to view the current partition table, create new partitions, change the size of existing partitions, and more. Here's an example of how to use fdisk
to view the partition table of a disk:
sudo fdisk -l /dev/sda
This will display the partition table for the /dev/sda
disk.
mkfs
The mkfs
command is used to create a file system on a disk or partition. It supports various file system types, such as ext4, XFS, and FAT. Here's an example of how to create an ext4 file system on a partition:
sudo mkfs.ext4 /dev/sda1
This will create an ext4 file system on the /dev/sda1
partition.
mount
The mount
command is used to mount a file system to a specific directory in the Linux file system hierarchy. This allows you to access the files and directories on the mounted file system. Here's an example of how to mount an ext4 file system to the /mnt
directory:
sudo mount /dev/sda1 /mnt
This will mount the /dev/sda1
partition to the /mnt
directory.
umount
The umount
command is used to unmount a file system that has been previously mounted. This is important to do before removing or modifying a disk or partition. Here's an example of how to unmount the /mnt
directory:
sudo umount /mnt
This will unmount the file system that was previously mounted to the /mnt
directory.
df
The df
command is used to display information about the file system, including the total size, used space, and available space. Here's an example of how to use df
to view the file system information:
df -h
This will display the file system information in a human-readable format.
du
The du
command is used to display the disk usage of a directory or file. It can be used to identify which files or directories are taking up the most space on a disk. Here's an example of how to use du
to view the disk usage of a directory:
du -h /var/log
This will display the disk usage of the /var/log
directory in a human-readable format.
These are just a few of the many disk commands available in Linux. By understanding and using these commands, you can effectively manage and maintain your Linux file systems and disks.