LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-26-2022, 05:08 AM   #1
progama
LQ Newbie
 
Registered: Aug 2018
Posts: 7

Rep: Reputation: Disabled
list dirs and subdirs using most disk space in a tree format


Hello All!!

I'm looking for regular shell commands to achieve the following. Let's say I have a large dir (several hundred Gigs) and I want to find out which dirs/subdirs are utlizing most space beginning from the main dir and want to be able to choose how many dirs and subdirs to be displayed:

>cd main_dir
>command <display 5 entry in main dir> <choose depth 2> <display no of entries at each depth 4>

size X
size X1
size X2
size X3
size X4
size Y
.....similar to X.

All results are in decreasing order.

Thanks!
 
Old 01-26-2022, 06:11 AM   #2
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 446Reputation: 446Reputation: 446Reputation: 446Reputation: 446
There's a command ncdu that works a bit like that. It's interactive, so when you start it, it displays the size of all sub-directories. And you can browse the sub-directories with usage.

You probably need to install it, as it's not installed by default. When you have, type "man ncdu" for options and examples. I don't think it has a max depth, but you can export the report in a cron script, and browse it later.
 
Old 01-26-2022, 06:17 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,804

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
and you can use du too:
Code:
du -sh *| sort -hr
 
1 members found this post helpful.
Old 01-26-2022, 07:35 AM   #4
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,371

Rep: Reputation: 2748Reputation: 2748Reputation: 2748Reputation: 2748Reputation: 2748Reputation: 2748Reputation: 2748Reputation: 2748Reputation: 2748Reputation: 2748Reputation: 2748
This is a little script that I use. For long listings I pipe the output to a pager like less.
Code:
#!/bin/bash

# Script to show a quick summary of a directory's disk usage.
# Defaults to current directory

DIR=${1:-$(pwd)}
# Handle the "." directory case so that grep works
[[ $DIR == "." ]] && EDIR="\." || EDIR=$DIR
du -c "$DIR" | grep  -v "$EDIR$"  | sort -k1nr
 
Old 01-26-2022, 07:56 AM   #5
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
Quote:
Originally Posted by Guttorm View Post
I don't think it has a max depth
But then gt5 definitely has it: both --max-depth and --max-lines.

dutree and durep have similar options:

dutree: -d/--depth and -a/--aggr

durep: -td/--text-depth and -hs/--hide-size

Last edited by shruggy; 01-26-2022 at 08:31 AM.
 
Old 01-26-2022, 08:18 AM   #6
progama
LQ Newbie
 
Registered: Aug 2018
Posts: 7

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Guttorm View Post
There's a command ncdu that works a bit like that. It's interactive, so when you start it, it displays the size of all sub-directories. And you can browse the sub-directories with usage.

You probably need to install it, as it's not installed by default. When you have, type "man ncdu" for options and examples. I don't think it has a max depth, but you can export the report in a cron script, and browse it later.
Thanks Guttorm! I tried ncdu but for larger dirs it simply crashes
 
Old 01-26-2022, 11:11 AM   #7
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 446Reputation: 446Reputation: 446Reputation: 446Reputation: 446
Hmm. I've used it for big volumes and many millions files, and I can't remember seeing it crash. Just very slow on very many files.

When there are lots of files/directories, it probably needs a lot of RAM, but I have plenty. Any error messages?

Maybe try the other solutions? I think a max-depth would help here.
 
Old 01-26-2022, 12:32 PM   #8
progama
LQ Newbie
 
Registered: Aug 2018
Posts: 7

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Guttorm View Post
Hmm. I've used it for big volumes and many millions files, and I can't remember seeing it crash. Just very slow on very many files.

When there are lots of files/directories, it probably needs a lot of RAM, but I have plenty. Any error messages?

Maybe try the other solutions? I think a max-depth would help here.
No error message as such unfortunately. It will simply exit.
 
Old 01-28-2022, 03:30 AM   #9
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,804

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
you can always check $?.
And in such cases strace may give additional info.
 
Old 01-28-2022, 09:36 AM   #10
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,781

Rep: Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198
Code:
du -axh | sort -h
If you don't mind a mix of filesndirs.
Note: the -x skips sub mounts.
 
  


Reply

Tags
du



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Trying to deal with .config/user-dirs.dirs nix84 Fedora 3 10-12-2015 02:37 AM
[SOLVED] Apple gcc: Insert include dirs between -I dirs and -isysroot dirs f.barker Programming 1 11-11-2011 10:19 AM
sorting and displaying dirs and subdirs by the amount of files they contain basher400 Linux - Newbie 9 06-15-2009 03:00 AM
Freeing space; deleting subdirs after installs intermod Linux - General 2 01-01-2008 03:58 PM
xgettext: How to parse entire directory structure (dirs/subdirs) Muffe Linux - Software 1 04-28-2006 09:52 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration