[RndTbl] Best ways to find where disk space is being used?

Adam Thompson athompso at athompso.net
Mon Feb 6 06:15:34 CST 2023


There's a shell trick I stumbled upon years ago to simplify that: filename globbing will only include directories if you have a trailing slash.

So "du -sm */ | sort ..." usually gives the same result as the find pipeline.

I have run into situations where it didn't, and this is one 'feature' I've never felt the need to fully explore & understand, so very much YMMV.

I also have a vague recollection that the shellglob way also has some corner cases with spaces or control characters in the directory names, that the find (1) approach handles better.

Quick'n'dirty, not necessarily "best", but sometimes useful.

-Adam

Get Outlook for Android<https://aka.ms/AAb9ysg>

________________________________
From: Roundtable <roundtable-bounces at muug.ca> on behalf of Brian Lowe <brian2 at groupbcl.ca>
Sent: Monday, February 6, 2023, 00:37
To: Continuation of Round Table discussion <roundtable at muug.ca>
Subject: Re: [RndTbl] Best ways to find where disk space is being used?


On Sunday, February 5, 2023 2:56:04 P.M. CST Chris Audet wrote:

> I've got a fairly long lived CentOS server that stubbornly stopped

> installing updates because the HDD is full.

>

> Can someone share their favourite way to determine where disk space is

> being used up on a system?

>

> For example, on Windows I'd use Wiztree/Treesize/Windirstat. On Linux

> desktop I've been using Gnome Disk Usage Analyzer (aka Baobab)

> <https://wiki.gnome.org/Apps/DiskUsageAnalyzer>.

>

> But I'm not sure what the best solutions are in cases where there's no GUI

> available. I could always mount / over SSH and use Baobab to crawl the

> remote filesystem, but that seems less than optimal 🤔



I use this method from the command line. As root, `cd /` and issue the following command:



find . -maxdepth 1 -type d 2>&1 -print0 | grep -zv '^\.$' | xargs -0 du -sm | sort -rn | more



The directory with the greatest usage appears first. `cd` into it and issue the

above command again. Clean directories and large files, then repeat as needed.





Two things to note:



1. Some programs in Linux do a trick where they allocate a file and then delete it while keeping the file open. The inode remains busy and the space isn't freed up until the process terminates. The advantage to this is other processes can't open the file to look into its contents. The disadvantage is you can't see the file using 'ls'. However, such files show up in 'lsof' with the tag '(deleted)'.



2. A file system can report "full" if it runs out of inodes. This used to be a problem on old, small systems, but probably isn't any more because file systems today tend to be very large and have loads of spare inodes. The command "df -i" shows the inode counts.



Brian

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://muug.ca/pipermail/roundtable/attachments/20230206/17d09b4e/attachment.htm>


More information about the Roundtable mailing list