5.7. File redirection
When issuing commands, you can specify where you want the standard input, output and errors to go, and to be able to do this you need to do a bit of redirection. A combination of the most useful redirections with corresponding file descriptors is shown in Table 5.1.
When using standard error in redirection, you must use a file descriptor, but for standard input and output this is optional. Table 5.1 shows both methods for completeness.
Command > filename | Send standard output to a new filename |
Command >> filename | Send standard output to filename (appended) |
Command 1 > filename | Send standard output to filename |
Command > filename 2>&1 | Send all output (including errors) to filename ... |
Get Linux and Unix Shell Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.