Create file in Linux and replace content
I have a pro开发者_C百科ject in Linux. I want to create a file named index.html
in all folders.
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.
This should actually work exactly in the same way:
find . -type d -exec cp $sourcedir/index.html {}/index.html \;
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.
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
精彩评论