How do I open latest file from list of files in a particular directory in aix

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












How do I open the latest file from list of files in a particular directory?
Same file name arrange in date wise with latest in last.



Currently I am using following commands:



ls -lrt filename*
tail -f filename






share|improve this question

























    up vote
    1
    down vote

    favorite












    How do I open the latest file from list of files in a particular directory?
    Same file name arrange in date wise with latest in last.



    Currently I am using following commands:



    ls -lrt filename*
    tail -f filename






    share|improve this question























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      How do I open the latest file from list of files in a particular directory?
      Same file name arrange in date wise with latest in last.



      Currently I am using following commands:



      ls -lrt filename*
      tail -f filename






      share|improve this question













      How do I open the latest file from list of files in a particular directory?
      Same file name arrange in date wise with latest in last.



      Currently I am using following commands:



      ls -lrt filename*
      tail -f filename








      share|improve this question












      share|improve this question




      share|improve this question








      edited Jun 26 at 10:07









      Jeff Schaller

      30.8k846104




      30.8k846104









      asked Jun 26 at 6:33









      Ajay mishra

      61




      61




















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          2
          down vote













          If your shell is a Bourne-like shell and its [ builtin implements the -nt test to test whether one file is newer than another, you may use



          newest=
          for file in ./* ./.*; do
          if [ -f "$file" ]; then
          if [ -z "$newest" ] || [ "$file" -nt "$newest" ]; then
          newest=$file
          fi
          fi
          done

          if [ -f "$newest" ]; then
          printf 'The latest file is "%s"n' "$newest"
          else
          echo 'Could not find files here' >&2
          exit 1
          fi


          This would iterate over all regular (and symlink to regular) files (including hidden ones) in the current directory and then tell you which one was found to be the newest file. You would replace the printf statement with the actual command that you'd want to run on "$newest".



          As a shell function, which additionally takes a list of files as its argument:



          newest () (
          newest=
          for file do
          if [ -f "$file" ]; then
          if [ -z "$newest" ] || [ "$file" -nt "$newest" ]; then
          newest=$file
          fi
          fi
          done

          if [ -f "$newest" ]; then
          printf '%sn' "$newest"
          else
          echo 'No files found' >&2
          return 1
          fi
          )


          Then



          tail -f "$(newest ./filename*)"





          share|improve this answer






























            up vote
            0
            down vote













            You can use GNU find, to print all files with their last modified time, sort them in reverse order, get the latest modified file ( head -n 1 - top entry ) and then do a tail of the last modified file



             find <Directory-name> -type f -printf '%TY-%Tm-%Td %TT %pn' | sort -r | head -n 1 | awk 'print $3' | xargs tail -f





            share|improve this answer






























              up vote
              0
              down vote













              If zsh is installed, you can do in it:




              tail -f filenameCtrl+xm


              Ctrl+xm is a completer that expands to the latest file (according to last modification time).



              In a script:



              #! /usr/bin/env zsh
              tail -f filename*(om[1])


              Where om sorts by modification time (most recent first) and [1] selects the first.






              share|improve this answer





















                Your Answer







                StackExchange.ready(function()
                var channelOptions =
                tags: "".split(" "),
                id: "106"
                ;
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function()
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled)
                StackExchange.using("snippets", function()
                createEditor();
                );

                else
                createEditor();

                );

                function createEditor()
                StackExchange.prepareEditor(
                heartbeatType: 'answer',
                convertImagesToLinks: false,
                noModals: false,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: null,
                bindNavPrevention: true,
                postfix: "",
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                );



                );








                 

                draft saved


                draft discarded


















                StackExchange.ready(
                function ()
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f451921%2fhow-do-i-open-latest-file-from-list-of-files-in-a-particular-directory-in-aix%23new-answer', 'question_page');

                );

                Post as a guest






























                3 Answers
                3






                active

                oldest

                votes








                3 Answers
                3






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes








                up vote
                2
                down vote













                If your shell is a Bourne-like shell and its [ builtin implements the -nt test to test whether one file is newer than another, you may use



                newest=
                for file in ./* ./.*; do
                if [ -f "$file" ]; then
                if [ -z "$newest" ] || [ "$file" -nt "$newest" ]; then
                newest=$file
                fi
                fi
                done

                if [ -f "$newest" ]; then
                printf 'The latest file is "%s"n' "$newest"
                else
                echo 'Could not find files here' >&2
                exit 1
                fi


                This would iterate over all regular (and symlink to regular) files (including hidden ones) in the current directory and then tell you which one was found to be the newest file. You would replace the printf statement with the actual command that you'd want to run on "$newest".



                As a shell function, which additionally takes a list of files as its argument:



                newest () (
                newest=
                for file do
                if [ -f "$file" ]; then
                if [ -z "$newest" ] || [ "$file" -nt "$newest" ]; then
                newest=$file
                fi
                fi
                done

                if [ -f "$newest" ]; then
                printf '%sn' "$newest"
                else
                echo 'No files found' >&2
                return 1
                fi
                )


                Then



                tail -f "$(newest ./filename*)"





                share|improve this answer



























                  up vote
                  2
                  down vote













                  If your shell is a Bourne-like shell and its [ builtin implements the -nt test to test whether one file is newer than another, you may use



                  newest=
                  for file in ./* ./.*; do
                  if [ -f "$file" ]; then
                  if [ -z "$newest" ] || [ "$file" -nt "$newest" ]; then
                  newest=$file
                  fi
                  fi
                  done

                  if [ -f "$newest" ]; then
                  printf 'The latest file is "%s"n' "$newest"
                  else
                  echo 'Could not find files here' >&2
                  exit 1
                  fi


                  This would iterate over all regular (and symlink to regular) files (including hidden ones) in the current directory and then tell you which one was found to be the newest file. You would replace the printf statement with the actual command that you'd want to run on "$newest".



                  As a shell function, which additionally takes a list of files as its argument:



                  newest () (
                  newest=
                  for file do
                  if [ -f "$file" ]; then
                  if [ -z "$newest" ] || [ "$file" -nt "$newest" ]; then
                  newest=$file
                  fi
                  fi
                  done

                  if [ -f "$newest" ]; then
                  printf '%sn' "$newest"
                  else
                  echo 'No files found' >&2
                  return 1
                  fi
                  )


                  Then



                  tail -f "$(newest ./filename*)"





                  share|improve this answer

























                    up vote
                    2
                    down vote










                    up vote
                    2
                    down vote









                    If your shell is a Bourne-like shell and its [ builtin implements the -nt test to test whether one file is newer than another, you may use



                    newest=
                    for file in ./* ./.*; do
                    if [ -f "$file" ]; then
                    if [ -z "$newest" ] || [ "$file" -nt "$newest" ]; then
                    newest=$file
                    fi
                    fi
                    done

                    if [ -f "$newest" ]; then
                    printf 'The latest file is "%s"n' "$newest"
                    else
                    echo 'Could not find files here' >&2
                    exit 1
                    fi


                    This would iterate over all regular (and symlink to regular) files (including hidden ones) in the current directory and then tell you which one was found to be the newest file. You would replace the printf statement with the actual command that you'd want to run on "$newest".



                    As a shell function, which additionally takes a list of files as its argument:



                    newest () (
                    newest=
                    for file do
                    if [ -f "$file" ]; then
                    if [ -z "$newest" ] || [ "$file" -nt "$newest" ]; then
                    newest=$file
                    fi
                    fi
                    done

                    if [ -f "$newest" ]; then
                    printf '%sn' "$newest"
                    else
                    echo 'No files found' >&2
                    return 1
                    fi
                    )


                    Then



                    tail -f "$(newest ./filename*)"





                    share|improve this answer















                    If your shell is a Bourne-like shell and its [ builtin implements the -nt test to test whether one file is newer than another, you may use



                    newest=
                    for file in ./* ./.*; do
                    if [ -f "$file" ]; then
                    if [ -z "$newest" ] || [ "$file" -nt "$newest" ]; then
                    newest=$file
                    fi
                    fi
                    done

                    if [ -f "$newest" ]; then
                    printf 'The latest file is "%s"n' "$newest"
                    else
                    echo 'Could not find files here' >&2
                    exit 1
                    fi


                    This would iterate over all regular (and symlink to regular) files (including hidden ones) in the current directory and then tell you which one was found to be the newest file. You would replace the printf statement with the actual command that you'd want to run on "$newest".



                    As a shell function, which additionally takes a list of files as its argument:



                    newest () (
                    newest=
                    for file do
                    if [ -f "$file" ]; then
                    if [ -z "$newest" ] || [ "$file" -nt "$newest" ]; then
                    newest=$file
                    fi
                    fi
                    done

                    if [ -f "$newest" ]; then
                    printf '%sn' "$newest"
                    else
                    echo 'No files found' >&2
                    return 1
                    fi
                    )


                    Then



                    tail -f "$(newest ./filename*)"






                    share|improve this answer















                    share|improve this answer



                    share|improve this answer








                    edited Jun 26 at 10:12









                    Stéphane Chazelas

                    278k52513844




                    278k52513844











                    answered Jun 26 at 6:44









                    Kusalananda

                    101k13199312




                    101k13199312






















                        up vote
                        0
                        down vote













                        You can use GNU find, to print all files with their last modified time, sort them in reverse order, get the latest modified file ( head -n 1 - top entry ) and then do a tail of the last modified file



                         find <Directory-name> -type f -printf '%TY-%Tm-%Td %TT %pn' | sort -r | head -n 1 | awk 'print $3' | xargs tail -f





                        share|improve this answer



























                          up vote
                          0
                          down vote













                          You can use GNU find, to print all files with their last modified time, sort them in reverse order, get the latest modified file ( head -n 1 - top entry ) and then do a tail of the last modified file



                           find <Directory-name> -type f -printf '%TY-%Tm-%Td %TT %pn' | sort -r | head -n 1 | awk 'print $3' | xargs tail -f





                          share|improve this answer

























                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote









                            You can use GNU find, to print all files with their last modified time, sort them in reverse order, get the latest modified file ( head -n 1 - top entry ) and then do a tail of the last modified file



                             find <Directory-name> -type f -printf '%TY-%Tm-%Td %TT %pn' | sort -r | head -n 1 | awk 'print $3' | xargs tail -f





                            share|improve this answer















                            You can use GNU find, to print all files with their last modified time, sort them in reverse order, get the latest modified file ( head -n 1 - top entry ) and then do a tail of the last modified file



                             find <Directory-name> -type f -printf '%TY-%Tm-%Td %TT %pn' | sort -r | head -n 1 | awk 'print $3' | xargs tail -f






                            share|improve this answer















                            share|improve this answer



                            share|improve this answer








                            edited Jun 26 at 10:12


























                            answered Jun 26 at 6:49









                            Arushix

                            9968




                            9968




















                                up vote
                                0
                                down vote













                                If zsh is installed, you can do in it:




                                tail -f filenameCtrl+xm


                                Ctrl+xm is a completer that expands to the latest file (according to last modification time).



                                In a script:



                                #! /usr/bin/env zsh
                                tail -f filename*(om[1])


                                Where om sorts by modification time (most recent first) and [1] selects the first.






                                share|improve this answer

























                                  up vote
                                  0
                                  down vote













                                  If zsh is installed, you can do in it:




                                  tail -f filenameCtrl+xm


                                  Ctrl+xm is a completer that expands to the latest file (according to last modification time).



                                  In a script:



                                  #! /usr/bin/env zsh
                                  tail -f filename*(om[1])


                                  Where om sorts by modification time (most recent first) and [1] selects the first.






                                  share|improve this answer























                                    up vote
                                    0
                                    down vote










                                    up vote
                                    0
                                    down vote









                                    If zsh is installed, you can do in it:




                                    tail -f filenameCtrl+xm


                                    Ctrl+xm is a completer that expands to the latest file (according to last modification time).



                                    In a script:



                                    #! /usr/bin/env zsh
                                    tail -f filename*(om[1])


                                    Where om sorts by modification time (most recent first) and [1] selects the first.






                                    share|improve this answer













                                    If zsh is installed, you can do in it:




                                    tail -f filenameCtrl+xm


                                    Ctrl+xm is a completer that expands to the latest file (according to last modification time).



                                    In a script:



                                    #! /usr/bin/env zsh
                                    tail -f filename*(om[1])


                                    Where om sorts by modification time (most recent first) and [1] selects the first.







                                    share|improve this answer













                                    share|improve this answer



                                    share|improve this answer











                                    answered Jun 26 at 10:16









                                    Stéphane Chazelas

                                    278k52513844




                                    278k52513844






















                                         

                                        draft saved


                                        draft discarded


























                                         


                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function ()
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f451921%2fhow-do-i-open-latest-file-from-list-of-files-in-a-particular-directory-in-aix%23new-answer', 'question_page');

                                        );

                                        Post as a guest













































































                                        Popular posts from this blog

                                        How to check contact read email or not when send email to Individual?

                                        Displaying single band from multi-band raster using QGIS

                                        How many registers does an x86_64 CPU actually have?