python equivalent of bash find

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • BartlebyScrivener

    python equivalent of bash find

    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

  • Larry Bates

    #2
    Re: python equivalent of bash find

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

    Comment

    • Jerry Hill

      #3
      Re: python equivalent of bash find

      On 1 Mar 2007 12:14:43 -0800, BartlebyScriven er <rpdooling@gmai l.comwrote:
      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

      Comment

      • BartlebyScrivener

        #4
        Re: python equivalent of bash find

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

        Thank you both for the quick response.

        rd


        Comment

        • Bruno Desthuilliers

          #5
          Re: python equivalent of bash find

          BartlebyScriven er 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.

          Comment

          • BartlebyScrivener

            #6
            Re: python equivalent of bash find

            On Mar 1, 3:58 pm, Bruno Desthuilliers
            <bdesth.quelque ch...@free.quel quepart.frwrote :
            >
            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



            Comment

            Working...