python equivalent of bash find

Jerry Hill malaclypse2 at gmail.com
Thu Mar 1 21:30:24 CET 2007


On 1 Mar 2007 12:14:43 -0800, BartlebyScrivener <rpdooling at gmail.com> wrote:
> I recently moved from XP to Linux, but would like to use Python
> whenever possible.
>
> line from bash script:
>
> find ~/Mail -xdev -type f \( -mtime 0 -or -mtime 1 \) -exec cp -aPvu
> "{}" /backup-dest \;
>
> What modules would I use to accomplish this in Python? Or any other
> Python tricks to copy or backup all files modified today?

You can probably replicate that using the modules os and shutil.
Specifically, os.walk to traverse your directory tree, os.stat to get
the modification time, and shutil.copy to copy files around.  You
might also look at the stat module, which appears to have some helpers
for dealing with os.stat results.

On the other hand, you could also just use os.system or the subprocess
module to wrap your call to the find utility.

-- 
Jerry



More information about the Python-list mailing list