1: Find
Find. -type f-name "*.html" |xargs grep ' yourstring '
2: Find and replace
Find-name ' filename to look for ' | 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