python equivalent of bash find

Discussion in 'Python' started by BartlebyScrivener, Mar 1, 2007.

  1. 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
    BartlebyScrivener, Mar 1, 2007
    #1
    1. Advertising

  2. BartlebyScrivener

    Larry Bates Guest

    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
    Larry Bates, Mar 1, 2007
    #2
    1. Advertising

  3. BartlebyScrivener

    Jerry Hill Guest

    On 1 Mar 2007 12:14:43 -0800, 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?


    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
    Jerry Hill, Mar 1, 2007
    #3
  4. > You can probably replicate that using the modules os and shutil.

    Thank you both for the quick response.

    rd
    BartlebyScrivener, Mar 1, 2007
    #4
  5. 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.
    Bruno Desthuilliers, Mar 1, 2007
    #5
  6. On Mar 1, 3:58 pm, Bruno Desthuilliers
    <> 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
    BartlebyScrivener, Mar 1, 2007
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. William Park

    (patch for Bash) GTK+2 + Bash

    William Park, Jul 11, 2005, in forum: XML
    Replies:
    3
    Views:
    2,285
    William Park
    Jul 14, 2005
  2. Omar Khalid

    bash Vs python ??

    Omar Khalid, Nov 4, 2003, in forum: Python
    Replies:
    10
    Views:
    1,892
    Yu Wang
    Nov 6, 2003
  3. Peng Yu
    Replies:
    5
    Views:
    1,043
    Peng Yu
    Oct 19, 2009
  4. TP
    Replies:
    3
    Views:
    676
  5. Stephen Bannasch
    Replies:
    10
    Views:
    230
    Ben Bleything
    Nov 21, 2007
Loading...

Share This Page