How can I combine two (or more) calls by the watch
command?
Such that they are run together (serially) and watch
shows their combined output?
I.e. watch command1 command2
So to show the contents of two different directories:
watch $(ls dir1) $(ls dir2)
(The subshell parens were just added for clarity.)
Of course I could create a script to run both commands, pipe the results into a tempfile and cat it for its contents periodically through watch, but I'd refrain from it if this is natively possible somehow. :)
Subshells, grouping, process substitution did not help me, so I am out of luck and have no idea where to look now.
Is this possible at all?
UPDATE:
watch cat <(ls dir1) <(ls dir2)
gives me on the first iteration what I'd love to see refreshed periodically, but not repeatedly. :(
The watch command is a built-in Linux utility used for running user-defined commands at regular intervals. It temporarily clears all the terminal content and displays the output of the attached command, along with the current system date and time. By default, the watch command updates the output every two seconds.
Linux allows you to enter multiple commands at one time. The only requirement is that you separate the commands with a semicolon. Running the combination of commands creates the directory and moves the file in one line.
Running Multiple Commands as a Single Job We can start multiple commands as a single job through three steps: Combining the commands – We can use “;“, “&&“, or “||“ to concatenate our commands, depending on the requirement of conditional logic, for example: cmd1; cmd2 && cmd3 || cmd4.
watch
by default runs the passed command in shell so you can pass it any command valid for shell:
watch 'ls dir1; ls dir2'
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