In this article, we will review a number of Linux command line utilities that you can use to check disk partitions in Linux.
Monitoring the space usage of storage devices is one of the most important tasks for a SysAdmin, which ensures that there is adequate free space available on the storage devices to maintain the efficient operation of your Linux system.
List of Command Line Tools to Check Linux Disk Partitions
The following is a list of command line utilities for printing storage device partition tables and space usage.
1. fdisk (fixed disk) Command
fdisk is a powerful and popular command line tool used for creating and manipulating disk partition tables. It supports various partition table formats, including GPT, MBR, Sun, SGI, and BSD.
You can use fdisk‘s user-friendly, text-based, menu-driven interface to perform tasks such as displaying, creating, resizing, deleting, modifying, copying, and moving partitions on storage disks
The fdisk command below will print the partition table of all mounted block devices:
$ sudo fdisk -l
For more usage and examples of the ‘fdisk‘ command, please read ‘10 ‘fdisk’ Command Examples to Manage Partitions‘.
2. sfdisk (scriptable fdisk) Command
sfdisk works similarly to fdisk as it can print or manipulate a storage disk partition table. However, sfdisk offers additional features that are not available in fdisk. You can use it just like fdisk, and it also supports GPT, MBR, Sun, and SGI partition tables.
One difference between the two is that sfdisk does not create the standard system partitions for SGI and SUN disk labels like fdisk does.
$ sudo sfdisk -l
For more usage, go through the sfdisk man pages.
3. cfdisk (curses fdisk) Command
cfdisk is a simple program used for printing and managing disk partitions by providing basic partitioning functionality through a user-friendly interface that operates similarly to more powerful commands like fdisk and sfdisk, enabling users to view, add, delete, and modify hard disk partitions.
Use the right and left arrow keys to move the highlighter over the menu tabs.
$ sudo cfdisk
4. Parted Command
The parted command is a versatile and powerful utility for managing disk partitions on Unix-like operating systems. With a wide array of features, it allows users to create, resize, delete, and manipulate partitions on hard drives, making it essential for system administrators and advanced users.
The parted tool supports both MBR (Master Boot Record) and GPT (GUID Partition Table) partitioning schemes and provides options for various file systems.
Additionally, parted provides a range of advanced features, such as alignment control and the ability to create, resize and copy disk partitions (add a progress bar while copying), making it an indispensable tool for disk management tasks.
$ sudo parted -l
5. lsblk (list block) Command
The lsblk command provides a detailed overview of storage devices, including hard drives, solid-state drives, and removable media, along with their associated information like size, partitions, and mount points.
lsblk aids in system administration tasks, making it easier to identify available storage resources, understand disk configurations, and manage storage devices efficiently.
Its straightforward output and customization options make it a valuable tool for system administrators, helping ensure effective storage management and troubleshooting.
$ lsblk
6. blkid (block id) Command
The blkid command is used to identify block devices such as hard drives and partitions by their Universally Unique Identifier (UUID) or other attributes. It provides crucial information about storage devices, making it easier to mount and manage them.
$ blkid
7. hwinfo (hardware info) Command
The hwinfo command is used to provide comprehensive data about the system’s components, including CPU, RAM, storage devices, graphics cards, network interfaces, and more.
The system administrators and users employ ‘hwinfo‘ to diagnose hardware issues, identify compatible drivers, and enhance system performance.
$ hwinfo
To restrict the information to a summary, use --short
option as in the command below:
$ hwinfo --short --block
Make sure the hwinfo tool is installed on your system to get the above results.
List of Command Line Tools to Monitor Linux Disk Space Usage
The following list includes command-line utilities for monitoring Linux disk space usage.
8. df (disk filesystem) Command
The df command is used to retrieve essential information about disk usage and available storage space on Linux file system usage.
The “df” command assists users in monitoring disk space allocation, identifying potential storage issues, and making informed decisions regarding data management and cleanup.
The '-hT'
switch in the command below enables human-readable reporting of disk size, used space, available space, and used space percentages.
$ df -hT
9. du (disk usage) Command
The du command is used to allow users to assess the space occupied by files and directories on their storage device in a human-readable format.
The du command helps users identify which files or directories consume the most space, aiding in disk management, cleanup, and optimization tasks. This command is invaluable for system administrators and users seeking to maintain efficient disk usage.
$ du -sh /home/tecmint
10. pydf (python df) Command
The pydf command is an exceptional Python command line utility and a great replacement for the df command in Linux. It uses distinct colors to highlight disk partitions with specific attributes.
$ pydf
Make sure that the ‘pydf‘ utility is installed on your system. If it is not installed, you can install it using the ‘Install Pydf Tool in Linux‘ article.
What to Do When Your Linux Disk/Partition Is Running Out of Space?
Once you realize that any of your storage disk(s) is running out of space or is full, you should:
- First, make a backup of all your important files on the system using any of the Linux system backup tools.
- Next, check which files or directories are occupying the biggest amount of space on the disk(s) using the du command.
- Then delete from the storage disk(s), any files that are no longer important or that you will not use in the future with the help of the rm command or you can CCleaner tools to find and delete unwanted files in Linux.
- If your root partition is getting full, you can resize root partition using LVM, it should be pretty straight.
Note: In case you delete any important file, you can recover the deleted file in Linux.
Conclusion
In this article, we have talked about a number of useful command line utilities for displaying storage disk partition tables and monitoring space usage.
If there is any important command line utility for the same purpose, that we have left out? Let us know via the comment section below. You can possibly ask a question or provide us feedback as well.
A minor quibble about terminology. All the above commands DISPLAY their output information on the terminal. The output will be PRINTED only if it is piped into some print function. PRINT usually refers to hard copy output.
“If your root partition is getting full, you can resize root partition using LVM”
Isn’t that a rather drastic procedure, requiring a total re-organization of all the storage devices on your system? It would take your system offline for an extended period of time. Wouldn’t using GParted to resize existing partitions be advisable, quicker, and less error-prone?
I don’t call these tools real monitoring tools, because you have them run them manually each time, so you have to do the monitoring yourselves.
What site would be good to get actual help on a Linux problem instead of being told all the things Im doing wrong posting my questions in the wrong site? My problem is I cant access my bios and have no splash screen to choose which O/S I want to log into.I will post some basic info here in hopes that you can help or guide me to anyone that can help.
http://paste.ubuntu.com/26178393/
thank you for your help and time.
Jim
@Jim
To be honest, there is no single straightforward solution to this issue. And from my own experience, no single site will help you solve an Computer/IT problem. You need to carefully peruse through the web and dig through various resources relating to an issue.
But first, what machine are you using(Dell, HP, Samsung, etc..)? There could possibly be a problem with your hardware causing you not to access the BIOS, for example the keyboard. The key for accessing the BIOS depends on the settings of the machine manufacturer, you could be using a wrong key.
You can contact the machine manufacturer or read manuals or documentations to learn how to access the BIOS, that is if it isn’t corrupted.
In addition, from the information you provided, i can noticed that you are using LILO boot loader, i personally prefer GRUB/2, you can change from LILO to GRUB2 using this guide: https://wiki.debian.org/FromLiloToGrub
I hope this will give you a starting point towards solving your issue. In case of any thing, you can always write to us.
Your commands example is OK, but sometime, you have some bad luck. And something is wrong with your system. Block-id, uuid are very hard to identify, if I have several hdd/ssd/whatever.
It could be very difficult to see that /dev/sdX or uuid, is located on xxx device, if I have 2 or more identical hdd/ssd. More simple is to use anywhere (fstab, as a example) /dev/disk/by-id/*.
In this case you will get even the serial-number that is printed to the (any) hdd/ssd label. Try for example this:
and you will understand what I am try to say! And you can use fdisk(whatever) /dev/disk/by-id/yyyyy
Less errors and less mistakes (I make a new gpt table on the wrong disk …)
Have a nice day, with BY-ID :)
I am not sure, that frisk supports GPT, I think that for GPT is gdisk
@Jan
According to the fdisk man page – “fdisk is a dialog-driven program for creation and manipulation of partition tables. It understands GPT, MBR, Sun, SGI and BSD partition tables.” Though i have not extensively tested it on GPT disks, so you might practically be correct.