0

I'm trying to free up some disk space on sone Slackware servers. Apparently 69 GB out of 72 GB are occupied so I need to clear up some more.

I searched around and found the below to search for large files and folders but it takes forever:

du -a /var | sort -n -r | head -n 10

So I need some help of how to find the large files and folders.

Andreas
  • 11
  • 1
    You might try some of the things recommended in this question: http://serverfault.com/questions/62411/how-can-i-sort-du-h-output-by-size – D34DM347 Dec 11 '15 at 15:42

3 Answers3

0

You can't avoid looking through your file system to find the stuff that's big. Maybe just set that command going in the background, possibly redirected to a file, and do something else for a bit.

You can refine the command a bit. As it is, the entire du process must run before any output will come out of sort. You could do this:

sort -max /var | grep '^[0-9][0-9][0-9]' > ~/disk_usage_report

Now you're only recording directories and files which are at least 100 MB in size, and you're not sorting them. I've also used -x just in case you have some other file system mounted other /var (and partly out of habit). You can look at the contents of that file at any time as they accumulate, and you can sort the entries there when viewing them:

sort -rn ~/disk_usage_report | head -n 10

On some systems I collect disk usage info like this routinely with a cron job, mostly so I can make comparisons between reports to see what's growing over time, but also it means I have a reasonably recent report available at short notice when I want it. E.g. a cron job like this:

19 3 * * * root du -max / > /var/log/disk_usage-date -Im

mc0e
  • 5,786
  • 17
  • 31
0

Scanning through files is inevitable, there is no other way. Depending on your disk speed this time will be slower or faster. Some usefull command you may try:

find /somedir -type f -size +10M

This will show you all files with size greater(the + sign) than 10M. You can use this only for files since directory's size is actually the directory's metadata(the file listing) and not the size of the files inside.

With find you can also find OLD files, which may be something you forgot a long time ago, for example

find /somedir -mtime +30

This will show files,links,dirs which were not modified for the last 30 days. You can also combine time + size like this:

find /somedir -type f -mtime +30 -size +100M

will show all files which are bigger than 100MiB and were not modified for more than 30 days

For directories use:

du -h -d1 /somedir

-h for human readable (kilo mega giga tera and so on) -d1 - show only first level dirs, by default du will scan everything recursively, which is not very useful in our case.

if you want to sort omit the -h and add '|sort -n -k1'

alternatively you can do:

du -sh *

in the directory you are interested in

EvilTorbalan
  • 605
  • 4
  • 10
0

I would just install https://dev.yorhel.nl/ncdu to avoid doing any console voodoo

AnonymousLurker
  • 141
  • 1
  • 5
  • Why install `ncdu`? How does it help? And why do you refer to our professional work as "voodoo"? – Michael Hampton Oct 18 '18 at 13:50
  • @MichaelHampton because ncdu makes it trivial to find directories that take most space or directories that have highest amount of files (and can cause running out of inodes). It's a small tool, so it's not overkill to have it even on a server. And I was rather referring to the not-so-user-friendly syntax of certain tools like find as "voodoo", it takes years before one can stop having to go to the manpage everytime before having to use them. – AnonymousLurker Oct 18 '18 at 13:58