Based on this answer, I want to perform an operation on all the files in a directory and its subdirectories.
The following command works a single file, and also works when used on multiple files in a loop.
for i in *.html; \ do sed -i '/<head>/a <link rel="stylesheet" href="/home/jian/postgres/doc/src/sgml/html/stylesheet.css">\' $i; \ done But the following command will not work.
find . -type d -exec \ for i in *.html; \ do sed -i '/<head>/a <link rel="stylesheet" href="/home/jian/postgres/doc/src/sgml/html/stylesheet.css">\' $i; \ done \ \; It gives the following error:
bash: syntax error near unexpected token `do' bash: syntax error near unexpected token `done' ;: command not found I found a related post here.
find . -type d -execif you want to make an operation on html files? Why notfind . -type f -name '*.html'and then exec thesedcommand directly on those files?--(need with GNUfindat least, the one that supports-iand can run commands) and the quotes around$i.