# Working with tmux

`tmux` is a very useful Linux command line tool. It allows you to create command line session that is persistent; meaning you can close the window and re-open it later and it remains in the same state. This allows you to do things such as start a long data compression operation from home then log out again, leaving the compression still running. `tmux` is therefore safe to use if you have a flaky network connection. You can also connect to existing `tmux` sessions. So if you start an operation locally on a PC, you can go home and re-connect to the same window. There is a [tmux tutorial here](https://edricteo.com/tmux-tutorial/) Below are details on some common operations that might be useful in the context of StitchIt.

## What to do if the last syncAndCrunch session is still stitching

Here is what to do if the previous `syncAndCrunch` session is stitching the last brain and you want to begin a new one.

1. Rename the existing `tmux` session to something memorable. e.g. if the current sample is called `XYZ-123` then we can rename the `tmux` session to `stitch_XYZ` by doing: `ctrl b` then press `$` then you can type the new name. Then press return.&#x20;
2. Now detach from the existing session with `ctrl b` then press `d`.&#x20;
3. You are now back at the non-tmux Linux command line (the green bar at the bottom has gone). You can verify your session is in the background with `tmux ls`. That lists all `tmux` sessions.&#x20;
4. Start a new session by typing `tmux`.
5. Rename it to whatever you normally call your `syncAndCrunch` `tmux` sessions. e.g. You might always name them after the microscope. To rename you can again do `ctrl b` then press `$` then type `slicerscope` or whatever the name is that you normally use.
6. Start MATLAB with `matlab`
7. When you are ready you can run `syncAndCrunch('slicerscope')` (substitute `slicerscope` with your rig name)
