How to add text to the beginning of all files in a folder?

macos, terminal, unix

Solution

Find all files in the current directory and insert `0000000` at the beginning of the file using `sed`:

find . -maxdepth 1 -type f -exec sed -i.bk '1i \
0000000' {} \;

This will also create `.bk` file for each file in directory. If you are happy with the result just `rm *.bk` to delete the back up files.

Problem

I have a folder with 1,000 small text files in it, and I need to modify the files and add 7 zeroes to the beginning of every one. After I do this I'll be able to cat them all together. Is there an easy way to do this in terminal?

Original source

Related problems