I'm kind of confused about how Linux handles redirection operators.
I have in my home directory just one file:
andy$: ls demo.mp4
Now, if I send the
ls output to a file, I should see only
demo.mp4 in the file because there is nothing in the directory other than this file:
andy$: ls > myfile
But I actually noticed
myfile contains itself!
andy$ cat myfile demo.mp4 myfile <-- ???
So this means that
ls gets executed after the creation of
- List directory content with
- Write the content (now
So in case I need to exclude the file I'm redirecting to I think I should do:
ls | grep -v "myfile" > myfile
So first, am I right?
If so, why? Where can I find more information on this?