Silence Result of Command
When you want to silence the result of a command in a Unix-like shell environment, you can use the > /dev/null or 2> /dev/null redirection techniques, depending on whether you want to suppress standard output (stdout) or standard error (stderr) respectively. Here’s how you can use them:
-
To silence standard output (stdout) of a command, use
> /dev/null:1command > /dev/nullThis will discard the normal output of the command.
-
To silence standard error (stderr) of a command, use
2> /dev/null:1command 2> /dev/nullThis will discard error messages and keep only the standard output.
Here’s an example of how you might use these redirections in practice:
|
|
In the first command, the standard output of the ls command is redirected to /dev/null, so you won’t see the list of files and directories in /nonexistent-directory. In the second command, the standard error is redirected to /dev/null, so you won’t see any error messages if the directory doesn’t exist or if there’s a permission issue.