#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    2
    Rep Power
    0

    Selecting only newest file


    Hello,

    I was hoping someone could help me out. I am trying to figure out how to search for the newest file in a directory and save it as a variable. For example, if you do a 'ls -ltr', the last file listed would be the newest file. Does anyone know how to save just that file name in a variable?

    Thanks,
    Krypto
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,643
    Rep Power
    4247
    in bash/ksh/sh:

    foo=`ls -tr | tail -1`
    echo $foo
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    2
    Rep Power
    0
    Works great!! Thanks!

IMN logo majestic logo threadwatch logo seochat tools logo