[SunHELP] script to find newest file

Wyatt Draggoo wyatt at draggoo.com
Wed Jul 24 10:54:50 CDT 2002


> has anyone created a script to find the newest file created
> within a large directory.  struggling with cutting date info
> and need some assistance.

If it's in a single directory, you can do an `ls -lrt' which will sort the
files with the newest at the bottom, so you can use `tail -1' to get it. 
It will sort them with the newest at the top without the `r' (`ls -lt'). 
Also, if you just need the filenames, you can use it without the `l' (`ls
-rt').

If you've got a certain time in mind, you can touch a temporary file with
that date/time, and then `find /dir -newer tmpfile', which will list the
files newer than the date/time on the temp file.  I use this a lot when I'm
installing a program.  I'll `touch /tmp/timefile', run the install, and
then do a `find / -newer /tmp/timefile' to find out what got
installed/changed.

Wyatt

--
Wyatt Draggoo



More information about the SunHELP mailing list