How to write a string to file and to stdout on console? 
If I do
echo "hello" > logfile.txt   I view only hello in logfile.txt but how can I write hello also on console of Linux?
Option One: Redirect Output to a File Only To use bash redirection, you run a command, specify the > or >> operator, and then provide the path of a file you want the output redirected to. > redirects the output of a command to a file, replacing the existing contents of the file.
Redirecting output to Multiple files and screen: If you want to redirect the screen output to multiple files, the only thing you have to do is add the file names at the end of the tee command.
Use the tee command:
echo "hello" | tee logfile.txt 
                        You can use >> to print in another file.
echo "hello" >> logfile.txt 
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With