Linux - Delete lines with keyword in files recursively

Please use with caution!

Finding lines containing the keyword:
grep -rs keyword
-r - recursively
-s - ignore error messages
Search is case-sensitive - use -i to deactivate
Deleting lines in all files containing a certain keyword recursively:
find . -type f -print0 | xargs -0 sed -i /keyword/d
it is case-sensitive!
Bonus: if you only want to delete the keyword and not the whole lines:
find . -type f -print0 | xargs -0 sed -i s/keyword//g

Bonus: rename only files in the current directory use the -maxdepth 1 option like find . -maxdepth 1 -type f [...].



Most recent Articles:
  • Notice Board 003: Progress is Progress
  • How to: Cisco ISE backup to SFTP repository with public key authentication
  • Dummy IP & MAC Addresses for Documentation & Sanitization
  • Deploying ISSO Commenting System for Static Content using Docker
  • Generate a Vanity v3 Hidden Service Onion Address with mkp224o