LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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
  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
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
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,539

Rep: Reputation: 60
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
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
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
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
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
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
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
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
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: RHEL, AltimaLinux, Rocky
Posts: 1,151

Rep: Reputation: 46
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
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
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: RHEL, AltimaLinux, Rocky
Posts: 1,151

Rep: Reputation: 46
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
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
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



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy files from multiple directories into one directory MadRabbit Linux - Newbie 8 02-07-2014 07:56 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

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:13 PM.

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