将版权信息插入多个文件 [英] Insert copyright message into multiple files
本文介绍了将版权信息插入多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在每个文件的最顶部插入版权信息?
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
递归解决方案(查找所有子目录中的所有.txt
文件):
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.
这篇关于将版权信息插入多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文