[SOLVED] How to find the directory with latest modified content??
Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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")
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..
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.
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.
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:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.