Sorting the output of "find"?

  • I need to be able to alphabetically sort the output of find before piping it to a command. Entering | sort | between didn't work, so what could I do?

    find folder1 folder2 -name "*.txt" -print0 | xargs -0 myCommand
  • Oli

    Oli Correct answer

    9 years ago

    Use find as usual and delimit your lines with NUL. GNU sort can handle these with the -z switch:

    find . -print0 | sort -z | xargs -r0 yourcommand

License under CC-BY-SA with attribution

Content dated before 6/26/2020 9:53 AM