Search replace text in a file from command line

Nginx webroot is defined in the following file:

/etc/nginx/sites-enabled/default

The following code specifies the webroot in this file

root /usr/share/nginx/html;

I change this webroot using a script. Following script will do this:

sudo sed -i -e 's/\/usr\/share\/nginx\/html/\/var\/www/' /etc/nginx/sites-enabled/default

-e indicates an expression. s/// does string search ands replace. We are simply replacing /usr/share/nginx/html with /var/www. /etc/nginx/sites-enabled/default simply indicate the file we wish to modify.

Technologies: