Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

linux use watch command with multiple calls

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. :(

like image 594
sjas Avatar asked Mar 18 '15 10:03

sjas


People also ask

How does watch command work in Linux?

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.

Can you run multiple commands in Linux?

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.

How do you run multiple commands in one?

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.


1 Answers

watch by default runs the passed command in shell so you can pass it any command valid for shell:

watch 'ls dir1; ls dir2'
like image 93
StenSoft Avatar answered Oct 12 '22 05:10

StenSoft