I have to do watch two commands in the same terminal windows. I mean something like
watch du -h filename.txt && df -h
But its showing only one output.
So what I am thinking is may be its not possible to use watch to run multiple commands on the same window.
If there is any way , Please let me know.
Thank you.
You can quote the commands:
And they'll be executed together.
If you want to make sure both commands execute, one of the ways is to separate them with
;
instead of&&
.&&
allows the execution of second command (second operand, to the right of&&
) only if the first command executed successfully (exit status0
). If this is intended behaviour, go with&&
.For completeness sake...
The '|| true' part causes the first command to evaluate as true even if it fails for some reason. This will allow the next command after the && to execute no matter the output of first. This is most likely unnecessary for the scenario, just showing it to be possible.
For multiple commands to run simultaneously, use single
&
operator between the commands. Like:To clear any confusion, here's how different operators work: