Bash Command to Replace a String in a File
If you want to replace a string in a file from the command line (bash), you can use the command sed. As an example, we want to replace PermitRootLogin yes by PermitRootLogin no in /etc/ssh/sshd_config:
sed -i -e 's/PermitRootLogin yes/PermitRootLogin no/g' /etc/ssh/sshd_config
If you want to do an case insensitive replace, you have to add /gi as suffix (instead of /g):
sed -i -e 's/permitrootlogin yes/PermitRootLogin no/gi' /etc/ssh/sshd_config
Related Posts
- Tutorial: Ubuntu 18.04 LAMP Setup for WordPress
- Find a File in Bash
- Install Umami Analytics with Let's Encrypt HTTPS
- Debug WordPress SQL Queries
- Install Sentry on Ubuntu 18.04 Using Nginx and Let's Encrypt Certificates
- Use Google Fonts Locally With GeneratePress
- Fix Linux File And Folder Permissions When Using Laravel Forge