如何更改目录中所有文件中单词的所有出现 [英] How to change all occurrences of a word in all files in a directory

查看:81
本文介绍了如何更改目录中所有文件中单词的所有出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个User类,其中方法之一是get_privileges();.

I was in the process of creating a User class where one of the methods was get_privileges();.

经过数小时的敲打键盘操作,我终于发现,我继承这个特定数据库的前一个编码器将单词" privileges "拼写为" privacy ".在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文件夹中的每个位置,并将"特权"替换为"特权",这样我就不必处理这种错字并编写代码了?

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屋!

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