Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to list files in natural order

📅 2015-Feb-09 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ ls, natural sort ⬩ 📚 Archive

One of the little-known options of ls is -v. It sorts the files or directories in a natural order. That is, if the file or directory name has numbers, then those files and directories are sorted in the natural order of those numbers. Like 2 comes before 101.

$ ls -v

This is one of those ls options that you might want to add to your favorite ls alias.

Tried with: CoreUtils 8.21-1 and Ubuntu 14.04


© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘 @codeyarns@hachyderm.io📧