Search code examples
unixsorting

Sorting file names by length of the file name


ls displays the files available in a directory. I want the file names to be displayed based on the length of the file name.

Any help will be highly appreciated. Thanks in Advance


Solution

  • You can do like this

    for i in `ls`; do LEN=`expr length $i`; echo $LEN $i; done | sort -n