How to list files and directories in linux by date and time

Most of you must know the usage of 'ls'. Here I will show you some enhanced use of 'ls' with different switches where you can view the files and directories on the basis of their access and modification time along with different format of time and date.


To list all the directories on the basis of modification time

# ls -lt
drwxr-xr-x. 2 root root 4096 Oct 3 18:56 Desktop
drwxr-xr-x 4 root root 4096 Oct 3 14:16 rpmbuild
drwxr-xr-x. 2 root root 4096 Sep 8 16:00 Documents
drwxr-xr-x. 2 root root 4096 Sep 8 16:00 Music
drwxr-xr-x. 2 root root 4096 Sep 8 16:00 Pictures
drwxr-xr-x. 2 root root 4096 Sep 8 16:00 Public
drwxr-xr-x. 2 root root 4096 Sep 8 16:00 Templates
drwxr-xr-x. 2 root root 4096 Sep 8 16:00 Videos
drwxr-xr-x. 2 root root 4096 Sep 8 16:00 Downloads


To long list the files viewing the time of creation
# ls -l --time-style="+%d %m %Y"
-rw-------. 1 root root 1478 08 09 2012 anaconda-ks.cfg
drwxr-xr-x. 2 root root 4096 03 10 2012 Desktop
drwxr-xr-x. 2 root root 4096 08 09 2012 Documents
drwxr-xr-x. 2 root root 4096 08 09 2012 Downloads
-rw-r--r--. 1 root root 53828 08 09 2012 install.log
-rw-r--r--. 1 root root 10035 08 09 2012 install.log.syslog
drwxr-xr-x. 2 root root 4096 08 09 2012 Music
drwxr-xr-x. 2 root root 4096 08 09 2012 Pictures
drwxr-xr-x. 2 root root 4096 08 09 2012 Public
drwxr-xr-x 4 root root 4096 03 10 2012 rpmbuild
The same can be used with different time switches
# ls -l --time-style=+%D
-rw-------. 1 root root 1478 09/08/12 anaconda-ks.cfg
drwxr-xr-x. 2 root root 4096 10/03/12 Desktop
drwxr-xr-x. 2 root root 4096 09/08/12 Documents
drwxr-xr-x. 2 root root 4096 09/08/12 Downloads
-rw-r--r--. 1 root root 53828 09/08/12 install.log
-rw-r--r--. 1 root root 10035 09/08/12 install.log.syslog
drwxr-xr-x. 2 root root 4096 10/08/12 Music
drwxr-xr-x. 2 root root 4096 09/08/12 Pictures
drwxr-xr-x. 2 root root 4096 09/08/12 Public