119

I'm looking for a linux alternative to WinDirStat. I would like to know what is taking up space on my hard drives.

A program that works on console and doesn't require a UI is preferred .

ripper234
  • 31,763
  • 2
    ncdu is my preferred answer, but I see the first answer says you're having problems with it that aren't in your question. – SDsolar Sep 09 '17 at 07:42

14 Answers14

131

If you want a command-line tool, I prefer ncdu, an ncurses version of du. It scans the disk (or a given folder) and then shows the top-level space usages; you can select a given directory to get the corresponding summary for that directory, and go back without needing to reanalyze:

Screenshot of ncdu


If you're ok with a GUI program, Filelight is the closest thing to WinDirStat I've found; it shows a graphical view of space consumption:

Screenshot of Filelight

Like ncdu, Filelight lets you select a given directory to get the breakdown for that directory

Michael Mrozek
  • 93,103
  • 40
  • 240
  • 233
  • 14
    don't you think QDirStat is closer to WinDirStat? – Janus Troelsen Sep 08 '16 at 11:51
  • 2
    @JanusTroelsen, this was answered in 2010. 5 years before the initial commit of QDirStat https://github.com/shundhammer/qdirstat/commit/78d9fef5c15c246f72c3ad3d1a2b2c8223ccefce – Shmuel Kamensky Apr 14 '22 at 12:57
  • @ShmuelKamensky And QDirStat is the descendant of KDirStat, which WinDirStat is actually a port of. So their comment is actually (even if indirectly) absolutely relevant. – adamency Feb 02 '24 at 04:04
  • @adamency, cool history! So QDirStat and WinDirStat are cousins. I didn't mean the comment left by Janus was irrelevant, QDirStat is a good recommendation. Just that the author of the answer could not have known that since it was released way after they answered! – Shmuel Kamensky Feb 03 '24 at 08:28
  • 1
    @ShmuelKamensky Yup I understood that, no worries :) – adamency Feb 06 '24 at 00:07
86

Based on your issues in installing ncdu my recommendation would be to use du and sort on together.

For instance:

  • du /home | sort -rn (will search all files/directories under /home and sort them by largest to smallest.
  • du -h /home | sort -rh (same but will show it in MB/KB/etc) - Note this requires coreutils 7.5 or newer (sort --version to check)

You can replace /home with any directory of your choice.

N J
  • 2,650
  • That's excellent, thanks for the help. My coreutils is 5.97 - is this why the sort order of du -h isn't right? – ripper234 Nov 12 '10 at 11:26
  • Yep, you'd have to settle for du /home | sort -rn with coreutils 5.97 or use some 'magic' with perl etc as demonstrated over on ServerFault (http://serverfault.com/q/62411/60012) – N J Nov 12 '10 at 11:27
  • 2
    OTOH if there is a big sub-sub-directory its bloat will show multiple time (for that dir and each parent dir) at the top of the results, and IMHO that distracts from the true bloat. Using "ncdu" suggested below could help with that, I'm gonna try it. =) – lapo Jan 13 '11 at 21:39
  • 2
    I find the -size option to "find" useful as well, as it lets you find all files under a certain. At least for GNU find, you can do something like: "find . -size +100M" to find files larger than 100M below the current directory. – gabe. Feb 02 '11 at 04:48
59

You should be aware that WinDirStat is actually a port of KDirStat, which is a Linux/KDE program. So, if you are looking for a Linux alternative to WinDirStat, you certainly should take a look at KDirStat. It is already packaged in most distros, just install it.

Another alternative is FileLight, already cited by Michael Mrozek, and the Konqueror plugin fsview (you can run it standalone from the command-line).

Juliano
  • 2,538
39

Another GUI program is: baobab

alt text

sudobash
  • 646
  • In deed, if I'm on Ubuntu I won't bother to look for any alternative. baobap is just enough. – phunehehe Dec 27 '10 at 04:09
  • It also shows number of files, which sometimes needs to be checked as well as disk space – golimar Aug 13 '18 at 10:26
  • Now part of GNOME out of the box, on Fedora at least. – Milind R Aug 16 '23 at 08:27
  • However, when I used it on an NTFS volume (a former Windows boot volume, specifically) of around 100 GB, it kept counting and reached nearly 500 GB in the total size and still kept going - I guess it doesn't have any smarts about counting hardlinks and symlinks. – Milind R Aug 16 '23 at 08:33
  • Ubuntu - no installation necessary! – diynevala Jan 23 '24 at 06:21
16

Use QDirStat (formerly KDirStat).

It includes a perl script that generates a cache file on the server/console without any need for an UI to be running/installed; transfer it to your desktop machine and view it in the gui client.

See https://unix.stackexchange.com/a/256516/186308 for details.

icyerasor
  • 261
  • 2
  • 4
7

I prefer the following command line:

$  du -s -m -x * | sort -n

Breaking it down, du shows disk usage; -s says print the total for each argument (each item in the current directory), -m says show the size in Megabytes. This makes it easier for sort to work; sort doesn't really understand the -h output. The -x ignores other filesystems; this is useful when trying to find space hogs in /var, and /var/spool/foo is a different filesystem.

HalosGhost
  • 4,790
  • Doesn't the top answer already use du? – muru Dec 03 '14 at 13:53
  • Yes, but du /home on my systems returns tens of thousands of files; I rarely care what the (say) 100 largest of those files are; I typically want to know which subdirectories are taking up the most space. – P Joslin Dec 03 '14 at 20:43
  • Instead of -s, I specified --max-depth=2, as I wanted to go one directory down from the root directory, but your answer pointed me in that direction. Thanks! – John Eisbrener Oct 13 '16 at 14:06
6

If you looked at the about screen on windirstat it showed you that it's based on kdirstat.

http://kdirstat.sourceforge.net/

DF1eCH
  • 61
6

There's also this cool python script from /www.vrplumber.com/programming/runsnakerun/

bzr branch lp:~mcfletch/squaremap/trunk squaremap

It's not the most feature rich, but it's run from a single python script so it's extremely portable.

alt text

Falmarri
  • 13,047
5

You could also try GD Map, another GUI tool based on treemaps.

Glorfindel
  • 815
  • 2
  • 10
  • 19
Bruno
  • 1,133
3

xdiskusage is very flexible, lightweight with very lean dependencies, easy to compile..

It shows a tree left-to-right that you can navigate with mouse or arrow keys, zoom in (click or enter), hide some parts for a better view, change sort order, number of colors etc with keys or context menu.

It's so lighweight that you can use it on a remote SSH link with good performance. In this case I recommend -q command line option to disable the progress bar that appears while files are walked.

You can also optionally run du yourself beforehand.

One situation is a remote filesystem which is full or near-full. On that system run du -ak | gzip >log_of_disk_usage.txt.gz, fetch the output and run gzip -dc log_of_disk_usage.txt.gz | xdiskusage -aq locally.
Or even ssh myremotesystem "cd /filesystem_near_full/ ; du -ak | gzip" > log_of_disk_usage.txt.gz to store the result locally without writing anything remotely.

xdiskusage does not offer to modify the filesystem (like move to trash, etc) but you can copy a path to clipboard and paste that into a file manager, terminal etc.

xdiskusage screenshot

2

I have recently used command line tool (CLI, not TUI): http://zevv.nl/play/code/philesight/

It produces a PNG file which you can view somewhere else. It also has a CGI script.

Most likely you are not limited to text mode at your local workstation, so it should be appropriate.

OCTAGRAM
  • 121
1

Also to see the files in a specific directory sorted by size after you have found the directory using du use:

ls -lrSh
Wodin
  • 245
1

Duc (https://duc.zevv.nl/) will work from the command line.

It can be installed and used like this in Debian 9:

# apt install duc
# duc index /
# duc graph /

With this you'll get a file named duc.png in the current directory. Now, you can copy this file to another GUI capable computer and it will look like this: duc.png

NOTE: Duc is the replacement for the tool that @OCTAGRAM mentioned in his answer.

0

For btrfs filesystems, you may like my tool, btdu:

  • Starts showing results instantly
  • Shows snapshots / reflinks / cloned files correctly
  • Shows real (compressed) usage of compressed files