Differences between revisions 1 and 16 (spanning 15 versions)
Revision 1 as of 2009-03-18 05:20:23
Size: 541
Editor: localhost
Comment: created by Samus_
Revision 16 as of 2016-03-23 02:54:29
Size: 436
Editor: KerrySomme
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
Describe BashFAQ/099 here.

<<Anchor(faq99)>>
== How can I get the newest file from a directory? ==
Parsing the output of 'ls' is a bad practice, you should create a loop and compare the timestamps:

{{{
saved_ts=0
for f in *; do
  f_ts=$(stat --format=%Y "$f")

  if ((f_ts > newest_ts)); then
    newest_ts=$f_ts
    newest_f=$f
  fi
done
}}}

there you'll have the newest file at $newest_f, notice that when a file changes also changes its timestamp so this will get the last created or modified file in the directory.
Hello dear visitor. I'm Mittie Odaniel. One on the very best things inside the world for me personally is drawing but I have not made a dime with it's. Office supervising is just how I generate. His wife and him live in Arizona. My husband and I maintain an internet business. You might want to examine it here: http://Thatch22.Webs.com/<<BR>><<BR>>
<<BR>><<BR>>
My blog ... [[http://Thatch22.Webs.com/|how to be a mystery shopper]]

Hello dear visitor. I'm Mittie Odaniel. One on the very best things inside the world for me personally is drawing but I have not made a dime with it's. Office supervising is just how I generate. His wife and him live in Arizona. My husband and I maintain an internet business. You might want to examine it here: http://Thatch22.Webs.com/<<BR>><<BR>>

My blog ... how to be a mystery shopper

BashFAQ/099 (last edited 2016-03-23 09:25:56 by geirha)