Copy files from multiple directories into one directory
Linux - NewbieThis 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.
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
#!/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.
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 ...
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.