_                    _
  ___ | |__   __ _ _______ | |_
 / _ \| '_ \ / _` |_  / _ \| __|
| (_) | | | | (_| |/ / (_) | |_
 \___/|_| |_|\__,_/___\___/ \__|

bashusage, redirection and tips.

Commands can output to files or programs.

Overwrite file : ls > log
Append to file : ls >> log

Command results can:

  • be displayed on the terminal: stdout, file descriptor 1.
  • be an error: stderr, file descriptor 2.
When redirecting, only the output is sent, to add error, stderr must be added to stdout:
ls > log 2>&1
This redirects stderr(2) to stdout(&1) and the output is saved to log. &1 means 1 is a file descriptor, not a file.

back to top

Commands can be combined:

Sequential execution : command1 ; command2
Execute command2 if command1 was successful : command1 && command2
Execute command2 if command1 failed : command1 || command2

back to top

Commands can be grouped and redirected together.

( command1 && command2 ) >> log 2>&1

back to top

linux

- Archlinux manpages: bash(1)

back to top

ohazot | about | ohazot.com <admin@ohazot.com>

This document applies to: linux , OpenBSD 7.8 | Created:2026-03-27|Updated:2026-03-27|