How to sort files with a certain permission by size?
In your standard bash
shell, you can do that with the find command:
find . -perm 0644 -printf '%s %p\n'| sort -nr
This finds all files and directories with permissions 0644
and prints the results formatted using the -printf
action. %s
represents the file size and %p
the file path. \n
represents a new line. The output is piped into sort
, set to sort numerically (-n
) and in reverse order (-r
).
Using the Z shell (zsh
) with its glob qualifiers:
print -rC1 *(.DNf:u=6,go=4:oL)
where the meanings are
- . matches plain files only
- D sets the GLOB_DOTS option for the current pattern
- N sets the NULL_GLOB option for the current pattern
- fspec matches files with access rights matching spec
- oL orders the results by length (size in bytes); use OL to reverse the order