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.
1
2
swapon [OPTION] [file]
swapoff [-a]

Static Information About the Filesystems

Here are /etc/fstab file’s fields definitions

Field Description
First Device name, LABEL, UUID, pseudo file systems(proc, tmpfs, sysfs).
Second Mount point, swap is the mount point of swap device.
Third File system type.
Fourth Mount point option, defaults means default options, multiple options(default,noauto,user, owner, nofail).
Fifth Dump frequency, 0(no backup), 1(backup everyday), 2(backup every other day)
Sixth Check file system, 0(no self-check), 1(self-test first), 2(secondary self-test).

Make Block or Character Special Files

Here are some common options for mknod command:

Option Description
-m MODE or ‑‑mode=MODE Set file permission bits to MODE.

Here are some TYPEs for mknod command:

Option Description
b Block (buffered) special file, MAJOR and MINOR must be specified.
c, u Character (unbuffered) special file, MAJOR and MINOR must be specified.
p FIFO, MAJOR and MINOR must be omitted.
1
mknod [OPTION] TYPE [MAJOR MINOR]

Copy a File

1
dd if=data_source of=target bs=block_size count=block_amount

Backup Disk MBR

1
dd if=/dev/sda of=/mnt/usb/mbr.backup bs=512 count1

Recover Disk MBR

1
dd if=/mnt/usb/mbr.backup of=/dev/sda bs=512 count=1

Create Virtual Compact Disc

1
cat /dev/cdrom > /root/compact_disc.iso

A Worse Performance Swap Space

1
2
3
4
free -m
dd if=/dev/zero of=/var/swapfile bs=1M count=2014
mkswap /var/swapfile
free -m

Display File Contents in Hexadecimal, Decimal, Octal, or ASCII

Here are some common options for mknod command:

Option Description
-b or ‑‑one-byte-octal One-byte octal display.
-c or ‑‑one-byte-char One-byte character display.
-C or ‑‑canonical Canonical hex+ASCII display.
-d or ‑‑two-bytes-decimal Two-byte decimal display.
-x or ‑‑two-bytes-hex Two-byte hexadecimal display.
1
hexdump [OPTION] file

References DF(1), DU(1), LSBLK(8), E2LABEL(8), DUMPE2FS(8), TUNE2FS(8), BLKID(8), FSCK(8), xfs_repair(8), E2FSCK(8), FDISK(8), GDISK, PARTED(8), PARTPROBE(8), MKFS(8), MKE2FS(8), MOUNT(8), UMOUNT(8), FUSER(1), LSOF(8), MKSWAP(8), SWAPON(8), FSTAB(5), MKNOD(1), DD(1), HEXDUMP(1)

Buy me a coffeeBuy me a coffee