简体   繁体   中英

Linux find and replace

How can I replace "abc" with "abcd" on all files of a folder using shell?

Is it possible using sed command?

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' {} \;

Or if you are fan of xargs:

find . -type f  | xargs -I {}  sed -i 's/abc/abcd/g' {}
sed -i 's/abc/&d/g' *

应该管用。

是:

find /the/folder -type f -exec sed -i 's,\<abc\>,&d,g' {} \;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM