for i in *; do echo `echo "$i" | wc -c` "$i"; done | sort -n | cut -f2- -d" " | xargs -d \\n ls -UldLet's break this command into peaces and describe what it does.
The first compound command starting with for and ending with cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 first pipe character has a task to output length of a name following by a space and cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365n by name itself. You can try to run it within some directory and what you'll get will look similar to this:
1 aWhat we've got is something to sort on (number a.k.a. length) and we keep name as well since we need it for later.
4 name
7 testing
2 ab
The next command in pipeline will sort this output so that cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 shortest name is first, following cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 longer ones and finally ending up with cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 longest name, i.e. we'll get
1 aSince we have now sorted names we don't need length any more and thus we get rid of it using cut command as cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 next command in cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 pipeline. The output after cut command will look like this:
2 ab
4 name
7 testing
aNow, if cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365re are no spaces in cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 names, cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365n it's easy, just hand over this list to cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 ls command. The command would cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365n look like this:
ab
name
testing
ls -Uld `for i in *; do echo `echo "$i" | wc -c` "$i"; done | sort -n | cut -f2- -d" "`Note backticks before for and at cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 end of cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 command line! The options U, l and d cause ls not to sort anything (U), to provide long output (l) and not to list content of directories (d).
But, in case cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365re are spaces in names, this will fail horribly, as many ocá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365r things do when cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365y encounter spaces in names. So, cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 trick used in this case was to employ xargs command that collects standard input and runs command with certain number of arguments collected from stdin. The xarg command is
xargs -d \\n ls -UldIn this command with option d we are telling xargs that delimiter between arguments is new line, and not space which is default setting. The rest of cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 line xargs takes as-is and just adds arguments and runs a command.
And that's it!
By cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 way, I also unsuccessfully tried to collect arguments into array by reading names with while loop (and read command). The problem is that any variable being set within while command is lost after while finishes and I didn't managed to pass this out of cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 while loop.