Back

Ignoring Command Output in Linux

In Linux, you can ignore the output of a command by redirecting it to /dev/null, a special file that discards all data written to it. There are different ways to ignore various types of output:



                command > /dev/null # To ignore the standard output of a command

                command 2> /dev/null # To ignore the standard error of a command

                command > /dev/null 2>&1 # To ignore both the standard output and standard error of a command


                # Examples: 

                ls > /dev/null # If you want to ignore the standard output of ls

                ls /root 2> /dev/null # If you want to ignore the standard error of ls (e.g., when it encounters a directory it cannot access)

                ls /root > /dev/null 2>&1 # If you want to ignore both the standard output and standard error of ls

                command &>/dev/null # In Bash, you can use &>/dev/null to ignore both stdout and stderr

                ls /some/directory > /dev/null 2>&1 # To ignore the output of a command that lists the contents of a directory