Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Get the latest dates for the directories  (Read 4106 times)

0 Members and 1 Guest are viewing this topic.

muddasani

    Topic Starter


    Starter

    Get the latest dates for the directories
    « on: April 22, 2009, 07:31:58 AM »
    hi,

    Please guide me what is the command to get the latest date of the files that is equal the directorie date

    ex: the directoriy date of abc is 12 feb 2008
    in abc directory the files and the dates are below
    10 feb 2008 a.txt 
    11 feb 2008 b.txt
    15 feb 2008 c.txt


    by using which command or function to get abc directory date will give as 15 feb 2008

    gh0std0g74



      Apprentice

      Thanked: 37
      Re: Get the latest dates for the directories
      « Reply #1 on: April 22, 2009, 08:55:32 AM »
      i don't understand. please describe more clearly.  your abc directory date is 12 Feb, but there's no files like that with 12 Feb.

      muddasani

        Topic Starter


        Starter

        Re: Get the latest dates for the directories
        « Reply #2 on: April 25, 2009, 08:57:31 AM »
        take this real time example....

        here directory date is nov 20 2007

        where as the file dates are nov 21 2007

        drwxrwsr-x   Nov 20  2007   /programs/postanalysis/output
        -rw-rw-r--      Nov 21  2007   /programs/postanalysis/output/a.wmf
        -rw-rw-r--      Nov 21  2007   /programs/postanalysis/output/a.doc


        thanks,
        muddasani

        banjo67xxx



          Beginner

          Thanked: 4
          • Certifications: List
          • Computer: Specs
          • Experience: Guru
          • OS: Linux variant
          Re: Get the latest dates for the directories
          « Reply #3 on: April 25, 2009, 12:33:43 PM »
          I need to explain the filesystem structure so that you can understand why it appears like it does.

          Every object has at least 3 dates associated with it: creation time, modify time, and last accessed time, maybe attribute change time too. These are stored in what's called an inode. The inode contains a flag which identifies if the object is a file or directory (or other things) and the block address(es) of the data.

          What's important to note is that a directory data block only contains the filename and its inode address.

          When you create/copy a file, rename/move a file or delete a file you will update the modification time of the directory because you've had to add, edit or remove entries from the directory.

          However, in your case the files a.wmf and a.doc were created on or before 20 Nov 07, and then they were editted on 21 Nov 07. The point is that the filenames a.wmf and a.doc were not renamed on 21 Nov 07 so that's why the directory wasn't modified.

          If you want to find the last modify time of any file within a directory (but not sub-directories) then you could do

          cd /programs/postanalysis/output
          ls -lat | tail +2 | head -1


          Finding the last modify time of a file anywhere in a directory tree would have to involve some combination of find and sort, but that's not so easy to write off the top of my head.