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
With right-click sort Another way to sort files in a given folder is by right-clicking on the body of the folder. A pop-up will appear. Here, click on “Sort by -> Size.” The files will be sorted accordingly.
Icon view. To sort files in a different order, click the view options button in the toolbar and choose By Name, By Size, By Type, By Modification Date, or By Access Date. As an example, if you select By Name, the files will be sorted by their names, in alphabetical order. See Ways of sorting files for other options.
Use SearchMyFiles Utility Tool to Search Files with Long Names or Text. The SearchMyFiles tool by NirSoft is an effective third-party application that allows you to easily search files when their name or path length is longer than a certain number of characters.
Every operating system has a limit to how many characters can be used in a file name that is around 255 characters long. When determining the length of a file, both the file name and the file extension are used together to get the total length. For example, the file "myfile. txt" is ten characters long.
The simplest way is just:
$ ls | perl -e 'print sort { length($b) <=> length($a) } <>'
You can do like this
for i in `ls`; do LEN=`expr length $i`; echo $LEN $i; done | sort -n
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With