View Categories

How to manage disk storage in Linux

Estimated Reading Time: 2 minute(s)

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
Cloud School Docs - image 6 -
Cloud School Docs - image 5 -
#The below command shows a summary of the allocated disk space to all partitions
df
Cloud School Docs - image 7 -
#The below df command 
df -H /dev/sda
Cloud School Docs - image 8 -
#The below command is similar to df but uses a graphical tabular interface for better readability
duf -all
Cloud School Docs - image 9 -
#The below command lists block storage devices
lsblk

#Also command lsusb lists the usb interface devices
Cloud School Docs - image 10 -
#The below command provides a tabular output for all disks and partitions
cfdisk
Cloud School Docs - image 11 -
#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
Cloud School Docs - image 12 -
#The tree command displays the hierarchical folder structure either from / or from another directory
tree
Cloud School Docs - image 13 -
#The gparted command is the graphical interface to parted
#The GNU partition management tool
parted
Cloud School Docs - image 14 -
# The below command displays a tabular list of mounts and can be used with grep to narrow down results
findmnt
Cloud School Docs - image 15 -
#Similar to findmnt, the mount command provides a list of all mounts
mount
Cloud School Docs - image 16 -

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
Cloud School Docs - image 17 -

Powered by BetterDocs