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:
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 |
Re: Re: Copy files from multiple directories into one directory
Quote:
Thanks, Tink That's just what I was looking for. J |
Re: Re: Re: Copy files from multiple directories into one directory
Quote:
One is glad to be of help! Cheers, Tink (discreetly pointing at the affero button) :} |
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 \; |
Thank you so much. Exactly what I needed!
|
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 |
Still works 10 years later on MacOSX too. Thank you brother!
Quote:
|
All times are GMT -5. The time now is 10:42 PM. |