brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: find -printf with sort shows the biggest files without using ls

Find
~/tips/tip-find-printf-biggest-files

find /srv -type f -printf '%s\t%p\n' | sort -nr | head -n 10

Prints byte sizes and paths so you can sort and find the largest files.

Parsing ls output is fragile. find can print the size and the path itself.

find /srv -type f -printf '%s\t%p\n' | sort -nr | head -n 10

%s is the size in bytes and %p is the path. The numeric reverse sort puts the biggest file on top. Swap in %TY-%Tm-%Td to print the modification date, or %u for the owner. -printf is a GNU extension. A file name that contains a newline spoils the layout, but for a quick look that rarely matters. Add -xdev when you search from the root, so other mounts do not distort the result.

Further reading: find manual page

More Find tips find / -maxdepth 1 -fstype proc find /backup -name '*.gz' ! -exec gzip -t {} \; -print 2>/dev/null find /srv/downloads -type f -size +100M -size -1G -exec ls -lh {} + find /srv/data -depth -print find /srv -xdev -samefile /srv/downloads/movie.mkv All Find tips (46) All topics

Link