LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
LinkBack Search this Thread
Old 07-12-2005, 12:06 PM   #1
Leary664
LQ Newbie
 
Registered: Aug 2004
Location: Upstate New York
Distribution: Red Hat 9.0
Posts: 8

Rep: Reputation: 0
Post How do I copy multiple files


Hi All,
I need you help. I have a CD with a bunch of 2kb images on it that need to be copied to a directory on the hard disk. As you may know, you can't use the "cp" command to do this. I know theres a way to use the "find" command and pipe it to the "cp" command but I don't know the syntex. It's something like......

find -name '*.jpg' | xargs cp /Directory_to_copy_to

Any Ideas?
Thanks kids

Leary
 
Old 07-12-2005, 12:27 PM   #2
Matir
Moderator
 
Registered: Nov 2004
Location: Kennesaw, GA
Distribution: Ubuntu
Posts: 8,502

Rep: Reputation: 110Reputation: 110
I'm not quite sure why 'cp /mnt/cdrom/*.jpg /directory/to/copy/to' wouldn't work, unless they're in a bunch of directories.

Otherwise, using xargs:
Code:
find /mnt/cdrom -iname '*.jpg' | xargs cp {} /directory/to/copy/to
 
Old 07-12-2005, 12:30 PM   #3
nadroj
Senior Member
 
Registered: Jan 2005
Location: Canada
Distribution: ubuntu
Posts: 2,538

Rep: Reputation: 58
have you tried doing something like
Code:
$ cp *.jpg /path/to/Folder
the cp command DOES allow you to copy multiple files to one directory.. do a variation of this and post the error message if so
 
Old 07-12-2005, 01:39 PM   #4
Leary664
LQ Newbie
 
Registered: Aug 2004
Location: Upstate New York
Distribution: Red Hat 9.0
Posts: 8

Original Poster
Rep: Reputation: 0
Ok. First off, thanks for the replies.

If I use "find" I get the error....

cp: copying multiple files, but last argument `/mnt/cdrom/current_image_name.jpg` is not a directory

It does this over and over again for each images it trys to copy. so I ctrl-C out of it.

If I try cp *.jpg /path/to/Folder

I get the error.....

Argument list too long

The CD has around 30,000 2kb thumbnail images on it for our website. My only guess is that there's too many files to copy at once.
Any other ideas?

Thanks for the help guys.
Leary
 
Old 07-12-2005, 01:41 PM   #5
Matir
Moderator
 
Registered: Nov 2004
Location: Kennesaw, GA
Distribution: Ubuntu
Posts: 8,502

Rep: Reputation: 110Reputation: 110
Exactly what is the find command you are running? I accidentally left off [--replace] after xargs. Try it with:
Code:
find /mnt/cdrom -iname '*.jpg' | xargs --replace cp {} /new/directory
 
Old 07-12-2005, 01:45 PM   #6
Leary664
LQ Newbie
 
Registered: Aug 2004
Location: Upstate New York
Distribution: Red Hat 9.0
Posts: 8

Original Poster
Rep: Reputation: 0
Oh, and I can copy a single file with the cp command but I'd rather no have to do it 30,000 times. I guess it would be good job security tho...
 
Old 07-12-2005, 01:47 PM   #7
Matir
Moderator
 
Registered: Nov 2004
Location: Kennesaw, GA
Distribution: Ubuntu
Posts: 8,502

Rep: Reputation: 110Reputation: 110
Did you try my revised find and xargs-based solution?
 
Old 07-12-2005, 01:50 PM   #8
Leary664
LQ Newbie
 
Registered: Aug 2004
Location: Upstate New York
Distribution: Red Hat 9.0
Posts: 8

Original Poster
Rep: Reputation: 0
Looks like that might be working I'll have to let it finish looping through all 30,000. We'll see what happens.
Thanks again, I'll let you know how I make out.
Leary
 
Old 07-12-2005, 01:52 PM   #9
Matir
Moderator
 
Registered: Nov 2004
Location: Kennesaw, GA
Distribution: Ubuntu
Posts: 8,502

Rep: Reputation: 110Reputation: 110
Cool, I hope it works for you. I imagine it might take a few minutes to go through it all.
 
Old 07-12-2005, 02:09 PM   #10
Leary664
LQ Newbie
 
Registered: Aug 2004
Location: Upstate New York
Distribution: Red Hat 9.0
Posts: 8

Original Poster
Rep: Reputation: 0
Yep

find /mnt/cdrom -iname '*.jpg' | xargs --replace cp {} /new/directory

Worked. Thanks for all of you help.
Leary
 
Old 07-12-2005, 02:13 PM   #11
Matir
Moderator
 
Registered: Nov 2004
Location: Kennesaw, GA
Distribution: Ubuntu
Posts: 8,502

Rep: Reputation: 110Reputation: 110
No problem. Glad it worked.
 
Old 07-12-2005, 11:26 PM   #12
WhatsHisName
Senior Member
 
Registered: Oct 2003
Location: /earth/usa/nj (UTC-5)
Distribution: RHL9;F1-10; CentOS4-5; DebianSarge-Squeeze
Posts: 1,151

Rep: Reputation: 45
Sounds like a job for rsync.

rsync -a /mnt/cdrom/*.jpg /new/directory

See:

man rsync
 
Old 07-13-2005, 08:45 AM   #13
Matir
Moderator
 
Registered: Nov 2004
Location: Kennesaw, GA
Distribution: Ubuntu
Posts: 8,502

Rep: Reputation: 110Reputation: 110
Quote:
Originally posted by WhatsHisName
Sounds like a job for rsync.

rsync -a /mnt/cdrom/*.jpg /new/directory

See:

man rsync
/mnt/cdrom/*.jpg would generate "Argument list too long" again.
 
Old 07-13-2005, 09:39 AM   #14
WhatsHisName
Senior Member
 
Registered: Oct 2003
Location: /earth/usa/nj (UTC-5)
Distribution: RHL9;F1-10; CentOS4-5; DebianSarge-Squeeze
Posts: 1,151

Rep: Reputation: 45
Quote:
/mnt/cdrom/*.jpg would generate "Argument list too long" again.
That’s interesting. I’ve used rsync on several occasions to copy over 800,000 files at a time when moving things around on servers. It takes a while, but a lot less time than cp.
 
Old 07-13-2005, 10:49 AM   #15
Matir
Moderator
 
Registered: Nov 2004
Location: Kennesaw, GA
Distribution: Ubuntu
Posts: 8,502

Rep: Reputation: 110Reputation: 110
Quote:
Originally posted by WhatsHisName
That’s interesting. I’ve used rsync on several occasions to copy over 800,000 files at a time when moving things around on servers. It takes a while, but a lot less time than cp.
If you wanted to move everything in /mnt/cdrom, it would be fine to use rsync /mnt/cdrom /destination, but with the *.jpg, that causes the shell to perform file globbing (wildcard expansion), generating an argument list > 131,072 characters (at least on my machine, 'getconf ARG_MAX' to check yours).
 
  


Reply


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy files from multiple directories into one directory MadRabbit Linux - Newbie 5 01-07-2009 03:21 PM
search and copy multiple files NiallC Programming 2 04-29-2005 04:40 AM
Multiple file copy james.farrow Linux - Newbie 8 08-17-2004 08:01 AM
find and copy files into multiple directories avargas22 Linux - Newbie 2 04-01-2004 11:11 AM
copy multiple files into one file HelpPlease Programming 2 12-09-2003 02:36 PM


All times are GMT -5. The time now is 04:22 PM.

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
Open Source Consulting | Domain Registration