Sort directories by number of files contained

Here is a one-liner which sorts all the directories under ‘/’ by the number of files contained: find / -type d -exec sh -c ‘ls -a1 "$1" | wc -l’ \"{}\" {} \; -print | \ sed  ‘$!N;s/\n/ /’ | sort -gr I recently needed this on a linux server where the inode quota was exceeded.Continue reading “Sort directories by number of files contained”

Bash extended pattern matching

If you don’t have extended pattern matching enabled you can enable it with shopt -s extglob From the bash manual page: If the extglob shell option is enabled using the shopt builtin, several extended pattern matching operators are recognized. In the following description, a pattern-list is a list of one or more patterns separated byContinue reading “Bash extended pattern matching”