List files by modification date with the ls command on Linux.

Posted: July 9, 2015. At: 12:42 PM. This was 3 years ago. Post ID: 8262
Page permalink.
WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters. These cookies expire two weeks after they are set.

This one-liner will list all files in a directory by modification time, newest first.

[email protected]:~/Pictures$ ls -thul

Use it this way to list the top 20 files listed.

jason@eyjafjallajkull:/var/log$ ls -thul | head -n 20
total 6.9M
-rw-rw-r-- 1 root              utmp 9.0K Jul  9 11:30 wtmp
-rw-r--r-- 1 root              root  85K Jul  9 11:26 Xorg.0.log
-rw-r--r-- 1 root              root    0 Jul  9 11:26 netserver.debug_1797
-rw-r--r-- 1 root              root  14K Jul  9 11:26 boot.log
-rw-r--r-- 1 root              root  32K Jul  8 11:14 faillog
-rw-r----- 1 syslog            adm   11K Jul  8 11:10 auth.log
drwxr-xr-x 2 root              root 4.0K Jul  8 11:09 apt
-rw-r----- 1 syslog            adm  105K Jul  8 10:55 kern.log
-rw-r----- 1 syslog            adm  392K Jul  8 10:55 syslog
drwxr-xr-x 2 root              root  12K Jul  8 10:55 upstart
drwxr-x--- 2 mysql             adm  4.0K Jul  8 10:55 mysql
drwxr-xr-x 2 root              root 4.0K Jul  8 10:55 cups
-rw-r--r-- 1 root              root  85K Jul  8 10:43 Xorg.0.log.old
-rw-r--r-- 1 root              root    0 Jul  8 10:43 netserver.debug_1704
-rw------- 1 root              utmp    0 Jul  2 01:59 btmp
-rw-r----- 1 syslog            adm  214K Jul  2 01:59 syslog.1
-rw-r--r-- 1 root              root    0 Jul  2 01:59 alternatives.log
-rw-r--r-- 1 root              root  33K Jul  2 01:59 dpkg.log
-rw-rw-r-- 1 root              utmp 112K Jul  2 01:52 wtmp.1

Use ls this way to list by file size.

jason@eyjafjallajkull:/var/log$ ls -S -luh | head -n 20
total 6.4M
-rw-r--r-- 1 root              root 673K Sep 26  2014 vnetlib
-rw-r----- 1 syslog            adm  544K Jun 29 08:41 kern.log.1
-rw-r----- 1 root              root 538K Apr 30 19:24 lynis.log
-rw-r--r-- 1 root              root 529K Sep 26  2014 vmware-installer
-rw-r----- 1 syslog            adm  397K Jul  8 10:55 syslog.1
-rw-r--r-- 1 root              root 290K Apr 12 21:43 udev
-rw-rw-r-- 1 root              utmp 286K Jun 16 23:42 lastlog
-rw-r----- 1 syslog            adm  260K Jun 18 18:35 syslog.7.gz
-rw-r--r-- 1 root              root 252K Jun 16 23:02 dpkg.log.1
-rw-r----- 1 root              root 200K Apr 30 18:56 lynis-report.dat
-rw-r----- 1 syslog            adm  190K Jun  9 08:52 kern.log.3.gz
-rw-r--r-- 1 root              root 183K Dec 30  2014 dpkg.log.7.gz
-rw-r----- 1 syslog            adm  148K Jun  1 12:07 kern.log.4.gz
-rw-r--r-- 1 root              root 135K Jul 23  2014 dpkg.log.10.gz
-rw-rw-r-- 1 root              utmp 112K Jul  2 01:52 wtmp.1
-rw-r----- 1 syslog            adm  109K Jun 26 01:55 syslog.5.gz
-rw-r----- 1 syslog            adm  105K Jul  8 10:55 kern.log
-rw-r--r-- 1 root              root  94K Mar 22 11:05 dpkg.log.4.gz
-rw-r--r-- 1 root              root  85K Jul  8 10:43 Xorg.0.log.old

List numeric user and group uids this way.

ubuntu ~/Documents $ ls -n
total 20276
-rwxrwxr-x 1 1000 1000     8510 May  3 23:24 a.out
-rw-rw-r-- 1 1000 1000     1530 Mar 20 03:11 hashes.out
-rw-rw-r-- 1 1000 1000     2496 Jun 18 03:33 hole.o
drwxrwxr-x 6 1000 1000     4096 Mar 20 02:46 impacket-read-only
-rw-rw-r-- 1 1000 1000     1118 May  3 23:24 my.c
-rw-rw-r-- 1 1000 1000      995 Mar 18 03:19 nikto-pinterest-log.log
drwxrwxr-x 3 1000 1000     4096 Mar 20 02:37 python
-rwxrwxr-x 1 1000 1000     7741 Mar 20 02:12 recipe-502268-1.py
-rw-rw-r-- 1 1000 1000    65536 Mar 20 03:02 sam.save
-rwxrwxr-x 1 1000 1000    64259 Mar 20 02:44 secretsdump.py
-rw-rw-r-- 1 1000 1000    32768 Mar 20 03:03 security.save
-rw-rw-r-- 1 1000 1000 20545536 Mar 20 03:03 system.save
-rw-rw-r-- 1 1000 1000     7754 Jun 18 03:31 virii.S

No comments have been made. Use this form to start the conversation :)

Leave a Reply