Linux find and replace strings in all Files under directory (reprinted)

Source: Internet
Author: User

Transferred from: http://rubyer.me/blog/1613/

  

Finding and replacing in a single file is simple, just don't say it. The search and replace of strings in all files in the folder will be remembered, recently deployed dozens of Linux servers, the summary is recorded.

Find files that contain strings under a folder

Example: Find all files in the/usr/local directory that contain "Rubyer.me".

' rubyer.me ' /usr/local/*
Vim replaces all string methods in a single file

Example: Replace all old in the current file with new

:%s/old/New/g#% means that the substitution says there is a row, and g means replacing all occurrences in a row.
Replace a file with a string under a folder

Sed combined with grep
Example: To change the Zhangsan in all files below the directory/www to Lisi, do this:

" s/old/new/g " ' grep old-rl/www '
Label:

>> original articles, welcome reprint. Reproduced please specify: Reproduced from Ruby fans, thank you!
>> original link address: Linux find and replace all files in the directory in the string

Linux find and replace strings in all Files under directory (reprinted)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.