Piping Commands Together

The pipe character “|”  is usually used to chain 2 or more commands. The pipe command will take the standard output (STDOUT) from the program that you are using and will sent as standard input (STDIN) for the command after the pipe.

Example: root@server:~# ls /var/log/ | grep mail

The “pipe” command will take the output of the ls command and “pipes” into the input of the grep command.

Redirecting Program Output to Files

There are situations when you want to save the output of a command to a file rather than displaying it on the screen or both save to a file and display. For instance if you want to create a file that contain a list of all files and directories from /var/www you can do something like this:

ls /var/www > www_list.txt

This will redirect the standard output to www_list.txt

Another similar command can be written so rather than creating a new file called www_list.txt to append the output to the end of the original file.

ls /var/www >> www_list.txt

  • > – if the file does not exist will be created,
  • >> – will append to the end of the file, and if the file does not exist will be created,
  • 2>> – will append only error to the file
  • 2>&1 – will redirect errors and the output in the same place.

This is my favorite and I think the more simple  if you want permanent redirect  from NON WWW to WWW insert the following code in the nginx configuration file nginx.conf :

server {
  listen 80;
  server_name www.debian-tutorials.com;
  rewrite ^/(.*)$ http://debian-tutorials.com/$1 permanent;
Permanent redirect from WWW to NON WWW in nginx, use this code in your nginx.conf :
server {
  listen 80;
  server_name debian-tutorials.com;
  rewrite ^/(.*)$ http://www.debian-tutorials.com/$1 permanent;


Apache2 is one of the most widely used HTTP server has a lot of features and can be customized in many ways.

In fact, to this web server, there are basically two ways you can do this, using .htaccess directives or using a file httpd.conf. .

Some people prefer to use. htaccess files, since they reside in the website and can be modified by the site owner, which is not the case for the daemon configuration file:


Permanent redirect  NON WWW to WWW using apache2 server configuration:
ServerName debian-tutorials.com
RedirectMatch permanent ^/(.*) http://www.debian-tutorials.com/$1
DocumentRoot /path/to/your/site/files/
ServerName www.debian-tutorials.com

Just put this in your ..htaccess file.

// .htaccess HTTP to HTTPS Rewrite Rule
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

The simplest way of achieving this is by altering the .htaccess file in your websites root directory.

Download the .htaccess file to your computer using your favorite FTP client, open and edit it.

If you do not have a .htaccess file you can create one and upload it, look harder tough, these files are usually hidden.

If your website root directory does have a .htaccess file open it and first check to see if the rewrite engine declaration is posted: RewriteEngine On

If the Rewrite Engine is On then go ahead and add this following code to your .htaccess file:

Remember to backup your .htaccess file before you start editing it. Continue Reading…