Linux - General This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
 |
04-18-2014, 09:52 AM
|
#1
|
Member
Registered: Oct 2013
Posts: 532
Rep: 
|
Can i redirect any command to dev null?
Hello,
i have bash script and my question is if i can with peace of mind point any bash command into dev null? ( >/dev/null )
because i cant veriffy there are any errors or it really executed command. respectivelly how i can veriffy it, any advice? thx
|
|
|
04-18-2014, 10:25 AM
|
#2
|
Senior Member
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,269
|
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.
|
|
|
04-18-2014, 10:37 AM
|
#3
|
Senior Member
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,908
|
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.
|
|
|
04-18-2014, 11:03 AM
|
#4
|
LQ Guru
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
|
To amplify the answer about stderr and stdout:
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
|
|
|
All times are GMT -5. The time now is 10:48 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|