So, you want to run the same command over different terminals? By the end of this blog, hopefully you will know about this neat trick/hack to solve this problem.

Hopefully, you’re familiar with tmux. If not, basically it is a tool that is used as terminal multiplexer. You can create, access, control multiple terminals from a single screen(and many more things).

So, we will be using it to run the same command in different terminals. The command to do this is [prefix]:setw synchronize-panes. The default prefix is Ctrl + B. To disable this you can re-run the above command ([prefix]:setw synchronize-panes) to toggle the functionality.

Let us go through the above demonstration step by step:

  • Create a new session

tmux new -t random
  • Split window

    Split the window into multiple panes. For horizontal splitting you can use the shortcut [prefix] %, for vertical use [prefix] "

  • Synchronize Panes

    Use the command prefix :setw synchronize-panes to run the same command on all panes.

  • Disable the functionality

    In case you want to disable the functionality, and get back to your stuff, you can use the command

prefix :setw synchronize-panes

​ Some other situations where you may find this useful:

  • When debugging the same code for a different version of a python(or any other language). Suppose your code works when well in python3.6 but somehow fails in python3.7.
  • You want to make the same change inside your different projects.

Hopefully you can now execute the same command in different panes to reduce your time. That’s it in this post.

Till we meet in another post, keep hacking!!!