[ACCEPTED]-How can I create a file in each folder?-linux

Accepted answer
Score: 30
find . -type d -exec touch {}/index.html \;

This'll create an index.html in . and all subdirectories.

0

Score: 4
cd /project_dir && find . -type d -exec touch \{\}/index.htm \;

HTH

0

Score: 2

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.

Score: 1

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 {} \;

More Related questions