Link to home
Start Free TrialLog in
Avatar of gudii9
gudii9Flag for United States of America

asked on

what is 2> command used for

Hi,

what is 2> command used for

please advise
what is 2 what is >
ASKER CERTIFIED SOLUTION
Avatar of Lee W, MVP
Lee W, MVP
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gudii9

ASKER

bash-4.4$ 2>                                                                                                                                      
bash: syntax error near unexpected token `newline'                                                                                                
bash-4.4$ 2>errors.txt                                                                                                                            
bash-4.4$ 2>                                                                                                                                      
bash: syntax error near unexpected token `newline'                                                                                                
bash-4.4$ ls -ltr                                                                                                                                  
total 8                                                                                                                                            
-rw-r--r-- 1 13381 13381 978 Nov  9 20:39 README.txt                                                                                              
-rw-r--r-- 1 13381 13381   0 Nov  9 20:39 xyz.txt                                                                                                  
-rw-r--r-- 1 13381 13381  24 Nov  9 20:40 xyx.txt                                                                                                  
-rw-r--r-- 1 13381 13381   0 Nov  9 21:30 errors.txt                                                                                              
bash-4.4$ vi errors.txt                                                                                                                            
                                                                                                                                                   
[1]+  Stopped                 vi errors.txt                                                                                                        
i tried as above
https://www.tutorialspoint.com/unix_terminal_online.php

i opened error.txt but do not see any error message like below in that
bash: syntax error near unexpected token `newline'      

please advise
this is something you append to a command.  It is not a command meaning do this now and forever more.

Example:

Type ls and press enter
Now type ls -y and press enter
Now type ls -y 2>error.txt and press enter
with 2>error.txt nothing is displayed... but you just saw that ls -y gives an error.  So now open error.txt and you'll see the error that ls -y provided.  You redirected the standard error output of that command.
When would you use 2>? When you are running a script or a program that could return a lot of error information and capturing it to a file for later review makes sense.  Scripting could do this - using 2> would capture all errors a script generated but not all the noise (successes).