Linux Disk Management Commands
Overview
Linux provides various commands for managing disks and filesystems. These commands allow you to view disk usage, partition disks, format filesystems, and more. This document covers basic and commonly used disk management commands.
Disk Usage and Information
df
Displays information about disk space usage on filesystems.
Example
du
Displays disk usage for files and directories.
Example
du -sh /home/user
# Output: Shows the total disk usage of the directory '/home/user' in human-readable format
lsblk
Lists information about all available block devices.
Example
fdisk
Partition table manipulator for creating, deleting, and managing disk partitions.
Example
Common fdisk
Commands
- List partitions:
p
- Create a new partition:
n
- Delete a partition:
d
- Write changes:
w
- Quit without saving:
q
parted
A tool for managing disk partitions.
Example
Common parted
Commands
- Print partition table:
print
- Create a new partition:
mkpart
- Delete a partition:
rm
- Resize a partition:
resizepart
- Quit:
quit
Filesystem Management
mkfs
Creates a filesystem on a disk or partition.
Example
fsck
Checks and repairs a filesystem.
Example
mount
Mounts a filesystem to a directory.
Example
umount
Unmounts a filesystem from a directory.
Example
lsblk
(again)
Lists block devices and their mount points.
Example
Disk Usage Analysis
ncdu
A disk usage analyzer with a text-based user interface.
Example
Summary
Linux offers a comprehensive set of commands for managing disks and filesystems. Understanding these commands helps in monitoring disk usage, partitioning disks, and maintaining filesystems effectively. For more detailed information on each command, refer to the Linux manual pages.