Saturday, April 20, 2024
HomeTutorialsHow To Check Total Hard Disk Size in Ubuntu Terminal

How To Check Total Hard Disk Size in Ubuntu Terminal

Using the terminal shell is powerful in Linux machines when checking and monitoring the system’s health and status. The terminal shell executes commands with the connection to the Linux kernel. As a result, it can provide you the real-time results. There are tools and commands for Linux that help you monitor the CPU load, Hard disk space, disk bad sectors, RAM status, etc. Ubuntu and other distribution users use the terminal shell over the GUI method to check the hard disk size because the command-line method to monitor the hard disk details and specifications is hassle-free and gives us real-time output with fewer errors.

Hard Disk Size in Ubuntu Terminal


In Linux, the file system reports are usually generated into block size. In a previous post, we saw that while finding the bad sectors on the disk, it displayed the result in a block-size value. There are two syntaxes/commands to show the disk sizes on Linux; they are the du and df.

  • df command – The df command shows the total used and free size of the disk. If you do not assign any filename, the system will mount the file into the primary disk. It shows the values in 1kB block size.
  • du command – The du shows the amount of disk space used by specified files and their subdirectory.

In this post, we’ll see how to check the hard disk size in Ubuntu through the du, and df commands on the terminal shell.

df Output Analysis on Ubuntu


In the below command, we can see some specific values. Here we will see what they mean.

$ df

DF Output Analysis On Ubuntu

  • Filesystem: This shows the name of the filesystem.
  • 1K-Blocks: See the total amount of available blocks on the file system measured on 1kB block.
  • Used: With the used parameter, you can monitor your used disk in 1kB block size.
  • Available: See the available disk on your Linux system in 1kB block size.
  • Use%: Use% allows you to see the used disk on Linux as a percentage value.
  • File: In the CLI, you can see the file name on your system.
  • Mounted on: Monitor the location where your filesystem or a single folder is mounted.

Check Hard Disk Size in Ubuntu Terminal With df Command


Here, we will see a few most used df commands to check the hard disk size in Ubuntu through the terminal. You can execute the commands in any other Debian-based system as well.

1. df Terminal Command To Check Hard Disk Size in GB


The below-mentioned df command will let you see the total size of the hard disk on your Ubuntu system.

$ df -a

DF Terminal Command To Check Hard Disk Size in GB

2. Print Readable Data To Check Hard Disk Size in Ubuntu 


Sometimes, through the command line, we might get some output data that is hard to understand or not readable for a human. To make the output simple and human-readable, please use the -h flag with the df command on the Ubuntu shell.

$ df -h

3. Print Disk Usage in Megabytes In Ubuntu Terminal


You can use the -BM syntax on the command line to see the disk space in megabytes format on your Ubuntu system.

df -BM

Print Disk Usage in Megabytes In Ubuntu Terminal

4. Disk Info in Numbers of inodes


In Ubuntu, you can also see the hard disk size and used amount through the terminal shell with their index node value. Knowing the index node value or the inodes will help you to set and organize the soft links on Linux.

df -i

Disk Info in Numbers of inodes

Here is the explanation of the index nodes:

  • source: This shows the name of the files on the system.
  • fstype: It shows the type of the file on Ubuntu/Linux.
  • itotal: Display the size of the file through the terminal shell.
  • iused: This shows the total amount of used size on the disk.
  • iavail: See the free amount of the disk via the index node.
  • ipcent: View the used percentage of the hard disk in index node value.
  • size: Displays the hard disk size on Ubuntu in 1kB block size.

5. Include or Exclude File Types To Check Hard Disk Size in Ubuntu Terminal


You can also exclude or include any type of file through the df command on Ubuntu. The below-mentioned command will tell us how we can assign a specific print type that will instruct the DF command to add the file to the output.

df -T
df -t ext4

Include Or Exclude File Types To Check Hard Disk Size in Ubuntu Terminal

6. See SquashFS Files


The SquashFS files are special compressed files on Ubuntu and other Linux systems. It supports the block-size method to view the files. Execute the below-mentioned commands to see the used size of SquashFS files on your Ubuntu through the terminal.

df -x squashfs
df -x squashfs --total

See SquashFS Files

7. See the Size of the Directory or Filesystem


If you need to see the hard disk size or the block size of any specific directory or folder on Ubuntu Linux through the terminal shell, you can use the following df commands given below.

df /dev/sda1
df /dev/sda*

8. Alias with df To Check Hard Disk Size in Ubuntu Terminal


If you have a bigger syntax with the DH command, you can use an alias for the DH syntax to make your command easier on the Ubuntu terminal shell.

alias dfc="df -h /dev/sda1 --output=source,fstype,size,used,avail,pcent"

9. Use -a Flag to Include All Filesystems


You can add the -a flag to add all the filesystems on the terminal command for showing the hard disk size on Ubuntu.

df -a --output
df -a --output | less

10. Finding Out What’s Taking Up the Used Disk Space


Through the below-mentioned DF command. You can monitor which particular directory is keeping your disk busy on your Ubuntu machine.

df -h -t ext4

Finding Out What’s Taking Up the Used Disk Space

du Command on Ubuntu To Check Hard Disk Size in Terminal


Through the DU command on Ubuntu, you can see the used and free size of the hard disk on the terminal shell. If you do not use any logical arguments with the DU command, it will conventionally show the disk space in 1024 bytes. Here we will see a few practical and most used examples of the DU command on Ubuntu to see the disk size in the Ubuntu terminal.

1. Get Started with du Command


The below-mentioned du command on the Ubuntu terminal shell will give us the output of used and free hard disk sizes on the machine.

$ du

Get Started with DU Command

2. Human-Readable Output


Earlier, we have seen how to print human-readable data for the DH command; the below-mentioned DU command also shows the human-readable block size or the disk size data in the Ubuntu terminal.

du -h

3. Summarize The Output


You can execute the below-mentioned du command on your Ubuntu terminal shell to summarize the hard disk results on your system.

du -h -s *

Summarize The Output

4. Sort Hrad Disk Results


You can assign the DU command to sort the directory or folders that are using more disks on your Ubuntu system. The below-mentioned du command will give you the sorted results from largest to smallest disk used in the Picture directory.

du -sm Pictures/* | sort -nr

Sort Hrad Disk Results

Insights!


In the entire post, we have seen the elaborated notion of finding out the hard disk size in Ubuntu through the terminal shell. We have also seen the use case of two specific commands (du and df) to check the hard disks used and free size on Ubuntu or a Debian-based Linux System.

If you find this article has been useful for you, please do not forget to share this post with your friends and the Linux community. We also encourage you to write down your opinions in the comment section regarding this article.

Mehedi Hasan
Mehedi Hasan
Mehedi Hasan is a passionate enthusiast for technology. He admires all things tech and loves to help others understand the fundamentals of Linux, servers, networking, and computer security in an understandable way without overwhelming beginners. His articles are carefully crafted with this goal in mind - making complex topics more accessible.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

You May Like It!

Trending Now