Commenting multiple lines in a shell script using vi/vim in a single step

A text editor like vi or vim can be used to comment multiple lines in a shell script (or any other scrip or configuration file) in a single go rather than adding # or whatever that goes for a comment for the script in question.

Open the file to be edited using vi/vim using the command vi filename (where filename can be replaced by the name of the file), now enter the command mode by pressing : .In order to comment multiple lines ( i.e. to add a # to the beginning of the line) , say lines from 5 to 10 in the script, type the command
:5,10s/^/#/ # : in the command is part of entering the editing/ex mode in vi.

Note# The command :set nu can be used to view line numbers in vi/vim
Clarification
General Syntax
==============================================
:%s/r1/r2/ is the syntax used for string substitution in vi/vim
Syntax split
: Enter command mode
% Perform the command on all lines
s Short form for :substitute command
r1 Can be replaced with any string in the script/file that is to be replaced
r2 Can be replaced with any string which should replace the string r1 in the script/file
/ Used a separator
Changes from syntax in executed command
============================================

In the command that we used for substitution/adding comments to lines starting from 5 to 10
% has been replaced with 5,10 so that the command will be executed only for lines starting from 5 to 10
^ caret [^ ] matches the position before the first character in the string (hence in the command that we executed the substitution takes place for the position before the first character[=r1])
# Replacement for r2 in syntax (i.e. # is used as the character/string which substitutes r1[position before the first character])

Comment removal

In order to uncomment multiple lines (we will remove # from the lines that we have commented, i.e. from 5 to 10) we can use the command
:5,10s/^#//
Clarification
^# Matches all characters starting with # (since ^ means position before the first character, ^x [x can be replaced with any character which does not hold a special meaning in bash, or \x if x has got a special meaning] will match any line which has got x as the character at the first character)
// Two /s without any in between space :: hence substitution will completely remove # from the beginning without adding anything
Commenting all lines in a script/file
Open the file in vi/vim and use the command
:%s/^/#/g

g stands for global (so that the substitution will occur globally, i.e. for all lines in the script)
All the rest have already been explained in General Syntax
Note: For php files which treat ; as the commenting character instead of # , # can be replaced with ; i.e. for commenting all lines in a php file we can use the command %s/^/;/g

If you require help, contact SupportPRO Server Admin

Server not running properly? Get A FREE Server Checkup By Expert Server Admins - $125 Value

Tracked?

Privacy is everybody main concern especially while using the internet. Would you like to be tracked? Everyone would have the answer NO. Therefore, here is a solution in the form of a plugin/add-on. Best of all; it is FREE. Its compatible with Windows, Linux and even Mac. Currently it is available for the browsers: Chrome, Firefox, Safari, and Internet Explorer. The number of companies that are tracking you would surprise you. You would no longer have to worry about the ever-changing piracy policies.

Check out this video:

You can download it from here

Article Authored by Rosemary J Thomas
Author, Rosemary J Thomas, is the Business Development Executive with SupportPRO.
SupportPRO offers 24X7 technical support services to Web hosting companies and service providers.

If you require help, contact SupportPRO Server Admin

Server not running properly? Get A FREE Server Checkup By Expert Server Admins - $125 Value

Re-Route SMTP Via IP Tables

Consider a situation where the email server ip gets blacklisted in a server with any email server like exim or qmail, we can reroute the smtp via another IP using IP Tables.

For routing the SMTP via xxx.xxx.xx.xx, issue the following command:

iptables -t nat -A POSTROUTING -o eth0 -p tcp dport 25 -j SNAT to xxx.xxx.xx.xx

If you require help, contact SupportPRO Server Admin

Server not running properly? Get A FREE Server Checkup By Expert Server Admins - $125 Value

How to install nginx with upload-progress-module in the server?

You can install nginx with upload progress-module. You can follow the bellow steps to install.

1. cd /usr/local/src
2. wget http://nginx.org/download/nginx-0.8.53.tar.gz
(download from http://github.com/masterzen/nginx-upload-progress-module and sftp to “/usr/local/src”) masterzen-nginx-upload-progress-module-v0.8.1-0-gc740674.tar.gz
3. tar xzvf nginx-0.8.53.tar.gz
tar xzvf masterzen-nginx-upload-progress-module-v0.8.1-0-gc740674.tar.gz

4. cd nginx-0.8.53

./configure –prefix=/opt \
–sbin-path=/opt/sbin/nginx \
–conf-path=/opt/etc/nginx/http-nginx.conf \
–error-log-path=/var/log/http-nginx/error.log \
–http-log-path=/var/log/http-nginx/access.log \
–pid-path=/var/run/http-nginx.pid \
–lock-path=/var/lock/http-nginx.lock \
–user=www-data \
–group=www-data \
–with-http_realip_module \
–with-rtsig_module \
–with-http_gzip_static_module \
–with-http_stub_status_module \
–with-http_ssl_module \
–without-mail_pop3_module \
–without-mail_imap_module \
–without-mail_smtp_module \
–add-module=/usr/local/src/masterzen-nginx-upload-progress-module-c740674/

5. make
6. make install

You can control nginx from /etc/init.d/nginx <start/stop/restart> and the conf file by default is /etc/nginx/nginx.conf .

If you require help, contact SupportPRO Server Admin

Server not running properly? Get A FREE Server Checkup By Expert Server Admins - $125 Value