Help with "cp" command syntax
I have a directory with many sub-directories, each containing flies. I would like to copy all of these files (but not the directories) to another directory.
My attempts at recursively doing this with "-R" as well as "! -type d" does not work. |
Ok... let me see if I understand what you're trying to do...
You want to copy the non-directory contents of a tree of directories... for example, given the following tree: ./a/b/file1 ./a/file2 ./a/b/c/file3 you want file1, file2, and file3 to be copied elsewhere without maintaining the directory structure. You CANNOT do this with a single cp command - copying files recursively without maintaining the directory structure doesn't really make sense. Still, it's not an impossible or difficult task - you could do it in one line with find. Code:
find DIRECTORY_TO_COPY -not -type d -exec cp -d -i "{}" DESTINATION_DIRECTORY \; See man cp. See man find. |
Quote:
|
If you really want to copy the files from all sub-directories to a ginle directory, try this:
Code:
find /path/to/src/dir -type f -exec cp -i "{}" /path/to/dest/dir \; |
Thanks, I'll give it a try. Admittedly I didn't think about the dangers of filenames with the same name.
A poster above opined that it didn't really make sense to do this operation. There is a practical reason why I'm doing it: The sub-directories contain images. For presentation purposes I want to place all images in one directory so that they can be viewed sequentially would having to navigate between directories. |
In which case you might find "mv" a better option.
Or mmv even better if you have it on your distro. Multiple copied of images can eat disk space real quick. |
Quote:
You can generate the filename with a sequentially numbered prefix so it doesn't matter if there are duplicate names: Code:
$ mkdir picture_links The expansion of the n variable uses the braces because id we wrote this: Code:
$n_${f##*/} |
All times are GMT -5. The time now is 06:28 AM. |