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
  Search this Thread
Old 01-16-2005, 07:59 PM   #1
Hegemon
Member
 
Registered: Jan 2002
Location: Australia
Distribution: Gentoo
Posts: 103

Rep: Reputation: 15
Copying all files from subdirectories into one directory


I am wanting to copy all .jpg files from a directorie and its subdirectories into one directory however i carn't quite get it to work right. The main problem is that some of the files have spaces in their names so they get counted as multiple files. I have attempted to get the files enclosed in quotes however I can only get it to enclose all the files in one big quote or each files but in a way that still makes them go over several lines.

For instance if i have a directory tree as follows:
./Dir 1/File 1.jpg
./Dir 2/File 2.jpg

Code:
for i in `find -printf "\"%h/%f\"\n" | grep jpg`; { echo $i; }
will output:
Code:
"./Dir
1/File
1.jpg"
"./Dir
2/File
2.jpg"
I understand ls can automagically enclose the file names in quotes but it doens't appear to bable to list the directory name those files are in.
 
Old 01-16-2005, 08:53 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
find -iname "*jpg" -exec cp "{}" target_dir/. \;

sould do the trick ...


Cheers,
Tink
 
Old 01-17-2005, 01:22 AM   #3
Hegemon
Member
 
Registered: Jan 2002
Location: Australia
Distribution: Gentoo
Posts: 103

Original Poster
Rep: Reputation: 15
Thanks, that worked fine
 
Old 01-17-2005, 11:25 AM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Pleasure mate :)


Cheers,
Tink
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Bash, Find script files in a directory or subdirectories within... ray5_83 Programming 4 10-10-2008 07:42 PM
copy 3 files to a directory and all subdirectories? snip128 Linux - Newbie 9 08-12-2005 09:18 PM
Automatically Copying files from the ftp directory into the html directory swatward Linux - General 3 04-17-2005 10:55 PM
copying files to protected directory? webazoid Linux - Software 1 07-11-2004 09:08 AM
How to know the property a directory include the files and subdirectories? Xiangbuilder Linux - Newbie 3 08-31-2003 05:48 AM

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

All times are GMT -5. The time now is 09:06 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