[ACCEPTED]-How can I create a file in each folder?-linux
Accepted answer
find . -type d -exec touch {}/index.html \;
This'll create an index.html
in .
and all subdirectories.
0
cd /project_dir && find . -type d -exec touch \{\}/index.htm \;
HTH
0
Assuming you have a list of your project 6 directories in a file called "projects.txt", you 5 can do this (for bash and zsh)
for i in $(cat projects.txt)
do
touch $i/index.html
done
To create 4 your projects.txt, you can use the find
command. You 3 could replace the cat
directly with a find
invocation 2 but I thought it more clear to separate 1 the two operations.
I know it's an old question but none of 2 the current answers allow to add some sample 1 code, here my solution:
#create a temp file
echo "<?php // Silence is golden" > /tmp/index.php
#for each directory copy the file
find /mydir -type d -exec cp /tmp/index.php {} \;
#Alternative : for each directory copy the file where the file is not already present
find /mydir -type d \! -exec test -e '{}/index.php' \; -exec cp /tmp/index.php {} \;
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.