在目录和子目录中查找并替换sed [英] Find and replace with sed in directory and sub directories

查看:449
本文介绍了在目录和子目录中查找并替换sed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行此命令在我的网站根目录中的所有文件中查找并替换所有出现的'apple'与'orange':
$ b

I run this command to find and replace all occurrences of 'apple' with 'orange' in all files in root of my site:

find ./ -exec sed -i 's/apple/orange/g' {} \;

但不通过子目录。

这个命令有什么问题?

编辑:这里是find ./命令的一些输出:

Edited: here is some lines of output of find ./ command:

./index.php
./header.php
./fpd
./fpd/font
./fpd/font/desktop.ini
./fpd/font/courier.php
./fpd/font/symbol.php


推荐答案

您的查找应该看起来像这样,以避免向sed发送目录名:

Your find should look like that to avoid sending directory names to sed:

find ./ -type f -exec sed -i -e 's/apple/orange/g' {} \;

这篇关于在目录和子目录中查找并替换sed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆