Linux provides us with a lot of tools to manage disks. These
tools allow us to view disk usage and partition the drive.
Report Disk Space Usage
Here are some common options for du command:
Option
Description
-h or ‑‑human-readable
Show human readable size format.
-s or ‑‑summarize
Size of the specified directory only.
1
du [OPTION]
Estimate File Space Usage
Here are some common options for df command:
Option
Description
-h or ‑‑human-readable
Show human readable size format.
-i or ‑‑inodes
Show inodes instead of blocks.
-l or ‑‑local
Show local file related information.
-P or ‑‑portability
Show in POSIX style, keep in same line.
-T or ‑‑print-type
Show filesystem type.
1
df [OPTION]
List Block Devices
We can use lsblk command to list block devices:
1
lsblk
Show Partitions
We can output all the partitions through the /proc/partitions
file:
1
cat /proc/partitions
Change or Show an ext{2|3|4} Filesystem Label
Show device’s label:
1
e2label device
Change device’s label:
1
e2label device label
Dump an ext{2|3|4} Filesystem Information
Here are some common options for dumpe2fs command:
Option
Description
-h
Show super block details.
1
dumpe2fs [OPTION] device
Adjust ext{2|3|4} Filesystem Tunable Parameters
Here are some common options for tune2fs command:
Option
Description
-c #
Adjust the self-check behavior after the # mount
amount,0 or -1 means disable the function.
-i #
Adjust the self-check behavior after # days of the mount
usage.
-j
Adjust disk from ext2 to ext3, this can be reversed, but
this doesn’t hurt the existing data.
-l
Show super block details.
-L LABEL
Change disk label.
-m
Adjust remaining percentage for super user.
-o OPTION(acl or ^acl)
Adjust default mount point.
-r
Adjust remaining blocks.
1
tune2fs [OPTION] device
Show locate/print block device attributes
Here are some common options for blkid command:
Option
Description
-i or ‑‑info
Show I/O Limits (aka I/O topology) information
-k or ‑‑list-filesystems
Show all known filesystems and RAIDs.
-L LABEL or ‑‑label LABEL
Look for devices according to LABEL.
-U UUID or ‑‑uuid UUID
Look for devices according to UUID.
1
blkid [OPTION] device
Check and Repair a Linux Filesystem
Here are some common options for fsck command:
Option
Description
-t FSTYPE
Specify a file system type.
-a
Repair automatically.
1
fsck [OPTION] device
Repair an XFS Filesystem
1
xfs_repair
Check a Linux ext{2|3|4} Filesystem
Here are some common options for e2fsck command:
Option
Description
-f
Force inspecting.
-p
Repair automatically.
1
e2fsck [OPTION] device
Manipulate Disk Partition Table
Here are some common options for fdisk command:
Option
Description
-l or ‑‑list
List device’s partition tables, if no device is
given, then output /proc/partitions instead.
Here are some common command for fdisk command when creating
partition:
Option
Description
d
Delete a partition.
l
Show supported types.
n
Create partition, e: extended partition, p: primary
partition. +NG(Number of GigaBytes), +NM(Number of
MegaBytes), +NK(Number of KiloBytes), +N(Number of
Bytes)
p
Show disk partition, include the pending one.
q
Exit without saving the operations.
t
Edit partition type.
w
Save before exit.
1
fdisk [OPTION] device
Manipulate GUID Partition Tables
1
gdisk
Manipulate Disk Partitions
Here are some common options for parted command:
Option
Description
-l or ‑‑list
Show all block devices’ partition layout.
1
parted [OPTION][device]
Inform the System of Partition Table Changes
1
partprobe
Build a Linux Filesystem
Here are some common options for mkfs command:
Option
Description
-b BLOCKSIZE
Specify the block size, by default is 4096, available
options are 1024, 2048 or 4096.
-E
User specified extra file system attributes.
-i #
Specify the byte spaces per inode, by default is 8192,
this value must be the block size to the second power.
-L LABEL
Specify partition label.
-m #
Specify remaining percentage for super user.
-N #
Specify inode quantity.
-t FSTYPE
FSTYPE can be either ext2, ext3, ext4 or xfs. This is
equivalent to mkfs.ext2, mkfs.ext3, mkfs.ext4, mkfs.xfs.
1
mkfs
Create an ext{2|3|4} Filesystem
Here are some common options for mke2fs command:
Option
Description
-b BLOCKSIZE
Specify the block size, by default is 4096, available
options are 1024, 2048 or 4096.
-i #
Specify the byte spaces per inode, by default is 8192,
this value must be the block size to the second power.
-j
Create ext3 file system.
-L LABEL
Specify partition label.
-m #
Specify remaining percentage for super user.
-N #
Specify inode quantity.
-O FEATURE:
Create with the given features.
-t FSTYPE
Can be either ext2, ext3 or ext4.
1
mke2fs
Mount a Filesystem
Here are some common options for mount command:
Option
Description
-a
Mount all file systems defined in /etc/fstab file.
-n
Stop appending devices’ details to /etc/mtab file.
-o
Specify additional mount device options, it is, the file
systems’ enabled attributes, use comma for
multiple options.
-r
Read only mount, usually used for compact disc (CD).
-t FSTYPE
Specify device’s file system type, mount will call
blkid to identify the type by default.
-w
Read write mount.
Show all mounted devices by default, append mounted
device’s detail to /etc/mtab file by default.
1
mount [device][mountpoint]
Unmount Filesystems
Here are some common options for umount command:
Option
Description
-n or ‑‑no-mtab
Unmount without writing in /etc/mtab file.
1
umount [OPTION][device]
Check Mounted Devices
1
2
3
cat /proc/mounts
# OR
cat /etc/mtab
Check Processes Using Files or Sockets
Here are some common options for fuser command:
Option
Description
-k
Terminates all processes that are using the specified
file or directory.
-m
Lists all processes that are using the specified mount
point.
-km
Terminates all processes that are using the specified
mount point.
-v
View the process.
1
fuser [OPTION]
List Opened Files
1
lsof
Create a Swap Area
Here are some common options for mkswap command:
Option
Description
-c or ‑‑check
Check the block device for bad blocks before creating
the swap area.
-L or ‑‑label
Specify a label for the device.
-U or ‑‑uuid
Specify the UUID to use. The default behavior is to
generate a UUID.
1
mkswap [OPTION] device [SIZE]
Enable or Disable Devices and Files for Paging and Swapping
Here are some common options for swapon command:
Option
Description
-a or ‑‑all
All swap devices defined in the /etc/fstab file.
-L or ‑‑label
The label of the partition.
-s or ‑‑summary
Show swap usage summary, cat /proc/swaps is equivalent.