# Stop all runs before 'runN'?

**URL:** <https://cylc.discourse.group/t/stop-all-runs-before-runn/782>\
**Category:** Cylc Support\
**Created:** [October 13, 2023, 1:14am UTC](https://cylc.discourse.group/t/stop-all-runs-before-runn/782 "2023-10-13T01:14:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonnyhtw](https://yyz2.discourse-cdn.com/free1/user_avatar/cylc.discourse.group/jonnyhtw/32/232_2.png) [@jonnyhtw](https://cylc.discourse.group/u/jonnyhtw)\
**Post date:** [October 13, 2023, 1:14am UTC](https://cylc.discourse.group/t/stop-all-runs-before-runn/782/1 "2023-10-13T01:14:12Z")

</div>

hi there,

in my model development, i frequently get to the stage where i have loads of runs ‘alive’ at the same time because of trial and error…

is there a way to run something like?..

`cylc stop -k workflow/run{all active runs before runN}`

just wondering!

cheers

![image](https://global.discourse-cdn.com/free1/uploads/cylc1/original/1X/4ce2389c82d9700f81e7f0dd8b9b05300b19b1a0.png)

---

<div class="post-metadata">

**Author:** ![jonnyhtw](https://yyz2.discourse-cdn.com/free1/user_avatar/cylc.discourse.group/jonnyhtw/32/232_2.png) [@jonnyhtw](https://cylc.discourse.group/u/jonnyhtw)\
**Post date:** [October 13, 2023, 1:22am UTC](https://cylc.discourse.group/t/stop-all-runs-before-runn/782/2 "2023-10-13T01:22:06Z")

</div>

for this particular example i’ve just done this which works fine, but just wondering if there is a more `cylc`-y way of doing it! 🙂

`for i in {1..20}; do cylc stop -k u-cw586/run$i; done`

---

<div class="post-metadata">

**Author:** ![hilary.j.oliver](https://yyz2.discourse-cdn.com/free1/user_avatar/cylc.discourse.group/hilary.j.oliver/32/4_2.png) [@hilary.j.oliver](https://cylc.discourse.group/u/hilary.j.oliver)\
**Post date:** [October 13, 2023, 5:21am UTC](https://cylc.discourse.group/t/stop-all-runs-before-runn/782/3 "2023-10-13T05:21:04Z")

</div>

Cylc commands support basic pattern-matching for workflow and task IDs. See `cylc help id`. Note you have to quote the pattern on the command line to protect it from immediate shell expansion.

There’s no pattern for `<= n` but it’s usually easy to get the result with one or two commands. For your example:

```console
$ cylc stop "u-cw586/run?[!1]" # any character, then any character except 1

```

For running workflows, check you got the pattern right first with `cylc ping`:

```console
$ cylc ping "u-cw586/run?[!1]"
u-cw586/run14
u-cw586/run15
u-cw586/run16
u-cw586/run17
u-cw586/run18
u-cw586/run19
u-cw586/run20

```

(This pattern wouldn’t be correct if any of runs 1 through 11 were active, but it is correct for the group of runs shown in your screenshot above).

---

<div class="post-metadata">

**Author:** ![jonnyhtw](https://yyz2.discourse-cdn.com/free1/user_avatar/cylc.discourse.group/jonnyhtw/32/232_2.png) [@jonnyhtw](https://cylc.discourse.group/u/jonnyhtw)\
**Post date:** [October 16, 2023, 10:31pm UTC](https://cylc.discourse.group/t/stop-all-runs-before-runn/782/4 "2023-10-16T22:31:35Z")

</div>

thanks @hilary.j.oliver,

ok that’s super helpful.

one of the things that i come up against a lot (not just `cylc`!) is that when using pattern-matching (same as ‘regex’?) is that i don’t know exactly what type of patterns are matched. my understanding is that there are several types of regex? do you have a link to a dictionary or similar of exactly what is matched by cylc in this instance?

cheers,

---

<div class="post-metadata">

**Author:** ![hilary.j.oliver](https://yyz2.discourse-cdn.com/free1/user_avatar/cylc.discourse.group/hilary.j.oliver/32/4_2.png) [@hilary.j.oliver](https://cylc.discourse.group/u/hilary.j.oliver)\
**Post date:** [October 16, 2023, 11:45pm UTC](https://cylc.discourse.group/t/stop-all-runs-before-runn/782/5 "2023-10-16T23:45:07Z")

</div>

Well, regular expressions are a particularly powerful and general kind of pattern matching for arbitrary text. But like anything in computing, capabilities have evolved and different implementations support different syntax and different concepts. To be sure of what’s supported, you really have to consult the documentation for the language or program you’re using.

There are also simpler kinds of pattern matching, such as shell “globbing”, as used for matching filenames in Bash etc., with only a few simple meta-characters.

The Cylc CLI just uses a type of globbing for matching workflow IDs, because going full regex would be overkill.

See `cylc help id` for details!

---

<div class="post-metadata">

**Author:** ![MetRonnie](https://yyz2.discourse-cdn.com/free1/user_avatar/cylc.discourse.group/metronnie/32/125_2.png) [@MetRonnie](https://cylc.discourse.group/u/MetRonnie)\
**Post date:** [October 17, 2023, 10:30am UTC](https://cylc.discourse.group/t/stop-all-runs-before-runn/782/6 "2023-10-17T10:30:55Z")

</div>

Just to be clear - these are glob patterns, not regex patterns. See [glob (programming) - Wikipedia](https://en.m.wikipedia.org/wiki/Glob_(programming)#Syntax) for the syntax

---

<div class="post-metadata">

**Author:** ![jonnyhtw](https://yyz2.discourse-cdn.com/free1/user_avatar/cylc.discourse.group/jonnyhtw/32/232_2.png) [@jonnyhtw](https://cylc.discourse.group/u/jonnyhtw)\
**Post date:** [October 19, 2023, 10:33pm UTC](https://cylc.discourse.group/t/stop-all-runs-before-runn/782/7 "2023-10-19T22:33:33Z")

</div>

thanks a lot @hilary.j.oliver and @MetRonnie

i must admit i hadn’t come across `!` used in globs before.

cheers
