Bash 如何向所有子目录中的所有PHP文件添加文本块?
我有一个PHP脚本,我需要在顶部添加我的版权。我只是想让它在以后出现 以下是需要添加的内容:Bash 如何向所有子目录中的所有PHP文件添加文本块?,bash,shell,command-line,command,Bash,Shell,Command Line,Command,我有一个PHP脚本,我需要在顶部添加我的版权。我只是想让它在以后出现 以下是需要添加的内容: /** * MySoftware * * This file is part of MySoftware. * * MySoftware is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by
/**
* MySoftware
*
* This file is part of MySoftware.
*
* MySoftware is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MySoftware is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MySoftware. If not, see <http://www.gnu.org/licenses/>.
*
* @copyright Copyright MySoftware
* @license GNU Public License V3.0
*/
/**
*MySoftware
*
*此文件是MySoftware的一部分。
*
*MySoftware是免费软件:您可以重新发布和/或修改它
*它是根据GNU通用公共许可证的条款发布的
*自由软件基金会,或者许可证的第3版,或者
*(由您选择)任何更高版本。
*
*MySoftware发布的目的是希望它会有用,
*但无任何保证;甚至没有任何关于
*适销性或适合某一特定目的。见
*有关更多详细信息,请参阅GNU通用公共许可证。
*
*您应该已经收到GNU通用公共许可证的副本
*还有我的软件。如果没有,请参阅。
*
*@版权所有MySoftware
*@license GNU Public license V3.0
*/
如果可以在上述消息前后添加一个空行,使其在每个文件中更加突出,那就太好了
将此添加到所有php文件顶部的最快方法是什么?有几百个,我已经将它们全部移动到一个主文件夹/子文件夹中,所以我想可以使用命令行递归运行一些东西,将其添加到每个主文件夹的顶部
如果有人能通过命令行或任何其他方法发布一个示例脚本/代码来说明如何做到这一点,那将不胜感激 #/bin/bash
#!/bin/bash
text="Hello world
What's up?"
exec 3<> $1 && awk -v TEXT="$text" 'BEGIN {print TEXT}{print}' $1 >&3
text=“你好,世界
怎么了?”
exec 3$1&&awk-v TEXT=“$TEXT”'开始{print TEXT}{print}'$1>&3
试试看。将文本保存到文件中,比如说
/tmp/header
,然后运行以下脚本
DIR=/your/php/files/dir
for f in $(find ${DIR} -iname "*.php" -type f 2>/dev/null) ; do
cat /tmp/header "${f}" > /tmp/tmp_file || continue
/bin/mv /tmp/tmp_file "${f}"
done
我需要对它做什么更改才能将其应用于所有PHP文件?看起来这是一个特定的文件…查找-名称'*php'-print | xargs-J%sh/from/the/revised/answer请注意,您要求执行的操作分为两个不同的任务:递归查找目录下的所有php文件,并在文件顶部添加一块文本。重复