2

What do I need to do if I want to list all the files (not directories) and their size, with their sizes sorted from largest to smallest? I tried find . -type f -exec ls -Shl {} \; but it does list the files in order (of their size). Anyone can help??

Suky Zhang
  • 25
  • 1
  • 1
  • 3

1 Answers1

7

Use + instead of \;.

find . -type f -exec ls -Shl {} +

\; calls ls once per file whereas + calls it a single time with all the matched file names.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
  • 1
    The `+` does not process all files, well that depends on how much files is there to process. With the `+` find will process as much files as possible while avoiding `argmax` see https://www.in-ulm.de/~mascheck/various/argmax/ You know the error that says `list arguments too long` see https://stackoverflow.com/questions/11289551/argument-list-too-long-error-for-rm-cp-mv-commands – Jetchisel Feb 13 '20 at 21:35