首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何将文本块添加到所有子目录中的所有PHP文件?

如何将文本块添加到所有子目录中的所有PHP文件?
EN

Stack Overflow用户
提问于 2012-11-26 07:25:04
回答 2查看 828关注 0票数 1

我有一个PHP脚本,我需要添加我的版权在顶部。我只是想让它出现在

以下是需要添加的内容:

代码语言:javascript
运行
复制
/**
 * 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
*/

如果可以在上面的消息之前和之后添加一个空行,以便在可能的情况下在每个文件中突出显示,那就太好了。

什么是最快的方法来添加这个到我所有的php文件的顶部?有几百个,我把它们都移到了一个主文件夹/子文件夹中,所以我想可以用命令行递归地运行一些东西,将它们添加到每个文件夹的顶部。

如果任何人可以通过命令行或任何其他方法发布如何做到这一点的示例脚本/代码,将不胜感激!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-11-26 11:22:59

将文本保存到一个文件中,比如/tmp/header,然后运行以下脚本。

代码语言:javascript
运行
复制
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
票数 2
EN

Stack Overflow用户

发布于 2012-11-26 07:28:15

代码语言:javascript
运行
复制
#!/bin/bash
text="Hello world
What's up?"

exec 3<> $1 && awk -v TEXT="$text" 'BEGIN {print TEXT}{print}' $1 >&3

试试看。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13556671

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档