Please help me in solving the below issue:

I want copy a file say info.txt into multiples directories and their sub-directories .

I used this command:

  1. go to parent directory.
  2. find . -type d -exec cp ./info.txt {}/ \;

But I'm getting the below error:

cp: cannot create regular file /info.txt : permission denied.
link|improve this question
1  
Well you need permissions in all the directories you want to copy that file into... – Mat Jan 4 at 8:41
Including '/'. Are you sure you want to do that? Anyway, this is off-topic for a programming community! – Johnsyweb Jan 4 at 8:42
Thanks a lot MAt , I also changed the permissions by giving chmod -R 777 basic. Still I'm getting same error. – saras Jan 4 at 9:09
feedback

migrated from stackoverflow.com Jan 4 at 8:59

This question came from our site for professional and enthusiast programmers.

1 Answer

You don't have permission to copy to the root / directory. Are you sure you want to copy there?

Be aware that find . -type d will return the current directory (.), so copying ./info.txt to the current directory doesn't make sense, because it already exists there.

If you want to ignore the current directory use:

find . -type d ! -name "." -exec cp ./info.txt {}/ \;
link|improve this answer
Thanks a lot dogbane. Yes I do not want copy the file into current directory. But even after trying your command. I got same error.. – saras Jan 4 at 9:08
@saras try changing to ! -name "/" instead. – dogbane Jan 4 at 9:17
feedback

Your Answer

 
or
required, but never shown

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