Re: oldest and newest file/directory within a directory structure



--- "Taylor, David" <DTaylor@xxxxxxxx> wrote:

Hi *,



Does anyone know of a way to find the oldest and
newest file within a
directory structure - to include subdirectories too?



I am writing a script to do some reporting on
various directories (size,
# of files, # of directories, etc..) and would also
like to be able to
identify the oldest and newest file within each
directory structure too.



TIA



David



You could write a perl script or C program to "stat"
everysingle file in the filesystem and store the
results in an array or hash (or struct or array in C)
acording to the last modification time (I would assume
you would go for the i-node information.


Using GNU's find, this will give you the filename and
epoch (seconds since 1 Jan 1970) of the first and last
files to had the inode modified in the filesystem.



find . -xdev -printf "\n%p\t%T@" | sort -n -k2,2
2>/dev/null | sed -e '/^[<tab><space>]*$/d' | awk '{
if (NR==1){print } else {a=$0
}} END { print a} '

regards,
esv.
btw... replace the <tab> with an actual TAB and
<space> with its corresponding blank space.

Enrique Sanchez Vela
email: esanchezvela@xxxxxxxxx
--------------------------------------
http://www.savetheinternet.com/

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com



Relevant Pages