I'm running multiple commands in my Linux shell at the same time, e.g.
echo "Line of text 1" && echo "Line of text 2" && complexthing | xargs printf "complexspecifier"
I want to redirect all output to file1
. I know I can add >file1
after each individual command but this seems bulky. How can I do this?
If you don't need to run your commands in a subshell, you could use
{ ... } > file
:Note that you need a space after
{
and a semicolon before}
, unless you have an&
or a newline after the last command.Or, if you are on a machine that doesn't have
/dev/tty
, you can do:Figured it out. You can use parenthesis around the commands, then append
>file1
: