How to manage disk storage in Linux

Case #

You have a Linux distribution, for example Ubuntu Linux, and you need to run commands to manage the allocated disk space as well as to check partitions and mount points.

This article provides guidance on how to manage disk space in Linux.

Solution #

Manage disks, partitions and mounts #

You should run the following Linux commands to manage allocated disk space and to check partitions and mount points.

#The below command shows all available disks and partitions
fdisk -l
fdisk -l | grep /dev/sd
#The below command shows a summary of the allocated disk space to all partitions
df
#The below df command 
df -H /dev/sda
#The below command is similar to df but uses a graphical tabular interface for better readability
duf -all
#The below command lists block storage devices
lsblk

#Also command lsusb lists the usb interface devices
#The below command provides a tabular output for all disks and partitions
cfdisk
#You can check various configuration files to query information about disks and partitions
cat /proc/partitions
cat /etc/fstab
cat /etc/fstab.d
cat /etc/mtab
cat /proc/self/mountinfo
#The tree command displays the hierarchical folder structure either from / or from another directory
tree
#The gparted command is the graphical interface to parted
#The GNU partition management tool
parted
# The below command displays a tabular list of mounts and can be used with grep to narrow down results
findmnt
#Similar to findmnt, the mount command provides a list of all mounts
mount

Format and mount disks #

To format an attached disk from the Linux command line run the following command.

# Format disk /dev/sdb to create partitions
fdisk /dev/sdb
# For above command choose default options and click w to exit the fdisk command
# Now format the file system inside the created partition
mkfs.ext4 -L [label] /dev/sdb1
#Now mount the newly formatted partition to a mount point (mount point folder must already exist)
mount /dev/sdb1 /mymountpoint

Powered by BetterDocs