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 09-29-2010, 11:00 AM   #16
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,008

Rep: Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193

Assuming time is a complete unknown, how about:
Code:
find / -printf "%T+ %p\n" | sort | tail -n 1
 
1 members found this post helpful.
Old 09-29-2010, 11:04 AM   #17
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
Ah! grail's idea is what we were looking for methinks. WAY cleaner. And to make it print only the directory:
Code:
dirname $(find /search/path/ -printf "%T+ %p\n" | sort | tail -n 1 | awk '{print $NF}')
 
Old 09-29-2010, 11:07 AM   #18
kamalp
LQ Newbie
 
Registered: Sep 2010
Posts: 19

Original Poster
Rep: Reputation: 0
Hi GrapefruiTgirl,

thanks for the script.
but the script still relies on commands find -ctime and ls -rtl which leaves the problem intact..

I ran your script. it is not working for the situation where there are nested sub-directories.

Thanks,
Kamal

Last edited by kamalp; 09-29-2010 at 12:19 PM.
 
Old 09-29-2010, 12:00 PM   #19
kamalp
LQ Newbie
 
Registered: Sep 2010
Posts: 19

Original Poster
Rep: Reputation: 0
Hi All,

Thanks for all your inputs.
based on GrapefruiTgirl's script, I found a simple workaround for my problem.

find . -type f | xargs ls -rtl

The above command lists all files in all nested sub-directories with timed order (latest modified file being at end of list).
Based on the command output, we can see what is latest modified file which tells us the directory path also.

I think this solution works fine. what say?
(but still this command is not sorting files in order in some cases where the time format changes. ex: very old files are displayed with time like "Aug 30 2009" and for this year files "Aug 30 01:25")

Thanks,
Kamal

Last edited by kamalp; 09-29-2010 at 12:20 PM.
 
Old 09-29-2010, 12:11 PM   #20
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
I dunno, something's amiss. When I try your latest command, and grail's command, and my script, I get three different results, and grail's method looks to be the (most?) correct result. I'd do some more examining of your output if I were you.

It's fairly obvious that the script I provided is way too convoluted to work with, when compared to the possible alternates, so have a closer look at your results from the other methods..
 
Old 09-30-2010, 05:28 AM   #21
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,362

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Are you really sure about the 'old files' issue?
I don't have any files old enough to test, but although the basic ls cmd may show(!) dates in different formats for old files, when using

ls -ltr

ls is still reading the dir inode (which is where ctime/mtime/atime for the files are stored) and I'm (pretty) sure it's not stored differently dependent on age.
 
Old 09-30-2010, 07:47 AM   #22
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
I don't have a known working solution for this yet. But I just now confirmed (as best I can) that no method given yet in this thread, is working as desired. Seems it shouldn't be that complicated..

I made an infinite loop that writes to a file every 5 seconds forever. And using all methods given so far in this thread, none produce the file/directory that I'm writing to.
 
Old 09-30-2010, 07:58 AM   #23
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
Update:

It seems my test file and my window manager's logfile are both competing to be the last-modified file! Knowing that, I change what I wrote above in post #22:

My script still seems to work (convoluted as it is), as does grail's one-liner. And similarly to grail's one-liner, I got this:
Code:
find /home/sasha -type f -printf "%TY-%Tm-%Td %TT %p\n" | sort | tail -n 1
from here: http://mediakey.dk/~cc/linux-howto-f...s-recursively/
and it also seems to work. All 3 methods consistently produce either one of my testfile or my window manager's logfile.

What say the OP? Have you concluded that one of these methods is indeed producing accurate results for you?
 
Old 10-01-2010, 02:11 AM   #24
kamalp
LQ Newbie
 
Registered: Sep 2010
Posts: 19

Original Poster
Rep: Reputation: 0
Hi Celine,

perfect!!! It's working..
Thanks a lot for the info.

But I do have large very databases and it is taking hell lot of time to scan all files in all directories and sorting..

Is there another method to find the directory with latest modified content without scanning the files..?

Thanks,
Kamal
 
Old 10-01-2010, 04:10 AM   #25
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,008

Rep: Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193
Well you could change it to look for directories instead so the number to be scanned would be less. Simply change -f to -d for type
 
Old 10-02-2010, 05:17 AM   #26
kamalp
LQ Newbie
 
Registered: Sep 2010
Posts: 19

Original Poster
Rep: Reputation: 0
Hi Grail,

Thanks for the good suggestion. This will serve my purpose because whenever a file is modified it's directory's timestamp also gets updated.

I'm marking this thread as SOLVED. once again thanks a lot to all for the help.

Thanks,
Kamal
 
Old 10-02-2010, 05:23 AM   #27
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,140

Rep: Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123
inotify ?.
 
  


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
Get the absolute path of the latest file modified on a directory mortonmorton Linux - Newbie 2 10-15-2009 09:05 PM
Tail Last Modified File in a Directory tyoungblood Linux - Software 3 08-12-2005 08:42 AM
triggering bash script if directory modified cbb Linux - Software 1 10-23-2004 07:52 AM
monitoring directory to get the modified file names appas Programming 1 09-06-2004 04:56 AM
Get directory stats when a file has been modified? marri Programming 2 05-13-2004 08:44 PM

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

All times are GMT -5. The time now is 06:47 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