Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
That won't redirect errors, since they normally print to stderr, not stdout.
Many commands have a return code $? which you can test to see if the command executed correctly.
You can redirect any command to /dev/null. All it does is discard any output sent.
Redirection is setup by the shell usually - and that means that any executable can have stdin/stdout/stderr redirected to /dev/null. When stdin is redirected, it causes an end of file condition on a read.
This has no effect on any files opened by that executable (which includes shell scripts that may redirect things elsewhere).
As for verify - in what way do you mean by verify? If you mean "show no output" well, verification is no output... If you mean "the command had no error" then it depends on the command. Nearly all commands will exit with a 0 status on success, and non-zero status on failure. User applications might not follow that standard though. If you mean to identify WHAT error occurred, then you are out of luck. Most exit status reflect only that an error occurred (usually when the status is 1), but not what the error was - that is what stderr is used for.
stdout = Standard Output = File Descriptor 1
stderr = Standard Error = File Descriptor 2
It is normal to have background processes either log or go to /dev/null if you don't care about logging.
The ">" by itself redirects stdout by default and is equivalent to "1>".
The ">>" redirects stdout but appends (useful for logging) rather than overwriting.
To send BOTH stdout and stderr to the same place you can use a shortcut such as the following that would send stdout to /dev/null then redirect stderro to stdout (which has already been defined as /dev/null):
>/dev/null 2>&1
The 2>&1 says to redirect file descriptor 2 into file descriptor 1 so they both end up in /dev/null.
Note that order is important. You would not do:
2>&1 >/dev/null
as that would send stderr to wherever stdout was BEFORE you told stdout to go to /dev/null
Similarly you could go to a log file:
>/var/log/mylog 2>&1
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.