• VMware

    Learn about VMware virtualization for its products like vsphere ESX and ESXi, vCenter Server, VMware View, VMware P2V and many more

  • Linux

    Step by step configuration tutorials for many of the Linux services like DNS, DHCP, FTP, Samba4 etc including many tips and tricks in Red Hat Linux.

  • Database

    Learn installation and configuration of databases like Oracle, My SQL, Postgresql, etc including many other related tutorials in Linux.

  • Life always offers you a second chance ... Its called tomorrow !!!

    Monday, October 08, 2012

    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


    0 comments:

    Post a Comment