Score:0

Find Largest Directories/Files when Drive is Full

gr flag

When the drive of an Ubuntu 20.04 server is full, how can we find out the directories/files with the largest sizes, ranked from largest to smallest? This can allow me to find some files to delete (likely log files)

Tried installing ncdu but theres insufficient space

# sudo apt install ncdu
Reading package lists... Error!
E: Write error - write (28: No space left on device)
E: Write error - write (28: No space left on device)
E: The package lists or status file could not be parsed or opened.

Tried du with sort but it cant run with no disk space left.

# du --max-depth=7 /* | sort -n 
sort: write failed: /tmp/sort5SKbZn: No space left on device

df -h Output:

# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            474M     0  474M   0% /dev
tmpfs            99M   11M   88M  12% /run
/dev/vda1        25G   25G     0 100% /
tmpfs           491M   40K  491M   1% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           491M     0  491M   0% /sys/fs/cgroup
/dev/loop0       56M   56M     0 100% /snap/core18/2066
/dev/loop2       68M   68M     0 100% /snap/lxd/20326
/dev/vda15      105M  7.9M   97M   8% /boot/efi
tmpfs            99M     0   99M   0% /run/user/0
overlay          25G   25G     0 100% /var/lib/docker/overlay2/183819e24cd73185c27ef0af229e31e909f4af51dd7a4e0178eeab68a2f924e1/merged
/dev/loop3       33M   33M     0 100% /snap/snapd/12398
/dev/loop4       56M   56M     0 100% /snap/core18/2074
shm              64M   16K   64M   1% /var/lib/docker/containers/fdcf13f925676b32eaac67a55ff245d4ed7f0c91c78db26169106af56b15e77f/mounts/shm
/dev/loop5       71M   71M     0 100% /snap/lxd/21029
/dev/loop6       33M   33M     0 100% /snap/snapd/12704
N0rbert avatar
zw flag
`sudo apt clean` is a good first step. `mc` can help you too, it can calculate directory sizes.
Score:2
es flag

If you can ssh from a different machine, then you can pipe the output to sort on the machine that is not full. Let's say that you have two machines -- slim (which doesn't have a full hard drive) and full, which does.

From the command prompt on slim:

ssh user@full 'du -sh /' | sort -h

The first part:

ssh user@full 'du -sh /'

generates output from full. The pipeline | sort -h is running locally on slim, so you won't get errors about disk space.

Athena Wisdom avatar
gr flag
Nifty idea! Trying it out
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.