brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: { cmd1; cmd2; } > file redirects a whole shell group at once

Shell
~/tips/tip-shell-command-group-redirect

cat ~/tips/tip-shell-command-group-redirect.md

Sends the output of several commands to one file with a single redirect.

One redirect for several commands saves repeating it and avoids reopening the file.

{ date; uptime; df -h /; } > report.txt 2>&1

Curly braces run the commands in the current shell, so variables they set stay set. You need a space after { and a semicolon or newline before }. Parentheses ( ) run the group in a subshell instead, which is useful for a temporary cd. The redirect applies to the whole group, and the file is opened once.

Further reading: Bash manual: Command Grouping

More Shell tips zmv -n '(*).log' '$1.txt' zoxide query -ls project f=$(mktemp --suffix=.json) shopt globskipdots echo $EPOCHSECONDS All Shell tips (78) All topics

Link