(resource-terminal)=

# Terminal utilities

This section consists of quick references for the various functions/utilities that can be leveraged when interacting with Scrutinizer via command line.

```{seealso} 
See [this page](advanced-cli) for documentation for Scrutinizer's interactive command-line utility (scrut_util).
```

(qr-tmux)= 

## Tmux

When running a script or operation that may take a significant amount of time (e.g., upgrades, migrations, etc.), it is strongly recommended to do so within a tmux session. 

Frequently used tmux commands/actions:

:::::{dropdown} Starting a new tmux session (with an optional `SESSION_NAME` and/or `WINDOW_NAME`)

```cfg
tmux new [-s SESSION_NAME] [-n WINDOW_NAME]
```

:::::

:::::{dropdown} Terminating the current (or a specified) tmux session:

```cfg
tmux kill-ses [-t SESSION_NAME]
```

:::::

:::::{dropdown} Connecting/attaching to the last (or a specified) tmux session:

```cfg
tmux at [-t SESSION_NAME]
```

:::::

When running a script or operation, it can be also be helpful to create a new window or pane where the log file can be tailed using `less` (see below).

:::::{dropdown} Window shortcuts

```{list-table}
* - Create new window
  - **Ctrl** + **B**, **C**
* - Previous/next window
  - **Ctrl** + **B**, **P**/**N**
* - Switch to specified window number
  - **Ctrl** + **B**, **0**-**9**
* - Close current window
  - **Ctrl** + **B**, **&**
```

:::::

:::::{dropdown} Pane shortcuts

```{list-table}
* - Split current window into left/right panes
  - **Ctrl** + **B**, **%**
* - Split current window into top/bottom panes
  - **Ctrl** + **B**, **"**
* - Toggle between pane layouts
  - **Ctrl** + **B**, **Spacebar**
* - Switch to pane in the specified direction
  - **Ctrl** + **B**, **Arrow key**
* - Close current pane
  - **Ctrl** + **B**, **X**
```

:::::

(qr-less)=

## less

When running a migration, upgrade, or other operation in a tmux session, the log file can be tailed using `less` in a different window or pane:

```cfg
less [-i] <PATH/FILENAME>
```

```{note}
Less searches are case-sensitive by default. The `-i` option toggles on case-insensitive searches.
```

:::::{dropdown} Less shortcuts

```{list-table}
* - Tail file
  - **Shift** + **F**
* - Stop tailing
  - **Ctrl** + **C**
* - Navigate forward by one screen
  - **Ctrl** + **F**
* - Navigate backward by one screen
  - **Ctrl** + **B**
* - Go to end of file
  - **Shift** + **G**
* - Search forwards for `PATTERN`
  - /<PATTERN>
* - Search backwards for `PATTERN`
  - ?<PATTERN>
* - Next search match 
  - n
* - Previous search match
  - N
* - Filter *for* `PATTERN`
  - &<PATTERN>
* - Filter *out* `PATTERN`
  - !<PATTERN>
```





