[Melbourne-pm] need help for one kind of script

Craig Sanders cas at taz.net.au
Thu Jun 28 06:29:18 PDT 2007


On Thu, Jun 28, 2007 at 05:58:02PM +0530, ankur dave wrote:
> I need one script which will give me the last updated file from the
> specified directory.
> My problem is let say I am working on /var/www/test/ and in this we have
> some 5 other folders and so many perl and PHP files.
> now I will update all the files but at the end of the day I want to know
> what are the files I have updated.

do you want the last updated file in a directory tree (no matter how old it
is), or the file(s) updated today (i.e within the last 24 hours)?

if the latter, then:

find /var/www/test -type f -a -mtime 0

or 

find /var/www/test -type f -a -daystart -mtime 0

(for files modified since the start of the day)

see the man page for find(1) for more details.




the former could be done(*) with something like:

cd /var/www/test ; find . -type f -print0 | xargs -0 ls -lrt | tail -1



(*) for a very slack value of "done". i.e. only if the output
of find fits onto one command-line for xargs - which is why
the one-liner changes directory and searches ".", to make
the output smaller. if you have thousands of files or many
reallystupidlyveryunfeasiblylongfilenames under /var/www/test, you'd
need a better script :)

craig

-- 
craig sanders <cas at taz.net.au>


More information about the Melbourne-pm mailing list