0

I have a project in Linux. I want to create a file named index.html in all folders.
So I have used the following command:

find . -type d -exec touch {}/index.html \;

It's working! Now I'm trying to copy the existing file from a given location and it to be automatically replaced into all the folders of my project.

3 Answers 3

1

This should actually work exactly in the same way:

find . -type d -exec cp $sourcedir/index.html {}/index.html \;
0
1

If I understand your question correctly, what you want is to copy a given file in all the directories.

You can use a similar find command :

find . -type d -exec cp -f /tmp/index.html {} \;

where /tmp/index.html is path to the original file (replace it with your own path).

Also, you don't need to create the files if your final objective is to replace them with the original file.

3
  • You must escape those { char-pairs. Apr 18, 2011 at 12:31
  • 1
    @Zsolt: Worked perfectly well on my ubuntu. Please try and see if it works for you. Apr 18, 2011 at 12:33
  • My bad. For some strange reason, I used to think it must be escaped, and did not checked the docs. Sorry. Apr 18, 2011 at 12:43
0
tar -cvzf index.tar.gz `find . -type f -iname 'index.html'` && scp index.tar.gz USER@SERVER:/your/projec/root/on/SERVER && ssh USER@SERVER "tar -xvzf index.tar.gz"

Or if you're in the proper directory localhost, and rsync is available:

rsync -r --exclude='**' --include='**/index.html' . USER@SERVER:/your/projec/root/on/SERVER

HTH

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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