Bash Multiple Commands Output Combine

Combining Output from Multiple Commands in Bash

In the command-line language Bash on Linux PCs and servers, this article introduces how to combine the output of multiple commands into one output, and conversely, how to pass one output to multiple commands.

Shou Arisaka
2 min read
Nov 23, 2025

In the command-line language Bash on Linux PCs and servers, this article introduces how to combine the output of multiple commands into one output, and conversely, how to pass one output to multiple commands.

You don’t like your console getting messy with thousands of lines of output, right? When I don’t know how much output there will be, I always do tail -3 first. Or head -3, or wc would be fine too.

But there are also times when you want to do both head and tail, right? Actually, such situations occur quite often. It would be nice if we could do head, tail, and wc simultaneously.

(2021 addition: less is the best.)

Passing One Output to Multiple Commands

cat > hoge.md
hoge
fuga
foo
bar
# cat hoge.md | (head -3; tail -3) # => NG

cat hoge.md | tee >(head -1) >(tail -1)
hoge
fuga
foo
bar
hoge
bar  

# => In addition to normal cat output, head and tail outputs are appended respectively.

cat hoge.md | tee >(head -1) >(tail -1) 2>&1 1>/dev/null
hoge
bar

# => Remove cat output and output only head and tail outputs.

cat hoge.md | tee >(head -1 | wc) >(tail -1 >/dev/null ) 2>&1 1>/dev/null
1 1 5

# => Only head|wc output is output.

shell - How can I send stdout to multiple commands? - Unix & Linux Stack Exchange

Combining Multiple Commands into One Output

As a side note, it seems you can also do multiple commands together.

$ (echo zzz; echo aaa; echo kkk) | sort
aaa
kkk
zzz

bash - Pipe multiple commands into a single command - Stack Overflow

Share this article

Shou Arisaka Nov 23, 2025

🔗 Copy Links