Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 05-05-2009, 12:33 AM   #1
Registered: Nov 2005
Location: Berkeley, CA
Distribution: Slackware, Arch, Zenwalk (pre-2012)
Posts: 41

Rep: Reputation: 15
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.
Old 05-05-2009, 12:39 AM   #2
LQ Guru
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
How about

find . -name *.py -exec cp {} /home/click/pythons/ \;
Old 05-05-2009, 01:03 AM   #3
Registered: Nov 2005
Location: Berkeley, CA
Distribution: Slackware, Arch, Zenwalk (pre-2012)
Posts: 41

Original Poster
Rep: Reputation: 15
Originally Posted by billymayday View Post
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...
Old 05-05-2009, 02:33 AM   #4
Senior Member
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
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
1 members found this post helpful.
Old 05-05-2009, 03:36 AM   #5
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,411

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
For bash try this doc:


bash, python

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash - find command And_pas Programming 7 05-10-2007 04:33 PM
using bash find command to list *.h and *.cpp wgillett Linux - Software 3 12-15-2005 12:55 PM
trouble with find command in bash vrdhananjay Linux - Newbie 3 10-31-2004 12:37 AM
bash connot find the command Dunadan1821 Linux - Software 9 08-30-2004 09:04 AM
bash cant find format or mkfs command Dunadan1821 Linux - Software 3 08-12-2004 02:27 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:57 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration