Linux utility for finding the largest files/directories
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game 2 Looping
--
Chapters
00:00 Question
00:32 Accepted answer (Score 130)
02:06 Answer 2 (Score 200)
02:19 Answer 3 (Score 37)
03:22 Answer 4 (Score 23)
03:45 Thank you
--
Full question
https://superuser.com/questions/9847/lin...
Answer 3 links:
[filelight]: http://methylblue.com/filelight/
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#linux #diskspace
#avk47
ANSWER 1
Score 200
I always use ncdu
. It's interactive and very fast.
ACCEPTED ANSWER
Score 130
To find the largest 10 files (linux/bash):
find . -type f -print0 | xargs -0 du | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {}
To find the largest 10 directories:
find . -type d -print0 | xargs -0 du | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {}
Only difference is -type {d:f}
.
Handles files with spaces in the names, and produces human readable file sizes in the output. Largest file listed last. The argument to tail is the number of results you see (here the 10 largest).
There are two techniques used to handle spaces in file names. The find -print0 | xargs -0
uses null delimiters instead of spaces, and the second xargs -I{}
uses newlines instead of spaces to terminate input items.
example:
$ find . -type f -print0 | xargs -0 du | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {}
76M ./snapshots/projects/weekly.1/onthisday/onthisday.tar.gz
76M ./snapshots/projects/weekly.2/onthisday/onthisday.tar.gz
76M ./snapshots/projects/weekly.3/onthisday/onthisday.tar.gz
76M ./tmp/projects/onthisday/onthisday.tar.gz
114M ./Dropbox/snapshots/weekly.tgz
114M ./Dropbox/snapshots/daily.tgz
114M ./Dropbox/snapshots/monthly.tgz
117M ./Calibre Library/Robert Martin/cc.mobi
159M ./.local/share/Trash/files/funky chicken.mpg
346M ./Downloads/The Walking Dead S02E02 ... (dutch subs nl).avi
ANSWER 3
Score 37
For a quick view:
du | sort -n
lists all directories with the largest last.
du --max-depth=1 * | sort -n
or, again, avoiding the redundant * :
du --max-depth=1 | sort -n
lists all the directories in the current directory with the largest last.
(-n parameter to sort is required so that the first field is sorted as a number rather than as text but this precludes using -h parameter to du as we need a significant number for the sort)
Other parameters to du are available if you want to follow symbolic links (default is not to follow symbolic links) or just show size of directory contents excluding subdirectories, for example. du can even include in the list the date and time when any file in the directory was last changed.
ANSWER 4
Score 23
For most things, I prefer CLI tools, but for drive usage, I really like filelight. The presentation is more intuitive to me than any other space management tool I've seen.