8

I need to extract an archive and create a empty file in each of the folders contained within the archive.

I tried this:

for folder in `ls -d1 */` ; do touch "${folder}/COMPLETE"; done;

works just perfect till someone creates a folder with a space in its name.

How can I do this for all folders with or without spaces in their names?

\Hugo

Hugo
  • 12,334
  • 6
  • 30
  • 36

2 Answers2

14

You can use find instead:

find . -type d -exec touch {}/COMPLETE \;
dogbane
  • 266,786
  • 75
  • 396
  • 414
  • replaced . with * as I don't need a COMPLETE file in main directory. Thanks a lot! :) – Hugo Feb 09 '11 at 08:48
6

don't parse ls with for loop

for folder in */
do
  touch "$folder/COMPLETE"
done
kurumi
  • 25,121
  • 5
  • 44
  • 52