Skip to content

How to redirect standard error in bash?

1 min read

2> is input redirection symbol and syntax is:

      1. To redirect stderr (standard error) to a file:
        command 2> errors.txt
      2. To redirect both stderr and stdout (standard output):
        command &> output.txt


How to redirect standard error in bash

Run find command and save all error messages to the find.error.txt file:


find / -name "*.conf" 2> find.error.txt

You can view find.error.txt with the cat command:


cat find.error.txt


This is useful in shell scripts or any other purpose.


How to redirect standard error and standard output in bash

You can send both stdout and stderr to a file named output.txt


command &>output.xt
find / -name "*.pl" &>filelist.txt

Please note that both errors and the actual output of the find command stored into a file:


cat filelist.txt

Related services

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Unmanaged dedicated servers

full root access and free IPMI KVM, with Free Basic Managed Support.

Linux server management

hardening, patching, monitoring and automation for Ubuntu, Debian, RHEL and AlmaLinux.

Was this answer helpful?

Still stuck? Open a ticket