0

I try to get the most recently name-file in specific directory, with dir command:

dir /O:D|tail -3 |head -1

but I got this line:

11/23/2014  01:18 PM               393 2.32.5100-results.json

thanks

Stephan
  • 53,940
  • 10
  • 58
  • 91
kasis
  • 35
  • 5
  • It works as expected here using cygwin head and tail. Which head and tail are you using? Please [edit your question](http://stackoverflow.com/posts/27089409/edit) to include the output from dir and the output you expect to see. – DavidPostill Nov 23 '14 at 13:44
  • you want the filename only, right? Use `dir`'s parameter `/b` – Stephan Nov 23 '14 at 14:16

1 Answers1

0
dir /b /a-d /o-d | head -1 

And just for a native windows alternative

dir /b /a-d /o-d | cmd /v /c "set/p.=&&echo(!.!"

In both cases, execute a dir command, in bare format, without folders in date descending order and pipe the information into a

  • head command that will retrieve the only the first line (the newest file)

or

  • a cmd instance that will retrieve the first line (the newest file) and echo it to console
MC ND
  • 69,615
  • 8
  • 84
  • 126