Linux 批量查詢並替換資料夾下所有檔案的內容

2022-09-23 07:07:04 字數 1261 閱讀 8433

cd etc

grep -rn "

查詢的內容

" ./

cd etc

sed -i "

s/查詢的內容/替換後的內容/g

" `grep -rl "

查詢的內容

" ./`

sed -i "

s/要找查詢的文字/替換後的文字/g

" `grep -rl "

要找查詢的文字

" /任意資料夾`

sed -i '

s/selinux=enforcing/selinux=disabled/

' /etc/selinux/config 修改關閉selinux

setenforce 0

cat >> /usr/lib/systemd/system/nginx.service <

[unit]

description=nginx -high performance web server

documentation=http://

nginx.org/en/docs/

after=network-online.target remote-fs.target nss-lookup.target

[service]

type=forking

pidfile=/usr/local/nginx/logs/nginx.pid

execstartpre=/usr/sbin/nginx -t

execstart=/usr/sbin/nginx

execreload=//

usr/sbin/nginx -s reload

execstop=/usr/sbin/nginx -s stop

privatetmp=true

[install]

wantedby=multi-user.target

eof