Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > python equivalent of bash find

Reply
Thread Tools

python equivalent of bash find

 
 
BartlebyScrivener
Guest
Posts: n/a
 
      03-01-2007
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

 
Reply With Quote
 
 
 
 
Larry Bates
Guest
Posts: n/a
 
      03-01-2007
BartlebyScrivener 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?
>
> 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
 
Reply With Quote
 
 
 
 
Jerry Hill
Guest
Posts: n/a
 
      03-01-2007
On 1 Mar 2007 12:14:43 -0800, BartlebyScrivener <(E-Mail Removed)> 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
 
Reply With Quote
 
BartlebyScrivener
Guest
Posts: n/a
 
      03-01-2007
> You can probably replicate that using the modules os and shutil.

Thank you both for the quick response.

rd


 
Reply With Quote
 
Bruno Desthuilliers
Guest
Posts: n/a
 
      03-01-2007
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.
 
Reply With Quote
 
BartlebyScrivener
Guest
Posts: n/a
 
      03-01-2007
On Mar 1, 3:58 pm, Bruno Desthuilliers
<(E-Mail Removed)> wrote:

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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
equivalent of bash "set -x" in Python TP Python 3 09-26-2010 10:46 AM
python along or bash combined with python (for manipulating files) Peng Yu Python 5 10-19-2009 03:46 AM
Is there an equivalent in irb to command: history in bash? Stephen Bannasch Ruby 10 11-21-2007 07:57 PM
(patch for Bash) GTK+2 + Bash William Park XML 3 07-14-2005 12:09 AM
bash Vs python ?? Omar Khalid Python 10 11-06-2003 01:32 AM



Advertisments