# A Shorty But a Goody, Sorting mdfind Results by Date or Size

DevFeed: [A Shorty But a Goody, Sorting mdfind Results by Date or Size](<https://devfeed.tech/articles/a-shorty-but-a-goody-sorting-mdfind-results-by-date-or-size-28213.md>)

Original publisher: [Read original article](<http://fuzzyblog.io/blog/osx/2020/08/12/a-shorty-but-a-goody-sorting-mdfind-results-by-date.html>)

Author: Fuzzygroup

Published: 2020-08-12T05:48:00Z

Content type: tutorial

Language: en

Sources: [Scott Johnson](<https://devfeed.tech/sources/scott-johnson.md>)

Topics: [Command-line interface](<https://devfeed.tech/topics/cli.md>), [Unix](<https://devfeed.tech/topics/unix.md>), [ls](<https://devfeed.tech/topics/ls.md>), [Sorting](<https://devfeed.tech/topics/sorting.md>)

Tags: [apple](<https://devfeed.tech/tags/apple.md>), [command](<https://devfeed.tech/tags/command.md>), [command-line](<https://devfeed.tech/tags/command-line.md>), [files](<https://devfeed.tech/tags/files.md>), [hacks](<https://devfeed.tech/tags/hacks.md>), [ls](<https://devfeed.tech/tags/ls.md>), [mdfind](<https://devfeed.tech/tags/mdfind.md>), [osx](<https://devfeed.tech/tags/osx.md>), [sorting](<https://devfeed.tech/tags/sorting.md>), [unix](<https://devfeed.tech/tags/unix.md>)

## AI overview

A short tutorial showing how to pipe mdfind results through xargs to list files sorted by modification date or calculate and sort file sizes.

## Source excerpt

mdfind is an OSX executable which taps into the underlying spotlight index to find files quickly. However if you want to quickly sort results you need to pipe its output (the symbol i.e. shift key + forward slash) into another program. The program we are going to send its results to is xargs which then handles integrating the results from mdfind with another command and organizing the results. Note: I regard xargs as "Unix Dark Magic"; I've never fully understood it but it is one of those things that when I need a powerful command line incantation, I tend to think "Hm.... Needs Me Some xargs Here". Sorting by File Date To sort files by name, make a variant of this: mdfind -name url_common.rb -0 | xargs -0 ls -lt Sorting by File Size To sort files by file size, make a variant of this: mdfind -name url_common.rb -0 | xargs -0 du -hc | sort -g This one is interesting because it pipes from mdfind to xargs running du -hc and then to sort. See Also Apple.com Hacks for Macs