Question

I'd like to copy a content of directory 1 to directory 2. However, I'd like to only copy files (and not directories) from my directory 1. How can I do that ?

cp dir1/* dir2/*

then I still have the directories issue.

Was it helpful?

Solution

you can also use this in dir1

find . -type f -exec cp{} dir2/ \;

OTHER TIPS

You may try this one

cp dir1/*.* dir2/*

try this one

find dir1 -type f -exec cp {} dir2/ \;

The currently approved solution will work, however if sub-directories exist, this will also copy the files from the subfolders as well, but instead of putting the copied files in sub folders, it will copy them to dir1.

/dir1/dir1a/test.txt will end up as dir1/test.txt

-maxdepth can be used to only copy files in dir1:

find dir1 -maxdepth 1 -type f -exec cp {} dir2/ \;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top