How to find out what is taking up disk space in Linux

Sometimes disk space suddenly runs out, and you need to quickly identify the cause. Let’s find the problematic partition using the command:

df -h

Output example:

Filesystem             Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root  2.0G  1.5G  678M  64% /
/dev/mapper/rhel-usr    30G  4.5G   25G  16% /usr
/dev/sda               5.5T  5.3T  200G  97% /data
/dev/mapper/rhel-tmp    50G  3.5G   45G   8% /tmp
/dev/mapper/rhel-var   150G   35G  105G  23% /var
/dev/mapper/rhel-opt   200G   25G  165G  12% /opt
/dev/mapper/rhel-home   50G   45G  5.5G  89% /home
tmpfs                   76G     0   76G   0% /run/user

We are looking partitions, which 95% full or more. Use the /cd command to navigate to the folder from the corresponding “Mounted on” column. In our case it is /data folder. Next, execute:

du -ha --time | sort -h -r | head -n 15

The 15 largest files and folders will be displayed:

74M     2020-11-23 18:18        .
74M     2020-10-09 13:01        ./test-dev.jar
72K     2020-11-23 18:18        ./config
12K     2020-09-11 17:00        ./config/test.jks
8.0K    2020-11-23 14:49        ./config/server_keystore.jks
8.0K    2020-11-23 14:39        ./config/client_keystore.jks
4.0K    2020-11-23 18:18        ./config/test.properties
4.0K    2020-11-23 14:49        ./config/server_truststore_second.jks
4.0K    2020-11-23 14:39        ./config/client_truststore_second.jks
4.0K    2020-10-13 11:52        ./z
4.0K    2020-10-07 12:44        ./config/zookeeper.client.digest.jaas
4.0K    2020-10-05 17:20        ./config/zookeeper.client.kerberos.jaas
4.0K    2020-09-17 16:47        ./generator.sh
4.0K    2020-09-11 17:28        ./config/test1.jks
4.0K    2020-08-31 13:20        ./manual.sh

du -ha –time command displays the creation/modification date of files and directories in the current folder.
sort -h -r command sorts the results in reverse order by memory usage.
head -n 15 command sets the number of lines to display.

So, the answer is:

du -ha --time /your/directory | sort -h -r | head -n 15

If you still have any questions, feel free to ask me in the comments under this article, or write me on promark33@gmail.com.

If I saved your day, you can support me :)

Leave a Reply

Your email address will not be published.