Display Human-Readable File Sizes in Find Results – How to Guide

findlsshell

I'm trying to find all large files on my Centos server. To do that I'm using:

find / -maxdepth 10 -size +100000 -ls

I tried changing -ls to -lsh but it is not allowed.

How can I display these results with human-readable sizes (using suffixes k, M, …)?

Best Answer

find doesn't have sophisticated options like ls. If you want ls -h, you need to call ls.

find / -maxdepth 10 -size +100000 -exec ls -lh {} +

I recommend the -xdev option to avoid recursing into other filesystems, which would be useless if you're concerned about disk space.

find / -xdev -maxdepth 10 -size +100000 -exec ls -lh {} +

If you use zsh as your shell, then instead of using find, you can use glob qualifiers. Limiting the file size is simple: L followed by a size; the size can have an optional unit before the number. If you don't care about the maximum depth, you can use **/ to recurse into subdirectories. If you care about maximum depth, it's more cumbersome as zsh glob patterns lack a way to express “at most n occurrences”. To avoid cross-device recursion, use the d glob qualifier; you need to find the device number, which you can display with the stat command under Linux (stat -c %d / to display just the number) or with zsh's own stat builtin (run zmodload zsh/stat to load it).

ls -lh /**/*(L+M99d$(stat -c %d /))
Related Question