What does 2>/dev/null mean?
I would like a brief explanation of the following command line:
grep -i 'abc' content 2>/dev/null
command-line grep redirect stdout
add a comment |
I would like a brief explanation of the following command line:
grep -i 'abc' content 2>/dev/null
command-line grep redirect stdout
add a comment |
I would like a brief explanation of the following command line:
grep -i 'abc' content 2>/dev/null
command-line grep redirect stdout
I would like a brief explanation of the following command line:
grep -i 'abc' content 2>/dev/null
command-line grep redirect stdout
command-line grep redirect stdout
edited Sep 6 at 12:54
Zanna
50k13131238
50k13131238
asked Sep 26 '13 at 8:21
Naive
1,32481830
1,32481830
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
The > operator redirects the output usually to a file but it can be to a device. You can also use >> to append.
If you don't specify a number then the standard output stream is assumed but you can also redirect errors
> file
redirects stdout to file1> file
redirects stdout to file2> file
redirects stderr to file&> file
redirects stdout and stderr to file
/dev/null
is the null device it takes any input you want and throws it away. It can be used to suppress any output.
1
is there a difference between> /dev/null 2>&1
and&> /dev/null
– Alexander Mills
Oct 19 '17 at 0:25
6
In practice today I don't think there is2>&1
is an older syntax so&>
would not have worked years ago but both are equivalent.
– Warren Hill
Oct 19 '17 at 2:47
add a comment |
In short, it redirects stderr (fd 2) to the black hole (discards the output of the command).
Some more common use cases for redirection:
command > /dev/null 2>&1 &
Run command
in the background, discard stdout and stderr
command >> /path/to/log 2>&1 &
Run command
and append stdout and stderr to a log file.
2
Is there a good reason to use> /dev/null 2>&1
instead of&> /dev/null
?
– Craig McQueen
Nov 30 '15 at 6:43
6
@CraigMcQueen&>
is new in Bash 4, the former is just the traditional way, I am just so used to it (easy to remember).
– Terry Wang
Nov 30 '15 at 12:24
add a comment |
/dev/null
is treated as black hole in Linux/Unix, so you can put anything into this but you will not be able to get it back from /dev/null
.
Further, 2>
means that you are redirecting (i.e. >
) the stderr (i.e. 2
) into the black hole (i.e. /dev/null
)
Your command is:
grep -i 'abc' content 2>/dev/null
Don't try to end with another forward slash like this - 2>/dev/null/
(it's not a directory).
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f350208%2fwhat-does-2-dev-null-mean%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
The > operator redirects the output usually to a file but it can be to a device. You can also use >> to append.
If you don't specify a number then the standard output stream is assumed but you can also redirect errors
> file
redirects stdout to file1> file
redirects stdout to file2> file
redirects stderr to file&> file
redirects stdout and stderr to file
/dev/null
is the null device it takes any input you want and throws it away. It can be used to suppress any output.
1
is there a difference between> /dev/null 2>&1
and&> /dev/null
– Alexander Mills
Oct 19 '17 at 0:25
6
In practice today I don't think there is2>&1
is an older syntax so&>
would not have worked years ago but both are equivalent.
– Warren Hill
Oct 19 '17 at 2:47
add a comment |
The > operator redirects the output usually to a file but it can be to a device. You can also use >> to append.
If you don't specify a number then the standard output stream is assumed but you can also redirect errors
> file
redirects stdout to file1> file
redirects stdout to file2> file
redirects stderr to file&> file
redirects stdout and stderr to file
/dev/null
is the null device it takes any input you want and throws it away. It can be used to suppress any output.
1
is there a difference between> /dev/null 2>&1
and&> /dev/null
– Alexander Mills
Oct 19 '17 at 0:25
6
In practice today I don't think there is2>&1
is an older syntax so&>
would not have worked years ago but both are equivalent.
– Warren Hill
Oct 19 '17 at 2:47
add a comment |
The > operator redirects the output usually to a file but it can be to a device. You can also use >> to append.
If you don't specify a number then the standard output stream is assumed but you can also redirect errors
> file
redirects stdout to file1> file
redirects stdout to file2> file
redirects stderr to file&> file
redirects stdout and stderr to file
/dev/null
is the null device it takes any input you want and throws it away. It can be used to suppress any output.
The > operator redirects the output usually to a file but it can be to a device. You can also use >> to append.
If you don't specify a number then the standard output stream is assumed but you can also redirect errors
> file
redirects stdout to file1> file
redirects stdout to file2> file
redirects stderr to file&> file
redirects stdout and stderr to file
/dev/null
is the null device it takes any input you want and throws it away. It can be used to suppress any output.
edited Sep 26 '13 at 13:55
answered Sep 26 '13 at 8:38
Warren Hill
15.3k165376
15.3k165376
1
is there a difference between> /dev/null 2>&1
and&> /dev/null
– Alexander Mills
Oct 19 '17 at 0:25
6
In practice today I don't think there is2>&1
is an older syntax so&>
would not have worked years ago but both are equivalent.
– Warren Hill
Oct 19 '17 at 2:47
add a comment |
1
is there a difference between> /dev/null 2>&1
and&> /dev/null
– Alexander Mills
Oct 19 '17 at 0:25
6
In practice today I don't think there is2>&1
is an older syntax so&>
would not have worked years ago but both are equivalent.
– Warren Hill
Oct 19 '17 at 2:47
1
1
is there a difference between
> /dev/null 2>&1
and &> /dev/null
– Alexander Mills
Oct 19 '17 at 0:25
is there a difference between
> /dev/null 2>&1
and &> /dev/null
– Alexander Mills
Oct 19 '17 at 0:25
6
6
In practice today I don't think there is
2>&1
is an older syntax so &>
would not have worked years ago but both are equivalent.– Warren Hill
Oct 19 '17 at 2:47
In practice today I don't think there is
2>&1
is an older syntax so &>
would not have worked years ago but both are equivalent.– Warren Hill
Oct 19 '17 at 2:47
add a comment |
In short, it redirects stderr (fd 2) to the black hole (discards the output of the command).
Some more common use cases for redirection:
command > /dev/null 2>&1 &
Run command
in the background, discard stdout and stderr
command >> /path/to/log 2>&1 &
Run command
and append stdout and stderr to a log file.
2
Is there a good reason to use> /dev/null 2>&1
instead of&> /dev/null
?
– Craig McQueen
Nov 30 '15 at 6:43
6
@CraigMcQueen&>
is new in Bash 4, the former is just the traditional way, I am just so used to it (easy to remember).
– Terry Wang
Nov 30 '15 at 12:24
add a comment |
In short, it redirects stderr (fd 2) to the black hole (discards the output of the command).
Some more common use cases for redirection:
command > /dev/null 2>&1 &
Run command
in the background, discard stdout and stderr
command >> /path/to/log 2>&1 &
Run command
and append stdout and stderr to a log file.
2
Is there a good reason to use> /dev/null 2>&1
instead of&> /dev/null
?
– Craig McQueen
Nov 30 '15 at 6:43
6
@CraigMcQueen&>
is new in Bash 4, the former is just the traditional way, I am just so used to it (easy to remember).
– Terry Wang
Nov 30 '15 at 12:24
add a comment |
In short, it redirects stderr (fd 2) to the black hole (discards the output of the command).
Some more common use cases for redirection:
command > /dev/null 2>&1 &
Run command
in the background, discard stdout and stderr
command >> /path/to/log 2>&1 &
Run command
and append stdout and stderr to a log file.
In short, it redirects stderr (fd 2) to the black hole (discards the output of the command).
Some more common use cases for redirection:
command > /dev/null 2>&1 &
Run command
in the background, discard stdout and stderr
command >> /path/to/log 2>&1 &
Run command
and append stdout and stderr to a log file.
edited Sep 6 at 12:57
Zanna
50k13131238
50k13131238
answered Sep 26 '13 at 8:32
Terry Wang
6,23932224
6,23932224
2
Is there a good reason to use> /dev/null 2>&1
instead of&> /dev/null
?
– Craig McQueen
Nov 30 '15 at 6:43
6
@CraigMcQueen&>
is new in Bash 4, the former is just the traditional way, I am just so used to it (easy to remember).
– Terry Wang
Nov 30 '15 at 12:24
add a comment |
2
Is there a good reason to use> /dev/null 2>&1
instead of&> /dev/null
?
– Craig McQueen
Nov 30 '15 at 6:43
6
@CraigMcQueen&>
is new in Bash 4, the former is just the traditional way, I am just so used to it (easy to remember).
– Terry Wang
Nov 30 '15 at 12:24
2
2
Is there a good reason to use
> /dev/null 2>&1
instead of &> /dev/null
?– Craig McQueen
Nov 30 '15 at 6:43
Is there a good reason to use
> /dev/null 2>&1
instead of &> /dev/null
?– Craig McQueen
Nov 30 '15 at 6:43
6
6
@CraigMcQueen
&>
is new in Bash 4, the former is just the traditional way, I am just so used to it (easy to remember).– Terry Wang
Nov 30 '15 at 12:24
@CraigMcQueen
&>
is new in Bash 4, the former is just the traditional way, I am just so used to it (easy to remember).– Terry Wang
Nov 30 '15 at 12:24
add a comment |
/dev/null
is treated as black hole in Linux/Unix, so you can put anything into this but you will not be able to get it back from /dev/null
.
Further, 2>
means that you are redirecting (i.e. >
) the stderr (i.e. 2
) into the black hole (i.e. /dev/null
)
Your command is:
grep -i 'abc' content 2>/dev/null
Don't try to end with another forward slash like this - 2>/dev/null/
(it's not a directory).
add a comment |
/dev/null
is treated as black hole in Linux/Unix, so you can put anything into this but you will not be able to get it back from /dev/null
.
Further, 2>
means that you are redirecting (i.e. >
) the stderr (i.e. 2
) into the black hole (i.e. /dev/null
)
Your command is:
grep -i 'abc' content 2>/dev/null
Don't try to end with another forward slash like this - 2>/dev/null/
(it's not a directory).
add a comment |
/dev/null
is treated as black hole in Linux/Unix, so you can put anything into this but you will not be able to get it back from /dev/null
.
Further, 2>
means that you are redirecting (i.e. >
) the stderr (i.e. 2
) into the black hole (i.e. /dev/null
)
Your command is:
grep -i 'abc' content 2>/dev/null
Don't try to end with another forward slash like this - 2>/dev/null/
(it's not a directory).
/dev/null
is treated as black hole in Linux/Unix, so you can put anything into this but you will not be able to get it back from /dev/null
.
Further, 2>
means that you are redirecting (i.e. >
) the stderr (i.e. 2
) into the black hole (i.e. /dev/null
)
Your command is:
grep -i 'abc' content 2>/dev/null
Don't try to end with another forward slash like this - 2>/dev/null/
(it's not a directory).
edited Sep 13 at 6:51
Zanna
50k13131238
50k13131238
answered Jun 11 '15 at 10:57
Indrajeet Gour
16114
16114
add a comment |
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f350208%2fwhat-does-2-dev-null-mean%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown