博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Linux 全局替换目录下包含关键词的文件的内容
阅读量:4229 次
发布时间:2019-05-26

本文共 570 字,大约阅读时间需要 1 分钟。

没啥多说的!下边这条命令就是搜索当前目录下的所有文件,并将文件里边包含的所有 world 替换成 hello。

注意事项:包含 grep 命令的是反引号 ` (反引号,反引号,反引号,重要的事情说三遍,如果不知道反引号是什么,可以去 Google 一下)而不是单引号 '。

sed -i "s/world/hello/g" `grep -rl world ./`

-i 参数表示直接在原文件中替换,不添加的话只是把替换的结果在命令行显示出来,原文件并不会真正被修改。

示例: 

[root@master shell_learning]# grep -r "world" ./ ./test.rb:    Hello world ./test1.txt:world./test2.rb:    return 'world' if item[root@master shell_learning]# sed -i "s/world/hello/g" `grep -rl world ./`[root@master shell_learning]# grep -r "hello" ./ ./test.rb:    Hello hello ./test1.txt:hello./test2.rb:    return 'hello' if item

 

转载地址:http://vjjqi.baihongyu.com/

你可能感兴趣的文章
网络通信编程学习笔记(七):Java与MQTT
查看>>
人工智能与机器学习学习笔记(二)
查看>>
Peer-to-Peer with VB .NET
查看>>
Java Database Programming Bible
查看>>
Model Driven Architecture: Applying MDA to Enterprise Computing
查看>>
Pro Jakarta Commons
查看>>
Pro JSP, Third Edition
查看>>
LightWave 3D 8 Revealed
查看>>
The Cg Tutorial: The Definitive Guide to Programmable Real-Time Graphics
查看>>
Operating Systems Design and Implementation (3rd Edition)
查看>>
Beginning Visual C# 2005
查看>>
Professional C# 2005
查看>>
Faster Smarter Beginning Programming
查看>>
The Essence of Object-Oriented Programming with Java and UML
查看>>
ROI of Software Process Improvement: Metrics for Project Managers and Software Engineers
查看>>
FileMaker 8 Functions and Scripts Desk Reference
查看>>
Web Security Field Guide
查看>>
Computer Animation: Algorithms and Techniques
查看>>
Multimedia-based Instructional Design
查看>>
3D Videocommunication : Algorithms, concepts and real-time systems in human centred communication
查看>>