Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Sort bash find results before opening files

I’m on MacOSX 12.6, the following terminal command opens all the files I need, but it would be far more useful if the files opened in alphabetical order. For some reason everything is found, but opens in random order.

cd /Volumes/Disk2/Books; find ./ -type f -regex '.*[advert]_00[1-5]_2023\.pdf' -exec open {} \;

I can’t see anything in the find documentation to affect sort order in the output. Previous answers to this type of question don’t appear to work with ”-exec open’ (I might be doing this wrong, sorry, inexperienced, I’m here to learn!)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Instead of

find whatever -exec open {} \;

do

find whatever | sort | xargs -n 1 open

That’s assuming your file names don’t contain newlines.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading