0

I am trying to extract the newest file in folder. I tried this:

ls -1t | head -1

But the problem is, that this command doesn't seem to differentiate in which second the file was created - if multiple files were created in the the same, this command just give the first file in this minute.

Is there a way to make this command more precise?

  • Have you checked this answer? http://stackoverflow.com/questions/5885934/bash-function-to-find-newest-file-matching-pattern – headbanger Apr 22 '16 at 08:36

1 Answers1

0

You should add T argument to the options to do that:

ls -1tT | head -1

See the output when l argument is added:

ls -tTl

-rw-r--r--  1 user  wheel      0 Apr 23 17:54:27 2016 1
-rw-r--r--  1 user  wheel      0 Apr 23 17:54:19 2016 3 
-rw-r--r--  1 user  wheel      0 Apr 23 17:54:12 2016 2
Hamid Rouhani
  • 2,309
  • 2
  • 31
  • 45