
This "option" has the "benefit" of being able to be POSIX-compliant if you replace the stat call with a simple ls. Method 1: Using Find command Find is a highly flexible command used to search files based on a variety of conditions. You may have to adjust the for loop range based on your shell's integer size, or if you know how large the largest log file might be. name \*.log -size $ + syntax to pass as many filenames to stat as will fit in the environment. To exercise your system and your patience, you could search for files of a specific size in a certain order: for((i=9223372036854775807 i>=0 i-)) do find.

the real work here is done by the globstar **/*.log, which gathers matching filenames (*.log) in the current directory and any subdirectories.stat is how we gather the file sizes with their names it's installed by default on CentOS systems - it is not POSIX-specified.Also see: man ls -S sort by file size If you want to sort in reverse order, just add -r switch. sets the globstar and dotglob shell options globstar enables the use of the ** syntax to match files in subdirectories dotglob enables the shell globbing to match directories that start with a. Simply use something like: ls -lS /path/to/folder/ Capital S.runs in a sub-shell, so that the shopt statements don't affect the current/running shell.( shopt -s globstar dotglob stat -format "%s %n" - **/*.log | sort -rn )

Here are two options one bash-centric and one just for fun.
