Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

There is no file in my directory called a. I used the command "rm a 2>a" to redirect the standard output error to file a. But when I tried the "ls" command, there is no file called a. Can someone explain this?

share|improve this question
2  
voting to move to superuser –  Ben Voigt Aug 2 '10 at 17:07
    
Well ... what happens when you do not redirect? Is anything printed to stdout? –  Fantomas Aug 2 '10 at 17:11
2  
Is this merely an academic question? What's your use case for using the same file name both for deletion and capturing the output? –  Doug Harris Aug 2 '10 at 18:09
add comment

migrated from stackoverflow.com Aug 2 '10 at 17:12

This question came from our site for professional and enthusiast programmers.

2 Answers

2>a causes the shell to redirect the standard error stream to a file called a. This file is created before the command is started. rm is then executed. It finds a file called a (already created by the shell) and unlinks it.

share|improve this answer
4  
Right... the file still exists, so that anything rm writes to stderr after calling unlink can go into it, but it no longer has its name. When the process quits, the file finally goes away. –  Ben Voigt Aug 2 '10 at 17:17
add comment

a is created bbefore the rm command executes....its as simple as that!

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.