Deep Arora
Deep Arora

Reputation: 2040

How to sort files in a folder in Mac using Terminal?

If I have 3 files in a folder.The names of files are:

0A1c.png 
0A93.png
00A4.png

MacOS sort performs numerical sort in finder and after sorting the order of files is:

0A1c.png
00A4.png
0A93.png

Numerically, 0 and 00 are equal, there 00A4 comes before 0A93 in numerical sorting.

I need to perform character sorting based up ASCII value of each character such that the resulting order of files after sorting is:

00A4.png
0A1c.png
0A93.png

Typing the ls command in command prompt list all files sorted based upon character value which is the order I need in finder. What command can I use in terminal to perform character sorting of files in a folder?

Upvotes: 1

Views: 4809

Answers (1)

John Zwinck
John Zwinck

Reputation: 249103

Simply use sort which is alphabetical by default:

ls | sort

Upvotes: 3

Related Questions