Linux 'grep' only highlights but doesn't filter [duplicate]
Linux 'grep' only highlights but doesn't filter [duplicate]
This question already has an answer here:
question is in the title.
I'm trying to perform
"du -sh * | grep '^[0-9]'"
on my root dir to filter out any ... cannot access ..., but my console will just color matches and print out everything.
Thanks for any help
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
1 Answer
1
When you run a command, it will always open 3 files: stdin
(keyboard input), stdout
(command output) and stderr
(command output for error messages), these are numbered from 0 to 2.
stdin
stdout
stderr
Those error messages from du
are written to stderr
, while the normal output is written to stdout
. This allows you to redirect the error messages to /dev/null. This makes the error messages disappear, you don't need grep for that.
du
stderr
stdout
du -sh * 2>/dev/null
thanks alot, i was banging my head against the wall the last half an hour because of this :D
– DaedraEYE
Jun 30 at 20:34