How to redirect output of a command in Linux
In Category Command Line
Many a times your script outputs lot of messages which may not be of any interest to the actual user. Also sometimes these messages may cause user not to notice any important messages printed in between. In such cases, it is good to redirect/hide/suppress the messages printed by commands present in your script.
The bash shell in Linux supports a redirection operator “>” using which all the messages printed by a command can be redirected to a file and hidden from the user screen. The following example creates a file message.txt with “Hello, Neo” i it.
[neo@techpulp ~]# echo Hello, Neo > message.txt [neo@techpulp ~]# cat message.txt Hello, Neo [neo@techpulp ~]#
There is no need to always create some files to hide the output of your script or command. Because if your aim is to just hide the messages, there is no point in consuming space on the hard drive. Instead you can redirect all messages to a special file /dev/null. Anything written to /dev/null will not be written anywhere but gone forever.
Recent Comments