Check Estimate File Space Usage with du Command on Linux

Check Estimate File Space Usage with du Command on Linux

If you are a Linux user, then there's an easy way available to check the file size from your desktop. In these types of cases, you need to right-click on a particular file and select the detail option to show the file or directory data and size. This is possible when we have a desktop or graphical interface. But what do you do if you are using a server and only have terminal (SSH) access available? In this type of case, we need to use the disk usage command. This command is identified with the du command in Linux. For using the disk usage command, multiple factors are available. We can check these factors step by step with examples. Now we can test all du commands in Linux.

Use du Command on Linux

This command specifies the estimated file used space in Linux. It targets the directory or file you want to choose. For example, if I want to check my Ubuntu Document directory's data, then I need to input the given command:

$ du ~/Documents
inet70@inet70pvtltd:~$ du ~/Documents
20	/home/inet70/Documents/headline/partials/icons
60	/home/inet70/Documents/headline/partials
8	/home/inet70/Documents/headline/.well-known
28	/home/inet70/Documents/headline/assets/css
320	/home/inet70/Documents/headline/assets/built
456	/home/inet70/Documents/headline/assets/fonts
16	/home/inet70/Documents/headline/assets/images
32	/home/inet70/Documents/headline/assets/js
856	/home/inet70/Documents/headline/assets
8	/home/inet70/Documents/headline/news
1076	/home/inet70/Documents/headline
11404	/home/inet70/Documents
inet70@inet70pvtltd:~$ 

From the output, you can see all the available folders and data, shown numerically.

Check disk usage data with human-readable format:

By checking the disk space usage command directly, the data is shown only in numerical format. It's not understandable. In this type of case, we need to include h in the command to show the data in bytes format. For example:

$ du -h ~/Documents
inet70@inet70pvtltd:~$ du -h ~/Documents
20K	/home/inet70/Documents/headline/partials/icons
60K	/home/inet70/Documents/headline/partials
8.0K	/home/inet70/Documents/headline/.well-known
28K	/home/inet70/Documents/headline/assets/css
320K	/home/inet70/Documents/headline/assets/built
456K	/home/inet70/Documents/headline/assets/fonts
16K	/home/inet70/Documents/headline/assets/images
32K	/home/inet70/Documents/headline/assets/js
856K	/home/inet70/Documents/headline/assets
8.0K	/home/inet70/Documents/headline/news
1.1M	/home/inet70/Documents/headline
12M	/home/inet70/Documents

From the output, you can see all the data is shown in kilobytes. It's understandable for all users. It doesn't always show all folder or file sizes in kB. It depends on the file size.

Check total directory's usage space with du command:

This character is for identifying the total file size in the directory. For example, if I need to check the available files total in the terminal, it's identified with "-c".

$ du -c ~/Documents
inet70@inet70pvtltd:~$ du -c ~/Documents
20	/home/inet70/Documents/headline/partials/icons
60	/home/inet70/Documents/headline/partials
8	/home/inet70/Documents/headline/.well-known
28	/home/inet70/Documents/headline/assets/css
320	/home/inet70/Documents/headline/assets/built
456	/home/inet70/Documents/headline/assets/fonts
16	/home/inet70/Documents/headline/assets/images
32	/home/inet70/Documents/headline/assets/js
856	/home/inet70/Documents/headline/assets
8	/home/inet70/Documents/headline/news
1076	/home/inet70/Documents/headline
11404	/home/inet70/Documents
11404	total

From the screenshot, you can see the files output. It's shown in a numerical format for human-readable format include "h" on the command to make it readable.

$ du -ch ~/Documents
inet70@inet70pvtltd:~$ du -ch ~/Documents
20K	/home/inet70/Documents/headline/partials/icons
60K	/home/inet70/Documents/headline/partials
8.0K	/home/inet70/Documents/headline/.well-known
28K	/home/inet70/Documents/headline/assets/css
320K	/home/inet70/Documents/headline/assets/built
456K	/home/inet70/Documents/headline/assets/fonts
16K	/home/inet70/Documents/headline/assets/images
32K	/home/inet70/Documents/headline/assets/js
856K	/home/inet70/Documents/headline/assets
8.0K	/home/inet70/Documents/headline/news
1.1M	/home/inet70/Documents/headline
12M	/home/inet70/Documents
12M	total

It's shown in a readable format.

Check directory usage space in summary:

This character is used to show all the directory's usage in summary. When we check the usage of a directory, it's shown as all files data inside the directory. For checking the directory data without showing insider files, then use this method. This symbol is "S". For example:

$ du -sh ~/Documents
inet70@inet70pvtltd:~$ du -sh ~/Documents
12M	/home/inet70/Documents

Here I can use "h" to make the output human-readable format. You can also use it. From the output, you can see it shows the size without identifying any file or folder in the directory.

Conclution:

From the given tutorial, maybe you have completely understood about how the du command is important in the Linux operating system. In the desktop, it's not as useful, but if you are a web developer, then it's helpful to check the available file sizes.