如何更改目录中所有文件中出现的所有单词 [英] How to change all occurrences of a word in all files in a directory
问题描述
我正在创建一个 User
类,其中一个方法是 get_privileges();
.
I was in the process of creating a User
class where one of the methods was get_privileges();
.
在我的头撞到键盘上几个小时后,我终于发现我继承这个特定数据库的前一个编码员将privileges"这个词拼写为privelages"在 MySQL 数据库中,因此在数百个访问这些特权"的文件中的任何地方,都是这样拼写的.
After hours of slamming my head into the keyboard, I finally discovered that the previous coder who I inherited this particular database spelled the word "privileges" as "privelages" in the MySQL database, and thus also everywhere in the hundreds of files that access these "privelages" it is spelled that way.
在 Linux (Ubuntu Server) 中有没有一种方法可以遍历 /var/www
文件夹中的每个位置并替换privelagesstrong>" 和特权",这样我就不必处理这个错字和围绕它的代码?
Is there a way in Linux (Ubuntu Server) that I can go through every place in the /var/www
folder and replace "privelages" with "privileges", so that I don't have to deal with this typo and code around it?
推荐答案
考虑到子目录的变体(未经测试):
A variation that takes into account subdirectories (untested):
find /var/www -type f -exec sed -i 's/privelages/privileges/g' {} ;
这将find
/var/www
下的所有文件(不是目录,由-type f
指定),并执行sed
命令在它找到的每个文件上用特权"替换特权".
This will find
all files (not directories, specified by -type f
) under /var/www
, and perform a sed
command to replace "privelages" with "privileges" on each file it finds.
这篇关于如何更改目录中所有文件中出现的所有单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!