The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Operating Systems > AIX
.
grep unix.com with google



AIX AIX is IBM's industry-leading UNIX operating system that meets the demands of applications that businesses rely upon in today's marketplace.

Reply
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-20-2009
Registered User
 

Join Date: Oct 2009
Posts: 25
How to read the latest file name in adirectory.

Hello all,

In a shell script, I need to get the name of the latest file which was created in a directory. i.e. I have the following directory.

Code:
/tmp/public/logs/

In this directory, I want to get the latest file that was created. Can you give me a hint as how can I get the latest file, based on timestamp?

Thanks in advance...
  #2 (permalink)  
Old 11-20-2009
scottn scottn is offline Forum Staff  
Moderator
 

Join Date: Jun 2009
Location: Zürich, CH
Posts: 1,611

Code:
LATEST=$(ls -t /tmp/public/log | head -1)

echo $LATEST

...


Last edited by scottn; 11-20-2009 at 04:15 PM..
  #3 (permalink)  
Old 11-20-2009
Registered User
 

Join Date: Oct 2009
Posts: 25
Quote:
Originally Posted by scottn View Post
Code:
LATEST=$(ls -t /tmp/public/log | head -1)
 
echo $LATEST
 
...

Thanks Scott, it worked.

You are always such a great help...Thanks buddy, again.
Sponsored Links
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Cannot read a file with read(fd, buffer, buffersize) function naranja18she High Level Programming 3 06-12-2009 02:39 PM
get latest file inquirer Shell Programming and Scripting 4 04-02-2009 12:15 PM
how to get the latest file shehzad_m Shell Programming and Scripting 3 01-29-2009 06:07 PM
How do I get the name of latest file? Hangman2 Shell Programming and Scripting 5 01-03-2009 10:18 AM
Read the latest file wereyou UNIX for Dummies Questions & Answers 3 02-10-2008 12:12 AM



All times are GMT -4. The time now is 02:14 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0