Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
03-25-2004, 05:35 PM
|
#1
|
|
LQ Newbie
Registered: Mar 2003
Location: Canada
Distribution: Slackware 8.x, 9.x
Posts: 26
Rep:
|
Copy files from multiple directories into one directory
This is prolly a no-brainer but I can't seem to see the soultion ...
I have files scattered throughout numerous subdirectories, and I would like to collect them all into one single directory. What command (or script) can I run to do this? cp and cpio seem to try and make the full path under the new directory, but that's not what I want. I just want all the files in one directory.
|
|
|
|
03-25-2004, 06:42 PM
|
#2
|
|
Member
Registered: Mar 2004
Location: US
Distribution: Redhat 9 - Linux 2.6.3
Posts: 836
Rep:
|
#!/bin/sh
echo "what files to collect:"
read collection
echo "Where do you want these:"
read destination
mv $collection $destination
exit
specifying full path-to-file names would probably work if not use a wildcard or modify the script.
or use cp.
and make sure the destination directory already exists.
if you need to specify multiple directories and files of a certain type, and it doesnt seem to work with this script for any reason you will need to cd to $directory and mv * $destination
get it.
Last edited by AutOPSY; 03-25-2004 at 06:49 PM.
|
|
|
|
03-25-2004, 06:52 PM
|
#3
|
|
Moderator
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,916
|
Re: Copy files from multiple directories into one directory
Quote:
Originally posted by MadRabbit
This is prolly a no-brainer but I can't seem to see the soultion ...
I have files scattered throughout numerous subdirectories, and I would like to collect them all into one single directory. What command (or script) can I run to do this? cp and cpio seem to try and make the full path under the new directory, but that's not what I want. I just want all the files in one directory.
|
find may well be the right tool for the job,
depending on the criteria you want to apply
for the selection of files ...
find <start directory> -iname "<all my files type>" -exec cp {} <target_dir> \;
If you can tell me what the criteria are I
can make more specific examples ...
Cheers,
Tink
|
|
|
|
03-26-2004, 08:44 AM
|
#4
|
|
LQ Newbie
Registered: Mar 2003
Location: Canada
Distribution: Slackware 8.x, 9.x
Posts: 26
Original Poster
Rep:
|
Re: Re: Copy files from multiple directories into one directory
Quote:
Originally posted by Tinkster
find <start directory> -iname "<all my files type>" -exec cp {} <target_dir> \;
|
Thanks, Tink
That's just what I was looking for.
J
|
|
|
|
03-26-2004, 03:07 PM
|
#5
|
|
Moderator
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,916
|
Re: Re: Re: Copy files from multiple directories into one directory
Quote:
Originally posted by MadRabbit
Thanks, Tink
That's just what I was looking for.
J
|
Sweet :} ...
One is glad to be of help!
Cheers,
Tink (discreetly pointing at the affero button) :}
|
|
|
|
01-07-2009, 03:21 PM
|
#6
|
|
LQ Newbie
Registered: Jan 2009
Posts: 1
Rep:
|
Copy files from multiple directories into multiple directories
I found the solution looking at your suggestions! thank you all for saving me days of (repetitive) work!
Using the suggestions, I figure out how to copy directories from multiple directories, saving them into new multiple directories with part of the name maintained!
Ex: You have many directories with name d7q32. They are inside other directories with different names (ex: blabla/bleble/d7q32, bobo/bebe/d7q32 and so on). You got to find only the information about d7q32, also keeping part of their directory tree name. Linuxly speaking, find . -type d -name "d7q32". But now you must copy it to a new place, so you want to execute cp on top of this search keeping the parents' directory structure, saving this structure in a new directory called mynewdir. The final {} \ is just find/exec stuff, don't worry.
find . -type d -name "d7q32" -exec cp -rf --parents {} mynewdir \;
|
|
|
|
11-29-2012, 01:41 PM
|
#7
|
|
LQ Newbie
Registered: Nov 2012
Posts: 1
Rep: 
|
Thank you so much. Exactly what I needed!
|
|
|
|
11-30-2012, 10:39 AM
|
#8
|
|
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,697
|
Please think carefully before re-opening old threads like this. It's usually discouraged unless you have something substantial to add to that discussion (e.g. corrections or updated information).
Also please state clearly when you do so, so that others who read it don't accidentally reply to a poster who is no longer active.
Now to supply my own addition to the discussion, here are a couple of useful links on using find:
http://mywiki.wooledge.org/UsingFind
http://www.grymoire.com/Unix/Find.html
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 06:33 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|