1: Find
find.-type f-name "*.html" |xargs grep ' yourstring '
2: Find and replace
find-name ' filename ' to find ' | xargs perl-pi-e ' s| replaced string | replaced string |g '
perl-pi-e
By adding the- e option to the Perl command followed by a line of code, it runs the code as if it were running a normal Perl script.
using Perl from the command line can help implement some powerful, real-time transformations. Careful study of regular expressions and their proper use will save you a lot of manual editing work.
3: Bulk Modify folder Permissions
find.-type-d-name *.html|xargs chmod 755
4: Bulk Modify file Permissions
find.-type-f-name *.html|xargs chmod 644
finding and replacing is a very common operation.
The little tricks introduced here can make it easy to do a lot of repetitive, tedious work.
take an example to illustrate
Find the string "password" in the. c file in the current directory
grep "Password" *.c
find files in the current directory and its subdirectories test.c
find.-name "test.c"-print
find the. vbs file in the current directory and its subdirectories and delete it
find.-name "*.vbs"-exec rm {} \;
Find the string "password" in the. c file in the current directory and its subdirectories
find.-name "*.c"-print | xargs grep "password"
Replace the string "password" with "pwd" in the. c file in the current directory.
perl-pi-e ' s/password/pwd/g ' *.c
Replace the string "password" with "pwd" in the. c file in the current directory and back up with a. bak extension
perl-pi.bak-e ' s/password/pwd/g ' *.c
Replace the string "password" as "pwd" in the. c file in the current directory and subdirectories
find.-name "*.c"-print | xargs perl-pi-e ' s/password/pwd/g '
use SED to manipulate bulk replacements
format: sed-i "s/lookup field/replace field/g" ' grep lookup field-rl path '
linux SED Bulk replaces strings in multiple files
sed-i "s/oldstring/newstring/g" ' grep oldstring-rl yourdir '
For example: Replace the www.viiving.com in all files under/home to www.zjant.com
sed-i "s/www.viiving.com/www.zjant.com/g" ' grep www.viiving.com-rl/mysites
operation in current directory: Sed-i "s/www.viiving.com/www.zjant.com/g" *
Bulk replacement file content method under Linux