Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 04-25-2012, 08:48 PM   #1
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:

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, 09:29 PM   #2
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677
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 09:32 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 12:11 PM
apt-get can't find latest FireFox. Fasn8n Ubuntu 7 03-15-2006 09:18 PM
how to find latest drivers? slinky2004 Linux - General 2 12-09-2005 07:48 PM
Where is 'config' in latest v. of quanta, cnt find it BuckRogers01 Linux - Software 1 07-04-2005 09:08 AM
Where to find the latest logfile a1ex_007 Linux - Security 1 03-18-2005 10:58 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:54 AM.

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