LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-25-2012, 07:48 PM   #1
goliwala
LQ Newbie
 
Registered: Mar 2012
Posts: 1

Rep: Reputation: Disabled
Find Latest File


Hello Everyone.

I generate files in a new directory daily. Sometimes I generate multiple files for the day, each file is named exactly the same, each file goes in its respective folder, folders are named according to the create timestamp. So for a day I sometimes end up with more then one file of the same name in their respective folders.
for example:
/etc/20120104104002/myfile_01_04_2012.txt
/etc/20120105160003/myfile_01_04_2012.txt

I need to find the latest myfile_01_04_2012.txt. The one in 20120105160003 folder. I've tried
find /etc/ -iname myfile_01_04_2012.txt -type f | sort -n | tail -1

I sometimes get the last file generated (which is what I want) and sometimes it is the first file generated.(not what I want)

What am I doing wrong?
 
Old 04-25-2012, 08:29 PM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
List the directories. They were created at the same time.

ls -1rd 2012*/ | head -1

If the sort order of the directories always sorts correctly, you can sort the directories with reverse sort so the most recent is first
ls -dr | head -1

/etc/ isn't the right directory for storing data. These look like log files. The directory to use for log files us /var/log. /etc is for static configurations.

Last edited by jschiwal; 04-25-2012 at 08:32 PM.
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
find the latest updated files ubuntu_amateur Linux - Newbie 4 11-02-2006 11:11 AM
apt-get can't find latest FireFox. Fasn8n Ubuntu 7 03-15-2006 08:18 PM
how to find latest drivers? slinky2004 Linux - General 2 12-09-2005 06:48 PM
Where is 'config' in latest v. of quanta, cnt find it BuckRogers01 Linux - Software 1 07-04-2005 08:08 AM
Where to find the latest logfile a1ex_007 Linux - Security 1 03-18-2005 09:58 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration