Is it possible to make a bash script that starts tmux and split the screen horizontally and runs watch -n1 tail -n5 file_n in each ? Basically I'm starting a script multiple times and write its progress into different files that I'd like to monitor. Would be nice if I could run that from one script as opposed to manually open 10 files by myself. I never used tmux btw that's why I'm asking this.

  • 2
    Try to read the manual. Dec 15 '16 at 17:16

Try this. It first establishes a detached tmux session, then opens your windows with tail commands, then sets the layout of the windows, then attaches to the session.

for f in `seq 1 10`; do
if [[ $f -eq 1 ]]; then
        tmux new-session -d -s my_session_name "watch -n1 tail -n5 file_${f}"
        tmux split-window -d -t my_session_name:0 -p20 -v "watch -n1 tail -n5 file_${f}";
tmux select-layout -t my_session_name:0 even-vertical
tmux attach-session -t my_session_name

If you want to have multiple instances of this run, you need to change all the occurences of my_session_name to be something unique for each session.

Also, your title mentions 5 windows but the body of your post mentions 10 files. The code as-is will open 10 files in 10 windows. Change the seq 1 10 part for however many windows/files you actually want.

  • even-vertical is only mentioned once. did you mean to put that on line 3 or 5 perhaps?
    – Tomachi
    May 20 '20 at 3:01
  • @Tomachi did you try running it? You only need to set the layout after you’re done splitting windows.
    – dpw
    May 21 '20 at 4:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.