This is mostly happen when we have many configuration or text files inside our Ubuntu / servers. For example , i have 5 nginx virtualhost files. For some reason, i need to change my sites to run NGINX on port 84. So i need to change
1 | listen 80; |
into
1 | listen 84; |
in each virtualhost files.
The fast way to do it is by using SED. The pattern is :
1 | sed -i 's/<search-string>/<replace-string>/ your-files' |
Here are example :
1 | sudo sed -i 's/listen 80;/listen 84;/' * |
Now all files which contain listen 80; will replaced with listen 84;. Easy right ?