Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
find ~/foldername -type f -name "*.c" -exec sed -i '1 i addtexthere' {} \;
share|improve this answer
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 posting your answer, you agree to the privacy policy and terms of service.

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