How would you insert a copyright message at the very top of every file?
#!/bin/bash
for file in *; do
  echo "Copyright" > tempfile;
  cat $file >> tempfile;
  mv tempfile $file;
done
Recursive solution (finds all .txt files in all subdirectories):
#!/bin/bash
for file in $(find . -type f -name \*.txt); do
  echo "Copyright" > copyright-file.txt;
  echo "" >> copyright-file.txt;
  cat $file >> copyright-file.txt;
  mv copyright-file.txt $file;
done
Use caution; if spaces exist in file names you might get unexpected behaviour.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With