Sample Header Ad - 728x90

Is there a way to alias "redirect stdout and stderr to a file"?

3 votes
2 answers
526 views
# Relevant Context : ### Redirect standard out
command > file
command 1> file
### Redirect standard error
command 2> file
### Redirect standard out and standard error to separate files
command 2> error.txt 1> output.txt
### Redirect standard out and standard error to the same file
command > file 2>&1
command &> file # bash only? 
# For all I know, all the examples are bash-only, but the article called it out explicitly on this line
Warning: the following example redirects *only* stdout to file. This happens because the stderr is redirected to stdout before the stdout was redirected to file
command 2>&1 > file # incorrect!
# Question: In my mind, these symbols are completely arbitrary, and therefore, difficult to memorize. I know how to alias *commands*, but is there some way to alias these symbols to make them easier to remember? Something like this: ### Redirect standard out and standard error to the same file
command redirectStandardOutputAndError file
or even better:
command >outerr file
Bonus points if this works on zsh and bash, but I'm bash is the only requirement.
Asked by Daniel Kaplan (1070 rep)
Sep 24, 2023, 09:03 PM
Last activity: Apr 23, 2025, 01:56 PM