sortingunixlsfile-listingfile-sorting

linux ls -ltr sort by name


I see many questions on this site on ls sorting
But what I need is a sorted output ls -ltr (sorted by file name)
Because I need the file sizes and dates as well for comparison.
I tried | sort -k, | sort, ls-1ltr without success.

This is the unsorted list:

ser@xeroxsqa02:/app/java/jars> ls -ltr
total 41940
-rwxr-xr-x 1 xeroxadmin mqm  331471 May 10  2017 spring-aop-3.1.1.RELEASE.jar
-rwxr-xr-x 1 xeroxadmin mqm  153115 May 10  2017 jdom-1.1.jar
-rwxr-xr-x 1 xeroxadmin mqm  185140 May 10  2017 commons-io-2.4.jar
-rwxr-xr-x 1 xeroxadmin mqm  279193 May 10  2017 commons-lang-2.5.jar
-rwxr-xr-x 1 xeroxadmin mqm  489884 May 10  2017 log4j-1.2.17.jar
-rwxr-xr-x 1 xeroxadmin mqm   53081 May 10  2017 spring-asm-3.1.1.RELEASE.jar
-rwxr-xr-x 1 xeroxadmin mqm 2095932 May 10  2017 ojdbc5-11.2.0.3.0.jar
-rwxr-xr-x 1 xeroxadmin mqm    4467 May 10  2017 aopalliance-1.0.jar
-rwxr-xr-x 1 xeroxadmin mqm   38460 May 10  2017 joda-convert-1.2.jar
-rwxr-xr-x 1 xeroxadmin mqm 1891110 May 10  2017 guava-13.0.1.jar
-rwxr-xr-x 1 xeroxadmin mqm  589824 May 10  2017 spring-beans-3.1.1.RELEASE.jar
-rwxr-xr-x 1 xeroxadmin mqm  449324 May 10  2017 spring-core-3.1.1.RELEASE.jar
-rwxr-xr-x 1 xeroxadmin mqm  232019 May 10  2017 commons-beanutils-1.8.3.jar
-rwxr-xr-x 1 xeroxadmin mqm  831068 May 10  2017 spring-context-3.1.1.RELEASE.jar
-rwxr-xr-x 1 xeroxadmin mqm  569231 May 10  2017 joda-time-2.0.jar
-rwxr-xr-x 1 xeroxadmin mqm   52915 May 10  2017 commons-logging-1.1.jar
-rwxr-xr-x 1 xeroxadmin mqm  107225 May 10  2017 spring-context-support-3.1.1.RELEASE.jar
-rwxr-xr-x 1 xeroxadmin mqm  176311 May 10  2017 spring-expression-3.1.1.RELEASE.jar
drwxr-xr-x 2 xeroxadmin mqm      46 Jun 30  2017 bkp
-rwxr-xr-x 1 xeroxadmin mqm 1599570 Jan 17 19:12 axis-1.4.jar
-rwxr-xr-x 1 xeroxadmin mqm   79796 Jan 17 19:12 commons-discovery-0.5.jar
-rwxr-xr-x 1 xeroxadmin mqm  148429 Jan 17 19:12 wsdl4j-1.6.2.jar

Solution

  • Have you tried following:

    ls -lru
    

    Per man page:

    -u with -lt: sort by, and show, access time; with -l: show access time and sort by name; otherwise: sort by access time, newest first