Listing and Sorting Files


Listing files by access date.

You can use the “-ltur” option. The “u” enforces the “by access date” listing order.  The “t” option to list files in order of age. The “r” option is to reverse the option

$ ls -ltur
-rwxr-xr-x  1 user1 users 1622374400 Mar 10 00:08 yyyy.iso
-rw-rw-r--  1 user1 users   18387452 Mar 13 14:06 xxxx.rpm
-rwxr-xr-x  1 user1 users        303 Mar 30 16:32 visJob.pbs
-rw-------  1 user1 users        762 Mar 30 16:35 visJob.o1475403
-rw-------  1 user1 users         59 Mar 30 16:35 visJob.e1475403

Listing Files by Modified Date and Time

You can use the “-ltr” option. The “r” is the reverse order.

$ ls -ltr
-rw-rw-r--  1 melvin melvin   18387452 Mar 13 14:03 xxxx.rpm
-rwxr-xr-x  1 melvin melvin        303 Mar 13 17:00 vis.pbs
-rw-rw-r--  1 melvin melvin       1084 Mar 23 16:52 yyy.pem

Listing files by owner

Use the output of the ls command to sort and pick out the owner column by adding “-k3” to sort on the third field.

$ ls -l | sort -k3 | more
drwx------  29 www           users                 1005 Sep 20  2022 www-home
drwx------  16 yyy           users                  684 Apr  3 14:07 yyy-home
drwx------  16 zzz           users                  746 Mar 21 11:31 zzz-home

Listing files by group

Sort files by the associated groups, you can pass the output from a long listing to the sort command and tell it to sort on column 4.

$ ls -l | sort -k4 | more
drwx------  29 www           users1                 1005 Sep 20  2022 www-home
drwx------  16 yyy           users2                  684 Apr  3 14:07 yyy-home
drwx------  16 zzz           users3                  746 Mar 21 11:31 zzz-home

Listing files by size

To sort files by Size, use the “-S” Option. If you wish to put the largest files at the end, use the “-r”. Use the “-h” to be human readable.

ls -lSrh
-rw-rw-r--  1 www users 1.9G Nov 15 11:04 integr8_120.xml.gz
-rw-rw-r--  1 www users 6.0G Jul 26  2022 20220712_msconvert.zip
-rw-rw-r--  1 www users 6.9G May 31  2022 ELECTRONICS.tgz

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.