Methods for replacing files in batches in Linux

Source: Internet
Author: User
Method 1 for replacing files in batches in Linux: Search for www.2cto. comfind. -typef-name & quot ;*. html & quot; | xargsgrep & amp; lsquo; yourstring & amp; rsquo; 2: find and replace find-name & amp; #39; name of the file to be searched & amp; #39; | xargsperl
Method 1 for replacing files in batches in Linux: Search for www.2cto.com find. -type f-name "*. html "| xargs grep 'yourstring' 2: find and replace find-name' file name to be searched '| xargs perl-pi-e's | replaced string | g'perl-pi-e in add the-e option to the Perl command, followed by a line of code, it will run the code like running a common Perl script. using Perl from the command line can help implement some powerful and real-time conversions. Studying regular expressions carefully and using them correctly will save you a lot of manual editing work. 3: Batch modify the folder permission find. -type-d-name *. html | xargs chmod 755 4: modify the file permission in batches to find. -type-f-name *. html | xargs chmod 644 is a common operation. The tips described here can help you easily complete a large number of repetitive and tedious tasks. In this example. search for the string "password" grep "password" * in the c file "*. c. search for the file test in the current directory and its multiple subdirectories. cfind. -name "test. c "-print searches for the current directory and its subdirectories. vbs file and delete find. -name "*. vbs "-exec rm {}\; under the current directory and its multiple subdirectories. search for the string "password" find in the c file. -name "*. c "-print | xargs grep" password "in the current directory. in the c file, replace the string "password" with "pwd" perl-pi-e's/password/pwd/g '*. c in the current directory. in the c file, replace the string "password" with "pwd" and use. bak extension backup perl-pi. bak-e's/password/pwd/g '*. c in the current directory and subdirectory. in the c file, replace the string "password" with "pwd" find. -name "*. c "-print | xargs perl-pi-e's/password/pwd/g' use the sed operation to replace the format in batches: sed-I "s/search field/replace field/g" 'grep search field-rl path 'Linux sed batch replace strings sed-I "s/oldstring/newstring in multiple files /g "'grep oldstring-rl yourdir' example: replace www.csdn.net with www.iteye.com sed-I "s/www. csdn. net/www. iteye.com/g "'grep www. csdn. net-rl/mysites: sed-I "s/www. csdn. net/www. iteye.com/g "*

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.