0

I need to show my root / directory file cumulative size with deep level 1 Its looks easy but I can't run which deserve

tree command doesn't show cumulative size

tree --du -h -L 1 
.
├── [   7]  bin -> usr/bin
├── [4.0K]  boot
├── [ 21K]  desktopfs-pkgs.txt
├── [4.2K]  dev
├── [ 12K]  etc
├── [4.0K]  home
├── [   7]  lib -> usr/lib
├── [   7]  lib64 -> usr/lib
├── [ 16K]  lost+found
├── [4.0K]  media
├── [4.0K]  mnt
├── [4.0K]  opt
├── [   0]  proc
├── [4.0K]  root
├── [4.8K]  rootfs-pkgs.txt
├── [ 800]  run
├── [   7]  sbin -> usr/bin
├── [  19]  snap -> /var/lib/snapd/snap
├── [4.0K]  srv
├── [   0]  sys
├── [ 520]  tmp
├── [4.0K]  Untitled Folder
├── [4.0K]  usr
└── [4.0K]  var

Also, du command

du -h -d 1 /
8,0K    /media
du: cannot read directory '/sys/kernel/tracing': Permission denied
du: cannot read directory '/sys/kernel/debug': Permission denied
du: cannot read directory '/sys/fs/pstore': Permission denied
du: cannot read directory '/sys/fs/bpf': Permission denied
0   /sys
166G    /mnt
du: cannot read directory '/run/udisks2': Permission denied
du: cannot read directory '/run/wpa_supplicant': Permission denied
du: cannot read directory '/run/user/1000/systemd/inaccessible/dir': Permission denied
du: cannot read directory '/run/svnserve': Permission denied
du: cannot read directory '/run/sudo': Permission denied
du: cannot read directory '/run/lightdm': Permission denied
du: cannot read directory '/run/lock/lvm': Permission denied
du: cannot read directory '/run/systemd/unit-root': Permission denied
du: cannot read directory '/run/systemd/inaccessible/dir': Permission denied
1,6M    /run
du: cannot read directory '/home/max/.cache/yay/wine-stable/pkg': Permission denied
du: cannot read directory '/home/max/.cache/yay/gnuradio-git/pkg': Permission denied
du: cannot read directory '/home/max/.cache/yay/pamac-classic/pkg': Permission denied
du: cannot read directory '/home/max/.cache/yay/wine-stable-next/pkg': Permission denied
du: cannot read directory '/home/max/.cache/yay/pamac-aur/pkg': Permission denied
du: cannot read directory '/home/max/.cache/paru/clone/qm-dfu-util-git/pkg': Permission denied
du: cannot read directory '/home/lost+found': Permission denied
146G    /home
.
.
.
Goes so on

I need only 1 deep level but du -h -d 1 / command shows permission denies. How can I ignore them for the cleanest view I tried to give root permission but shows minor errors

sudo du -h -d 1 /
8,0K    /media
0   /sys
166G    /mnt
du: cannot access '/run/user/1000/gvfs': Permission denied
1,6M    /run
146G    /home
du: cannot access '/proc/12363/task/12363/fd/4': No such file or directory
du: cannot access '/proc/12363/task/12363/fdinfo/4': No such file or directory
du: cannot access '/proc/12363/fd/3': No such file or directory
du: cannot access '/proc/12363/fdinfo/3': No such file or directory
0   /proc
19M /etc
16K /lost+found
0   /dev
49G /usr
41G /var
4,0K    /Untitled Folder
9,1M    /srv
2,6G    /opt
1,8M    /root
51M /tmp
98M /boot
403G    /

I glanced many example on web those commands looks great but mine terminal which Shell: bash 5.1.0 under default Manjaro looks a little bit away from perfect

2 Answers2

1

You can simply filter out the errors by redirecting stderr to /dev/null.

sudo du -h -d 1 / 2>/dev/null

Another possibility without specifying the depth, but using a wildcard instead would be:

sudo du -sh /* 2>/dev/null
Panki
  • 6,664
1

When inspecting disk usage, the content of virtual file systems (for instance, on my GNU/Linux: /dev, /proc, /run, /sys and /tmp) is usually not relevant. Excluding them makes things easier.

Using du, if you are fine with only listing the content of the file system mounted on / (ignoring that of other mount points), you can run:

sudo du -h -d1 -a -x /

Or, if you prefer not to use the -x ("one file system") option:

sudo du -h -d1 -a --exclude=/dev --exclude=/proc \
  --exclude=/run --exclude=/sys --exclude=/tmp /

(-a makes du show regular files as well).

While tree can not limit the depth of its output with -L and also show the full-depth size of directories (i.e. including all the contained subdirectories an files), you can let it produce formatted output and filter it afterwards. For instance, using JSON and jq:

sudo tree --du -a -x -h -J / | jq 'del(.[]?[]?[]?[]?[]?)'

(Unfortunately, tree's JSON output tends to contain malformed bits, making this solution quite unreliable).

You may also refer to Tracking down where disk space has gone on Linux? if you are interested in tools other than those mentioned in your question.

fra-san
  • 10,205
  • 2
  • 22
  • 43