Adding a line to multiple files in the same structure is not very hard, but I am stumped on how to do it over a possibly large directory tree structure. So lets say we have your project directory, which has hundreds of projects in it and you want to add a header to every *.c file. How can this be done? remember the files could be quite deep.

find ~/foldername -type f -name "*.c" -exec sed -i '1 i addtexthere' {} \;
  • 1
    Doesn't seem to work for me. – Recursion Mar 4 '11 at 20:16
  • can you paste few *.c lines of code – sush Mar 5 '11 at 2:54
  • They are empty files. – Recursion Mar 5 '11 at 3:06
  • sed -i '1 i addtexthere' does not work on empty files! – Volker Siegel Aug 4 '14 at 1:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.