Linux查找并替换 [英] Linux find and replace
本文介绍了Linux查找并替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用Shell在文件夹的所有文件上将"abc"
替换为"abcd"
?
How can I replace "abc"
with "abcd"
on all files of a folder using shell?
是否可以使用sed
命令?
推荐答案
尝试对文件file.txt使用以下命令:
Try the following command for the file file.txt:
sed -i 's/abc/abcd/g' file.txt
对当前文件夹中的所有文件尝试以下命令:
Try the following command for all files in the current folder:
find . -maxdepth 1 -type f -exec sed -i 's/abc/abcd/g' {} \;
对于当前目录和所有子目录中的文件:
For the files in the current directory and all subdirectories:
find . -type f -exec sed -i 's/abc/abcd/g' {} \;
或者,如果您是xargs的粉丝:
Or if you are fan of xargs:
find . -type f | xargs -I {} sed -i 's/abc/abcd/g' {}
这篇关于Linux查找并替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文