Mass modification of configuration files
Mass changes to configuration files may be required when there are abrupt, global changes on the server.
For example, changing the IP address or removing it from the server's network interfaces. Using either the panel interface or text editor, such changes would require a lot of time and are not always reasonable or even possible.
Changes can be done via the stream editor sed, as it allows you to find and fix recurring expressions:
sed -i "s/<old-value>/<new-value>/g" <path-to-files>
- -i or --in-place - modify files at their location, with backups created before editing,
- s or search - search for specific pattern,
- g or global - replace all occurrences of foo with the new value.
Before making any configuration changes, it is recommended to check that the backups of the files being changed are up to date.
Example
Changing Nginx web server configurations:
sed -i "s/192.168.0.100/192.168.0.108.208/g" /etc/nginx/vhosts/*/*
When this command is executed, the value 192.168.0.100 will be changed to 192.168.0.208 in all files in the /etc/nginx/vhosts/ directory and its subdirectories.