python equivalent of bash find

  • Thread starter BartlebyScrivener
  • Start date
B

BartlebyScrivener

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?

Thank you,

rd

"You can't have everything. Where would you put it?"--Steven Wright
 
L

Larry Bates

BartlebyScrivener said:
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?

Thank you,

rd

"You can't have everything. Where would you put it?"--Steven Wright
os.walk to walk directories
os.stat to get modification time of file
os.shutl to copy file somewhere

-Larry
 
J

Jerry Hill

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.
 
B

BartlebyScrivener

You can probably replicate that using the modules os and shutil.

Thank you both for the quick response.

rd
 
B

Bruno Desthuilliers

BartlebyScrivener a écrit :
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?

MHO is that you'd better learn linux (well... Unix) tools. Reinventing
the SquareWheel(tm) is usually not a good idea.
 
B

BartlebyScrivener

MHO is that you'd better learn linux (well... Unix) tools. Reinventing
the SquareWheel(tm) is usually not a good idea.

I agree. It's just a matter of experience and learning when to use
Unix tools and when to use Python.
The question never came up on Windows :)

Thanks,

rd

"Artificial stupidity (AS) may be defined as the attempt by computer
scientists to create computer programs capable of causing problems
of a type normally associated with human thought."

--Wallace Marshal
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top