What is Redirection Operator ?

Redirection Operator

Both the symbols > and >> are called redirection operators in Linux.

Redirection operator is used to save the output after running a command to a file.

Let us understand what these two operators are ?

1.  >  Operator


Whenever you run the command, then the output comes on the screen,  if you want to store the output on the screen in a file, then you can do it through this operator.

* This operator should be used only with commands that output to the screen. 

* It overwrites the output of the command inside the file.

*If the file does not already exist then it creates the file and then stores the output in this file.

Syntax :

$ (command ) > File_Name

Example:- 


Tittle : ls -l Command Output 

In above picture you can see the output of ls command, now we will store this output in a file. 


Tittle : uses of > operator 

Using this Redirection operator ( > ), we have directly stored the output in a file named "redirection.txt".


Tittle : redirection.txt

You can see in the above image that the output is saved inside the file.


Uses of  > Operator 

1. storing the output of a command inside a file.

2.  Creation of new file.

3. Copy the file using cat command '$ cat file1.txt  >  file2.txt'

What is cat command ? learn more

How to list directory ? Learn more 

2.  >> Operator 

It is also used to store the output of the command inside the file but instead of overwriting it, it appends the output inside the file.

* This operator should be used only with commands that output to the screen. 


* It appends the output of the command inside the file.


*If the file does not already exist then it creates the file and then stores the output in this file.


Syntax :

$ (command)  >> File_Name


It is also used like > operator but it appends instead of overwriting.


                  Thank for Reading.......!


If you liked this article, please help others by sharing.If there is anything incorrect in this or it needs more improvement then you can  contact at quedry.me


Comments

Popular posts from this blog

ls command

wc Command

ifconfig command