When you use the redirect output symbol (>) on a command line, the shell creates the output file immediately, before the command is executed. Dem- onstrate that this is true.
$ ls aaa
ls: aaa: No such file or directory
$ ls xxxxx > aaa
ls: xxxxx: No such file or directory
$ ls aaa
aaa
The first command shows the file aaa does not exist in the working direc-
tory. The second command uses ls to attempt to list a nonexistent file
(xxxxx) and sends standard output to aaa. The ls command fails and sends
an error message to standard error (i.e., displays it on the screen). Even
though the ls command failed, the empty file named aaa exists. Because the
ls command failed, it did not create the file; the shell created it before calling
ls.
Computer Science & Information Technology