Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I need to show space utilisation on the system, and find the largest 3 files on /home (or any other folder)

I've been using 2 different command lines

df -m -a -h
df -m -h /home

I still can't manage to get it to show me only the 3 largest files on that folder

share|improve this question

4 Answers 4

For top 3 files, with GNU find, and assuming no filename contain newline characters:

find /path/to/dir -type f -printf "%s %p\n" |sort -nr |head -3

That gives the 3 largest files in term of file size. For disk usage instead, replace %s with %b.

share|improve this answer

For top 3 files and folders in the current directory. It will show you the largest files and folders.

du -sm ./* 2>/dev/null | sort -n -r | head -n 3

If you really insist on files only, then X Tian's solution is better.

share|improve this answer

If you're using modern GNU versions of du and sort, this will show you the sizes:

$ du -hs * | sort -hr
53G         projects
21G         Desktop
7.2G        VirtualBox VMs
3.7G        db
3.3G        SparkleShare
2.2G        Dropbox
272M        apps
47M         incoming
14M         bin
8.6M        parking_lot
5.7M        rpmbuild
76K         task.ref.pdf
68K         vimdir.tgz
share|improve this answer

With zsh, you can see the 3 largest files (in terms of size, not disk usage) with:

ls -ldh -- *(DOL[1,3])

To check for disk usage, you'd need to define a sort order like:

zmodload zsh/stat
sdu() stat -A REPLY +block -- $REPLY

And use as:

ls -ldh -- *(DnO+sdu[1,3])

If you want to search for the largest file anywhere including subdirectories, change the * above to **/*.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.