Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.
share|improve this question
1  
Well you need permissions in all the directories you want to copy that file into... –  Mat Jan 4 '12 at 8:41
    
Including '/'. Are you sure you want to do that? Anyway, this is off-topic for a programming community! –  Johnsyweb Jan 4 '12 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 '12 at 9:09
add comment

migrated from stackoverflow.com Jan 4 '12 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 {}/ \;
share|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 '12 at 9:08
    
@saras try changing to ! -name "/" instead. –  dogbane Jan 4 '12 at 9:17
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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