Linux find and replace

前端 未结 3 719
情深已故
情深已故 2021-02-01 07:59

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

Is it possible using sed command?

3条回答
  •  醉梦人生
    2021-02-01 08:53

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

提交回复
热议问题