LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 05-04-2009, 11:33 PM   #1
crackpipe
Member
 
Registered: Nov 2005
Distribution: Slackware, Zenwalk, Debian
Posts: 33

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:
Code:
$ 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
Code:
$ 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-04-2009, 11:39 PM   #2
billymayday
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, 12:03 AM   #3
crackpipe
Member
 
Registered: Nov 2005
Distribution: Slackware, Zenwalk, Debian
Posts: 33

Original Poster
Rep: Reputation: 15
Quote:
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, 01:33 AM   #4
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,695
Blog Entries: 5

Rep: Reputation: 240Reputation: 240Reputation: 240
since you want to learn Python, here's a Python script that does what the find command does
Code:
import os,shutil
destination="/home/destination"
source="/src"
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'''
            try:
                '''move files to desintation'''
                shutil.move(os.path.join(r,files),os.path.join(destination,files))
            except Exception,e:
                #print e
                pass
 
Old 05-05-2009, 02:36 AM   #5
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,239

Rep: Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024
For bash try this doc: http://www.tldp.org/LDP/abs/html/
 
  


Reply

Tags
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 03:33 PM
using bash find command to list *.h and *.cpp wgillett Linux - Software 3 12-15-2005 11:55 AM
trouble with find command in bash vrdhananjay Linux - Newbie 3 10-30-2004 11:37 PM
bash connot find the command Dunadan1821 Linux - Software 9 08-30-2004 08:04 AM
bash cant find format or mkfs command Dunadan1821 Linux - Software 3 08-12-2004 01:27 PM


All times are GMT -5. The time now is 12:19 AM.

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