如何在Linux命令行中替换多个文件中的字符串 [英] How to replace a string in multiple files in linux command line

查看:197
本文介绍了如何在Linux命令行中替换多个文件中的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要替换文件夹中许多文件中的字符串,而只有ssh可以访问服务器.我该怎么办?

I need to replace a string in a lot of files in a folder, with only ssh access to the server. How can I do this?

推荐答案

cd /path/to/your/folder
sed -i 's/foo/bar/g' *

出现的"foo"将替换为"bar".

Occurrences of "foo" will be replaced with "bar".

在macOS上,您需要为-i-'.bak'或''提供备份扩展名

On macOS you need to provide a backup extension for -i - '.bak' or '' for no backup

cd /path/to/your/folder
sed -i '.bak' 's/foo/bar/g' *

这篇关于如何在Linux命令行中替换多个文件中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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