Find files older than X days and output them by their size

files

I am trying to get the files older than a number of days and list them in descending order based on their size with all their information (size, full path etc – something similar that is provided by ls).

While I am able to locate files older with:

find . -mtime +10

I am not able to list of the desired information.

Best Answer

Provided that your file paths do not contain newline characters:

find . -mtime +10 -printf "%s %n %m %u %g %t %p" \( \
  -type l -printf ' -> %l\n' -o -printf '\n' \) | sort -k1,1 -n

See find manual, section Actions.

  • %s File's size in bytes.
  • %n Number of hard links to file.
  • %m File's permission bits (in octal).
  • %u File's user name, or numeric user ID if the user has no name.
  • %g File's group name, or numeric group ID if the group has no name.
  • %t File's last modification time in the format returned by the C ctime function.
  • %p File's name.
  • %l Object of symbolic link (empty string if file is not a symbolic link).

BTW: Note that POSIX find manual doesn't specify most of the above actions.