DU

DU It is one of the tools or commands that works to see the occupied space on the hard drive.

What is the DU tool?

DU it is a standard command that helps you to know the space you are using on your hard disk, but besides this, it also includes other options, and with some new parameters it can improve its functions.

DU is the abbreviation for Disk Usage, or what translates as disk usage, and is developed from the operating systems that belong to the Unix family.

Its main function as mentioned above is to check the hard drive storage space of a file, a directory, or even files found within a system. It was first used in the number one version of the AT&T Unix system.

It is one of the most important commands, because as you should know, excess space directly affects the operation of the device, and in order to solve it, it is necessary to determine the real problem.

How to use the DU command?

Explaining how this command works is easier using an example, so, taking that into account, the idea is to see the files that are taking up more space in one of the folders on your computer, in this case the one called "home". To know this information, you must do the following:

1) See the folders that take up the most space

Note that in the first column you can see the size of the file or folder. Now, the first step is to place the command du -a /home | sort -n -r | head -n 10.

2) Find the largest directories

If you want to find the largest directories in general on your computer, you must place the following command: du-a | sort -n -r | head-n 7

3) Know the parameters used

It is important that you know the meaning of each of the parameters used to determine the capacity with DU. For this reason, they are mentioned below:

  • DU: It is the command used to set the space each file occupies on the system.
  • -to: It shows you the list of folders and files.
  • sort: Sort all the lines.
  • -n: It is in charge of comparing all the numeric values ​​of the strings.
  • -r: Invert the results of the comparisons.
  • heads: Shows the headers of the files.
  • -n#: Shows the number of lines to be displayed.

4) Know the details of the size of the directories

To know this information, it is important to correctly execute the following command: du -hs * | sort -rh | head-4. Note that it only shows you the four largest directories.

5) Display the directories and subdirectories

Another option you have is to display both directories and subdirectories to check the space they are consuming. You can do this by typing the command: du-Sh | sort -rh | head -10

How to see the weight of a file easily?

There is also another way that you can use to find out the weight of a specific file, and it is perhaps the easiest. But, you must follow some instructions:

  • The first step is to place the command: $ du -bsh Videos/
  • Then it will appear on the screen du-bsh VideosAnd also 215 Videos/.
  • The largest directories on the system appear below. They are arranged from largest to smallest, and with the command $du -sm you can see the files, as in the following example: