combine the best of 'du' and 'tree'
Also checkout ncdu: http://dev.yorhel.nl/ncdu
Its page also lists other "similar projects":
gt5 - Quite similar to ncdu, but a different approach.
tdu - Another small ncurses-based disk usage visualization utility.
TreeSize - GTK, using a treeview.
Baobab - GTK, using pie-charts, a treeview and a treemap. Comes with GNOME.
GdMap - GTK, with a treemap display.
Filelight - KDE, using pie-charts.
KDirStat - KDE, with a treemap display.
QDiskUsage - Qt, using pie-charts.
xdiskusage - FLTK, with a treemap display.
fsv - 3D visualization.
Philesight - Web-based clone of Filelight.
You don't need to grep for the colour code, the -d
option is list directories only
.
This seems to do what you want:
$ tree --du -d -shaC | grep -Ev '( *[^ ]* ){2}\['
.
├── [ 18] dir1
├── [ 30] dir2
├── [ 205] junk
│ ├── [ 18] dir1
│ ├── [ 30] dir2
│ └── [ 76] dir3
├── [ 119] merge
└── [ 20] stuff
4.4K used in 10 directories
The grep
command removes all lines that have (one or more spaces followed by a non-space followed by a space) twice, followed by a [
.
If you want a depth of 1, change the bound count inside the {} curly braces to {1}
rather than {2}
. same if you want a depth of 3, change it to {3}
.
You can turn this into a shell function, like so:
mytreedu() {
local depth=''
while getopts "L:" opt ; do
case "$opt" in
L) depth="$OPTARG" ;;
esac
done
shift "$((OPTIND-1))"
if [ -z "$depth" ] ; then
tree --du -d -shaC "$@"
else
local PATTERN='( *[^ ]* ){'"$depth"'}\['
tree --du -d -shaC "$@" | grep -Ev "$PATTERN"
fi
}
This uses getopts
to "steal" any -L
option and its argument from the tree
command line, if there is one. If there isn't a -L n
option on the command line, then that works too.
All other options and args are passed to the tree
command.
The local PATTERN=...
line isn't really necessary. I only did it like that to make sure that it would fit on one line and not word-wrap here on U&L
. The regular expression could and probably should just go directly on the tree | grep ...
line.
Run it like this:
mytreedu
or
mytreedu -L 2 /path/to/dir/
You can use dutree
- coloured output, according to the LS_COLORS environment variable.
- display the file system tree
- ability to aggregate small files
- ability to exclude files or directories
- ability to compare different directories
- fast, written in Rust