Linux Disk Management Commands Overview
fdisk: Used for creating, deleting, and modifying disk partitions.mkfs: Used for creating file systems.mount: Used for mounting file systems.umount: Used for unmounting file systems.df: Used to view disk usage.du: Used to view the disk usage of files or directories.parted: Used for creating, deleting, and modifying disk partitions (supports GPT partition tables).lsblk: Used to list all block devices on the system.blkid: Used to display information such as UUID and file system type for block devices.hdparm: Used to view and set hard drive parameters.smartctl: Used to view SMART information for hard drives.badblocks: Used to check for bad blocks on a disk.dd: Used for data backup and disk cloning.gparted: A graphical disk partitioning tool.LVM (Logical Volume Management): Provides logical volume management functions, such as creating, deleting, and extending logical volumes.
Detailed Introduction
Common disk management commands in Linux:
fdisk- Introduction:
fdiskis a disk partitioning tool used for creating, deleting, and modifying disk partitions. It is primarily used to manage the MBR partition table. - Syntax:
fdisk [options] <device>- Common Options:
-l: List disk partition information-u: Use sectors as the unit of measurement
- Common Options:
- Examples:
fdisk /dev/sda: Enter the interactive partitioning interface for the/dev/sdadiskfdisk -l: List partition information for all disks
- Introduction:
parted- Introduction:
partedis a more powerful disk partitioning tool that supports GPT partition tables. - Syntax:
parted [options] [device [command [options...]]]- Common Options:
-l: List disk partition information-s: Run in script mode
- Common Options:
- Examples:
parted /dev/sdb: Enter the interactive partitioning interface for the/dev/sdbdiskparted -l: List partition information for all disks
- Introduction:
mkfs- Introduction: The
mkfscommand is used to create file systems. - Syntax:
mkfs -t <type> [options] <device>- Common Options:
-t <type>: Specify the file system type, such as ext4, xfs, etc.
- Common Options:
- Examples:
mkfs -t ext4 /dev/sda1: Create an ext4 file system on the/dev/sda1partition
- Introduction: The
mount- Introduction: The
mountcommand is used to mount file systems. - Syntax:
mount [-t <type>] [-o options] <device> <dir>- Common Options:
-t <type>: Specify the file system type-o <options>: Specify mount options
- Common Options:
- Examples:
mount /dev/sda1 /mnt: Mount the/dev/sda1partition to the/mntdirectorymount -t ext4 /dev/sda1 /mnt: Mount the ext4 file system to the/mntdirectory
- Introduction: The
umount- Introduction: The
umountcommand is used to unmount file systems. - Syntax:
umount <device>orumount <mount_point> - Examples:
umount /dev/sda1umount /mnt
- Introduction: The
df- Introduction: The
dfcommand is used to view disk usage. - Syntax:
df [options] [file|directory]- Common Options:
-h: Display disk capacity and usage in a human-readable format-i: Display inode usage
- Common Options:
- Examples:
df -h: Display available space for all mounted file systemsdf -h /home: Display available space for the file system containing the/homedirectory
- Introduction: The
du- Introduction: The
ducommand is used to view the disk usage of files or directories. - Syntax:
du [options] [file|directory]- Common Options:
-h: Display disk space in a human-readable format-s: Show only the total
- Common Options:
- Examples:
du -h /home: Display the disk space occupied by the/homedirectory and its subdirectoriesdu -sh /home: Display only the total disk space occupied by the/homedirectory itself
- Introduction: The
dd- Introduction: The
ddcommand is used for data backup and disk cloning. - Syntax:
dd [options] [input_file=input] [output_file=output]- Common Options:
if=<file>: Specify the input fileof=<file>: Specify the output filebs=<bytes>: Specify the input/output block sizecount=<blocks>: Copy only a specified number of blocks
- Common Options:
- Examples:
dd if=/dev/sda of=/dev/sdb: Completely clone the data from the/dev/sdadisk to the/dev/sdbdiskdd if=/dev/zero of=/swapfile bs=1M count=2048: Create a 2GB swap file in the current directory
- Introduction: The