1

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 Apr 10, 2020 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 Apr 10, 2020 at 18:54

1 Answer 1

2

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .