0

I want to copy only files not folders from one folder to another in linux. I am using the following command

cp sourceDir/* destDir

The above command does copy all files to destDir but the command does not stop processing. Any help would be much appreciated.

2
  • What do you mean by "does not stop processing"? the cp command should not copy folders unless you add the -r option – steeldriver Apr 10 '20 at 16:15
  • I mean command does not end, when i go to the destination folder, the files are copied there but, command does not finish – Waleed Naveed Apr 10 '20 at 18:54
1

Option 1

You can try the following trick and change your command to

cp sourceDir/*.* destDir

it will only copy files in the same folder, as long as they have the format like filename.ext. Make sure you have not folder with the same format.

Option 2

Otherwise you try the following command:

find /sourceDir/ -type f -execdir cp "{}" /destDir/ ";"

It will search for all files inside the sourceDir and then copies them to the destDir.

3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.