-   Linux - Software (
-   -   bash command - find |cp (

crackpipe 05-04-2009 11:33 PM

bash command - find |cp
I wanted to find all the python scripts on my local machine and put them in a directory eg. (/home/crackpipe/pythons), so I can look through them and learn. I'm attempting to learn Python. I tried this command, but it doesn't work, probably for obvious reasons to someone here:

$ find . -name *.py |cp $1 /home/click/pythons/
cp: missing destination file operand after `/home/crackpipe/pythons'

So it appears "$1" cannot be passed. Not sure what gets passed from "find", if anything. What's a good format to run this? I'm afraid to attempt something like

$ cp -r *.py /home/crackpipe/pythons
in case it attempts to duplicate the entire disk, or most of it, into /home/crackpipe/pythons. I just want the ".py"'s there. Thanks.

billymayday 05-04-2009 11:39 PM

How about

find . -name *.py -exec cp {} /home/click/pythons/ \;

crackpipe 05-05-2009 12:03 AM


Originally Posted by billymayday (Post 3530350)
How about

find . -name *.py -exec cp {} /home/crackpipe/pythons/ \;

Well this was quite right. Many thanks. Now to understand Bash further, something I obviously need work on as well...

ghostdog74 05-05-2009 01:33 AM

since you want to learn Python, here's a Python script that does what the find command does

import os,shutil
for r,d,f in os.walk(source):
    for files in f:
        if files.endswith(".py"):
            '''assumes all python files ends with .py'''
            '''if not, extra code to be written to further check'''
                '''move files to desintation'''
            except Exception,e:
                #print e

chrism01 05-05-2009 02:36 AM

For bash try this doc:

All times are GMT -5. The time now is 01:45 PM.