# Ignore patterns in the form of "include only these" and "exclude" everything else inside a given root folder

**URL:** https://forum.syncthing.net/t/ignore-patterns-in-the-form-of-include-only-these-and-exclude-everything-else-inside-a-given-root-folder/17654
**Category:** Support
**Created:** [November 28, 2021, 6:07am UTC](https://forum.syncthing.net/t/ignore-patterns-in-the-form-of-include-only-these-and-exclude-everything-else-inside-a-given-root-folder/17654 "2021-11-28T06:07:12Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![pilgrim](https://forum.syncthing.net/letter_avatar_proxy/v4/letter/p/5e9695/32.png) [@pilgrim](https://forum.syncthing.net/u/pilgrim)
#### Post date: [November 28, 2021, 6:07am UTC](https://forum.syncthing.net/t/ignore-patterns-in-the-form-of-include-only-these-and-exclude-everything-else-inside-a-given-root-folder/17654/1 "2021-11-28T06:07:12Z")

</div>

I went through [couple](https://forum.syncthing.net/t/include-only-vs-exclude-ignore/7491/5) of [posts](https://forum.syncthing.net/t/un-ignore-subfolders-files-of-ignored-folder/1460/12) here and I still have doubts.

I will be syncing from Mac folder `/Users/user`(this is the single common root folder of all the folders I want to sync) – **but** I want to include ONLY the listed folders and ONLY THESE; nothing else.

My intended sync/include set:

**BLOCK A**

```
!/Users/user/.ssh
!/Users/user/.notes
!/Users/user/.dotfiles
!/Users/user/Pictures
!/Users/user/Movies
!/Users/user/Data/Audio
!/Users/user/Dropbox/Doc Backup
!/Users/user/Dropbox/Office Docs
!/Users/user/Dropbox/Config
!/Users/user/Dropbox/Archive
!/Users/user/Dropbox/Apps
!/Users/user/Library/Mail
!/Users/user/Library/Mobile Documents/com~apple~CloudDocs
!/Users/user/Library/Messages/Archive
!/Users/user/Library/Application Support/AddressBook/Sources
!/Users/user/iCloud Drive (Archive)

```

Do I need to do anything else? Maybe something like this? Or what I have done above it sufficient?

**BLOCK B**

```
/Users/user/Data/*
!/Users/user/Data

/Users/user/Dropbox/*
!/Users/user/Dropbox

/Users/user/Library/Mobile Documents/*
!/Users/user/Library/Mobile Documents

/Users/user/Library/Messages/*
!/Users/user/Library/Messages

/Users/user/Library/Application Support/AddressBook/*
!/Users/user/Library/Application Support/AddressBook

/Users/user/Library/Application Support/*
!/Users/user/Library/Application Support

/Users/user/Library/*
!/Users/user/Library

/Users/user/*
!/Users/user

```

Now do I even need to do this as well? Since my root/sync folder will be “/Users/user” I think it won’t even scan anything outside it, right?

**BLOCK C**

```
/Users/*
!/Users
*

```

I also want to ignore these no matter where they are - so I have kept there at top - these might be inside my include folders as well

**BLOCK D**

```
.DS_Store
*.swp
.Trash
.Xauthority
.bash_sessions
/Users/user/Pictures/Photos Library.photoslibrary
*.cache
.cache
/Users/user/Music/iTunes
build/
gradle/
.idea/
*.iml

```

Do I need all A, B, C, D?

Also, does the order matter? Do I need to keep certain include/exclude patters above/below one another in certain order for them to work or for them to be optimised?

Essentially what will be the simplest/cleanest way to achieve this?

---

<div class="post-metadata">

### Author: ![calmh](https://forum.syncthing.net/user_avatar/forum.syncthing.net/calmh/32/15311_2.png) [@calmh](https://forum.syncthing.net/u/calmh)
#### Post date: [November 28, 2021, 9:22am UTC](https://forum.syncthing.net/t/ignore-patterns-in-the-form-of-include-only-these-and-exclude-everything-else-inside-a-given-root-folder/17654/2 "2021-11-28T09:22:15Z")

</div>

Syncthing ignore patterns are folder-relative not absolute, and first match wins. I suggest starting with small and simple and using trial and error, instead of building a castle on paper up front.

---

<div class="post-metadata">

### Author: ![pilgrim](https://forum.syncthing.net/letter_avatar_proxy/v4/letter/p/5e9695/32.png) [@pilgrim](https://forum.syncthing.net/u/pilgrim)
#### Post date: [November 28, 2021, 10:21am UTC](https://forum.syncthing.net/t/ignore-patterns-in-the-form-of-include-only-these-and-exclude-everything-else-inside-a-given-root-folder/17654/3 "2021-11-28T10:21:15Z")

</div>

This is not castle on paper! This is my trial and error. I tried many ways but I am not able to figure it out. I have this specific use case so instead of trying to type some other example and then again getting confused I presented the entire folder hierarchy as it is.

I went through the doc as well but it was not helpful (yes, I have seen couple of posts where commenders have have just replied “it’s in the doc”).

So I posted here hoping someone might have gone through a similar use case and can help me.

---

<div class="post-metadata">

### Author: ![calmh](https://forum.syncthing.net/user_avatar/forum.syncthing.net/calmh/32/15311_2.png) [@calmh](https://forum.syncthing.net/u/calmh)
#### Post date: [November 28, 2021, 10:26am UTC](https://forum.syncthing.net/t/ignore-patterns-in-the-form-of-include-only-these-and-exclude-everything-else-inside-a-given-root-folder/17654/4 "2021-11-28T10:26:03Z")

</div>

Sorry, I presumed this was “on paper” since none of the patterns would work as written. As said, think “first match wins” and “folder relative paths”. If your folder root is `/Users/user` and you want to sync only `/Users/user/Movies`, start with

```
!Movies
*

```

(“Don’t ignore Movies; Ignore everything else”)

Build from there, adding patterns as required.

---

<div class="post-metadata">

### Author: ![pilgrim](https://forum.syncthing.net/letter_avatar_proxy/v4/letter/p/5e9695/32.png) [@pilgrim](https://forum.syncthing.net/u/pilgrim)
#### Post date: [November 28, 2021, 1:09pm UTC](https://forum.syncthing.net/t/ignore-patterns-in-the-form-of-include-only-these-and-exclude-everything-else-inside-a-given-root-folder/17654/5 "2021-11-28T13:09:35Z")

</div>

> [@calmh](#):
>
> ```plaintext
> !Movies
> *
> 
> ```

Well, just that worked like a charm! I think I was unnecessarily thinking more complex rules.

- Exclude **only** root folder (no other sub-root-folder ignore rules required)
- And then invert the exclusion for each folders/files you want to be included.

I will share my test/dummy example (in case others have this use case):

I created this test file/folder hierarchy inside my root folder (i.e. the added folder for sync).

![image](https://forum-uploads.syncthingcdn.net/original/2X/c/c32ece32f3e648f35fac38515ae290b68a057656.png)

And then I only wanted to backup these out of the heirarchy above.

```plaintext
Library/Application Support/AddressBook/Sources

Library/Messages/Archive

Library/Mail

Dropbox/db_d_2
Dropbox/db big d_3
Dropbox/db_d_1

Data/data_dir_1
Data/data_dir_1

Pictures
Movies
.dotfiles
.ssh
a

```

All I had to do was add this in Ignore Patterns:

```plaintext
!Library/Application Support/AddressBook/Sources
!Library/Messages/Archive
!Library/Mail
!Dropbox/db_d_2
!Dropbox/db big d_3
!Dropbox/db_d_1
!Data/data_dir_1
!Data/data_dir_1
!Pictures
!Movies
!.dotfiles
!.ssh
!a
# then just like done above ^ we invert ignoring/exclusion of everything we want to sync/include listing each path

# ignores everything in root folder
*

```

That’s it - ignore everything and then invert (with !) path of what you do not want to ignore.

I could verify and I could get exactly what I wanted on my iPhone (except hidden files/folders as I could not see them on iPhone)

---

<div class="post-metadata">

### Author: ![system](https://forum-uploads.syncthingcdn.net/original/2X/0/0b50e0a202b22ae6a67190759e8c868805b8ed9f.png) [@system](https://forum.syncthing.net/u/system)
#### Post date: [December 28, 2021, 1:10pm UTC](https://forum.syncthing.net/t/ignore-patterns-in-the-form-of-include-only-these-and-exclude-everything-else-inside-a-given-root-folder/17654/6 "2021-12-28T13:10:19Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
