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

crackpipe 05-05-2009 12:33 AM

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-05-2009 12:39 AM

How about

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

crackpipe 05-05-2009 01: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 02: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 03:36 AM

For bash try this doc:

All times are GMT -5. The time now is 06:18 PM.