Can I exclude a folder and all contents except a single file?

I am trying to backup a home folder and I would like to exclude a sub folder and all files inside of it except one file.

I have been trying various combinations of --exclude and --filter + and - but I can't see to get it right.

Is this possible? Could someone please help me with this syntax?

Ideally I would not like to specify the direct file path but just the file name:

*.file

This way I ensure I always get this file regardless of the path.

Here is an example:

/home/folder/
file 1
file 2
file 3

I want to sync on /home, exclude 'folder' and all files but include file 1 specifically.

Assuming that the contents under /home are unique e.g. dissimilar names, you can try the following command.

rclone copy --exclude={folder,file2,file3} source/path remote:path

I think you want to use --filter-from and use this as the file

+ folder/file 1
- folder/**
+ *

The first line includes that file you wanted, the second excludes everything else in that folder and the third includes everything else.

2 Likes

This works nicely. Thank you!

1 Like

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