How To Do It Faster?!?

Simo Melenius firstname.lastname at iki.fi-spam
Sat Apr 2 12:51:41 EST 2005


andrea_gavana at tin.it writes:

> >$ find . -type f -printf "%T@ %u %s %p\n" > /yourserverroot/files.txt
> That is a nice idea. I don't know very much about Unix, but I suppose that
> on a ksh I can run this command (or a similar one) in order to obtain the
> list I need. If anyone knows if that command will run also on a simple ksh,
> could please confirm that?

That depends on the unix flavor you're using -- my example was for GNU
utilities which are heavily used on (probably all) Linux systems.
BSDs, Solaris and other unixen have slightly different 'find' syntax.
Use "man find" to find out more about how 'find' works on your system.

On all systems I know, it goes like:

find <directory> [-switches ...]

where the switches vary depending on the system. In my example, I used
-type f (f as in file) to only list files (otherwise 'find' will
include directories too in the output) and -printf to include desired
data -- in this case, owner, last modified time, size, path -- in the
output (otherwise 'find' will only print the path).

You should at least go through the -printf formatting codes to see
what information you're able to include in the output (=> man find).

I used %T@ to print the last modified time in Unix time because it's
as simple as it can be: an integer, counting the number of seconds
since Jan 1 1970. Python's "time" module groks Unix time just like
that.

> Moreover, I could run this script in a while loop, like:

Except that, I'd imagine, constantly traversing the filesystem will
seriously degrade the performance of the file server. You want to run
your script periodically over a day, maybe at times when the server is
inactive. Or hourly between 8am-4pm and then once at night.

In Unix, there's a facility called cron to do just that, it runs
scripts and commands over and over again hourly, daily, weekly, or
just whenever you want it. Consult your unix flavor's manual or
newsgroup on that.

>         copy /yourserverroot/files.txt   /yourserverroot/filesbackup.txt
> always have the filesbackup.txt up-to-date, as a function of the "find"
> speed on the server.

Yes, creating a temporary file is a good approach. I'd suggest moving
the new list over the old one (mv tmpfile filelist.txt) instead of
copying, since usually move is merely a rename operation on the
filesystem and doesn't involve actually copying of any data.


br,
S

-- 
firstname.lastname at iki.fi-spam



More information about the Python-list mailing list