473,785 Members | 2,327 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Mar 1 '07 #1
5 4443
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
Mar 1 '07 #2
On 1 Mar 2007 12:14:43 -0800, BartlebyScriven er <rp*******@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
Mar 1 '07 #3
You can probably replicate that using the modules os and shutil.

Thank you both for the quick response.

rd
Mar 1 '07 #4
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.
Mar 1 '07 #5
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

Mar 1 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

699
34240
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro capabilities, unfortunately. I'd like to know if it may be possible to add a powerful macro system to Python, while keeping its amazing syntax, and if it could be possible to add Pythonistic syntax to Lisp or Scheme, while keeping all of the...
114
9886
by: Maurice LING | last post by:
This may be a dumb thing to ask, but besides the penalty for dynamic typing, is there any other real reasons that Python is slower than Java? maurice
8
2030
by: Jan Danielsson | last post by:
Hello all, How do I make a python script actually a _python_ in unix:ish environments? I know about adding: #!/bin/sh ..as the first row in a shell script, but when I installed python on a NetBSD system, I didn't get a "python" executable; only a "python2.4"
1
4563
by: news | last post by:
OP wrote: }in order to justify learning another language I'd first need to be }convinced that python could easily do the following:- } }ReadSectors2Bufr(hdx, StartSectr, SectrCnt, Bufr); <-- like linux:dd }PrintDecOf4Bytes(Offset, Bufr); <-- and also 1 and 2 byte values }OverWriteBufr(Offset, Bufr, Byte); }WriteBufr2Sectors ..... <-- like linux: dd } }I guess one would normally use bash, but I'd rather invest effort
118
6747
by: 63q2o4i02 | last post by:
Hi, I've been thinking about Python vs. Lisp. I've been learning Python the past few months and like it very much. A few years ago I had an AI class where we had to use Lisp, and I absolutely hated it, having learned C++ a few years prior. They didn't teach Lisp at all and instead expected us to learn on our own. I wasn't aware I had to uproot my thought process to "get" it and wound up feeling like a moron. In learning Python I've...
14
19804
by: Rochester | last post by:
Hi, I just found out that the general open file mechanism doesn't work for named pipes (fifo). Say I wrote something like this and it simply hangs python: #!/usr/bin/python import os
12
4567
by: Alex | last post by:
Hi all, The subject says pretty much all, i would very appreciate an answer. I tried to search the various forums and groups, but didn't find any specific answer... Thanks, Alex.
5
1438
by: aha | last post by:
Hello All, I have a situation where I can count on a Python installation being available on a system, but I can't count on it being a version of Python needed by my application. Since my application has it's own version of Python installed with it how should I use the system Python to launch the version of Python that launches my Application. Yes, this is a convoluted process, but not all Pythons are built the same :) Right now I am...
6
1871
by: Frantisek Malina | last post by:
What is the best way to do the regular bash commands in native python? - create directory - create file - make a symlink - copy a file to another directory - move a file - set permissions I need to write a program that creates real application/FTP accounts
0
9491
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10163
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10104
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7510
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5397
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5532
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4063
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3668
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.