Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then 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.
I'm relatively experienced with UNIX and Linux, but this has me thrown for quite a loop, and it seemed like such a simple question. How would I go about finding the newest file in a file system?
I thought something like:
Code:
ls -ltr `find /usr -type f`
would work, but I seem to be exceeding the argument maximum for ls:
ksh: 0403-029 There is not enough memory available now
I thought something involving xargs might work, but I really suck with that command. Anyone got any ideas?
You can try this out, it should work fairly well... right now it returns the 5 most recent and gives an ls on them... you could change that number by changing the head items returned.
Code:
for i in $(find / -printf "%T@ %Tx %TX %p\n" | sort -n -r | head -5 | cut -f5 -d' '); do ls -al $i; done
If you're looking for just something to run at command line that is simple...
Excellent! That works quite well (correction: on Linux).
One more thing though ... do you think you could explain to me that each of those %T specifiers does? It's hard to find good documentation about printf and I'm not familiar with those specifiers.
Edit: Seems that the -printf does not exist in AIX find. Was looking for something a little more universal:
find: 0652-017 -printf is not a valid option.
Last edited by newmanium2001; 04-14-2010 at 09:04 AM.
Ah the joys of working on cross platforms. No, that option isn't universal, likely you'd have to source compile find to get that functionality on AIX (or irix for that matter, I think it works on current solaris and bsd.) That being said there is no universal answer that will work everywhere, because the tools aren't uniform, the base functionality is typically the same, but the additional features can vary quite drastically... without using printf I'd try using -mtime -1 and try to figure a way to sort that list further. I don't have an aix system to tinker with at the moment to check options against heh.
In the case of what do the printf functions do, check out the ~find~ man page instead of the printf man page, you'll also get more useful information out of 'man 3 printf' than 'man 1 printf' typically (the section 1 manpage of printf is pretty worthless.)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.