Get the name of the newest file in a directory on the linux shell

Friday, October 14, 2011 posted by Till

If you have a directory with many files (a few thousand in my case) and need to know which one is the newest, then the following command might be useful. It returns the name and details of the newest file in a directory where it is executed:

ls -tl | sed -n 2p

Be Sociable, Share!


3 Responses to “Get the name of the newest file in a directory on the linux shell”

  1. Khurram says:

    how about ‘ls -ltr’ ?

  2. ls -Art | tail -n 1

  3. James Cage says:

    And how to get the oldest file in a directory?

Leave a Reply