How we get last created folder in one folder

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rahulhere
    New Member
    • Apr 2007
    • 3

    How we get last created folder in one folder

    How we pick last created file name of a folder
  • michaelb
    Recognized Expert Contributor
    • Nov 2006
    • 534

    #2
    I assumed (from the title) that you don't need to look recursively into subdirectories.
    If this is the case you can try this command
    Code:
    ~/public_html> ls -tAF | grep '/$' | head -1
    include/
    ~/public_html>
    It is of course a bit ugly...

    Comment

    • michaelb
      Recognized Expert Contributor
      • Nov 2006
      • 534

      #3
      I just realized that I did not get your question right - you are looking for the last updated file in the directory... In this case the code needs a tweak:

      Code:
      ~>  ls -tAF | grep -v '/$' | head -1

      Comment

      • ghostdog74
        Recognized Expert Contributor
        • Apr 2006
        • 511

        #4
        Code:
        ls -tr |tail -1 |awk '{print $NF}'

        Comment

        • michaelb
          Recognized Expert Contributor
          • Nov 2006
          • 534

          #5
          Originally posted by ghostdog74
          Code:
          ls -tr |tail -1 |awk '{print $NF}'
          Nice, but this code does not distinguish between files and folders; I think that rahulhere specifically wanted to get the latest folder (or file ?)

          Comment

          • ValHolla
            New Member
            • Sep 2006
            • 8

            #6
            Code:
            find . -type d -prune -exec ls -rt {} \; |tail -1
            This code will give you the "LAST" directory listed in the current directory
            depending on your OS you the -prune option may be -maxdepth 1 instead

            Code:
            find . -type d -maxdepth 1 -exec ls -rt {}\;|tail -1

            Comment

            Working...