Disk Management – How to Manage Disk Size

devicesdiskdisk-usagefilesystems

I am using Fedora 16. My /dev/sda2, mounted on / (root) with something like 50G got filled 100%:

[foampile@~ 13:13:39]> df
Filesystem     1K-blocks     Used Available Use% Mounted on
rootfs          51606140 49025452         0 100% /
devtmpfs         2988452        0   2988452   0% /dev
tmpfs            2999424       96   2999328   1% /dev/shm
/dev/sda2       51606140 49025452         0 100% /
tmpfs            2999424    51992   2947432   2% /run
tmpfs            2999424        0   2999424   0% /sys/fs/cgroup
tmpfs            2999424        0   2999424   0% /media
/dev/sda1          99150    79569     14461  85% /boot
/dev/sda5      247972844 10782056 224594412   5% /home

Q1: Is there a command, or an option with ls, which will list all the files under a directory recursively and sort them in the descending order by size? I would like to see which files/dirs are hogging the device.

Q2: My /home is relatively unused. is there a way to repartition the disk and switch some disk space from /dev/sda5 (/home) to /dev/sda2?

Thanks

Best Answer

Q1. Try something like sudo du -a -m -x | sort -k1n -r | head -n40. The -a flag to du says to be recursive. The -m flag displays sizes in MB. The -x stays on a single filesystem. This will list both files and directories, and only the 40 largest (because of the -n40 option to head). Some du implementations have a -t SIZE option to only display entries whose size exceeds SIZE.

To list files only, you could try instead something like: find / -xdev -type f -size +1M -ls. That will list only files on the same filesystem as / whose size exceeds 1 MB.

Q2. Almost certainly. But you should ask about this separately, or search (here or elsewhere) on keywords like "linux" and "repartition" because I've seen it discussed very often. Here are some previous Qs on this site:

Related Question