github.com/rclone/rclone@v1.66.1-0.20240517100346-7b89735ae726/docs/content/filtering.md (about)

     1  ---
     2  title: "Rclone Filtering"
     3  description: "Rclone filtering, includes and excludes"
     4  versionIntroduced: "v1.22"
     5  ---
     6  
     7  # Filtering, includes and excludes
     8  
     9  Filter flags determine which files rclone `sync`, `move`, `ls`, `lsl`,
    10  `md5sum`, `sha1sum`, `size`, `delete`, `check` and similar commands
    11  apply to.
    12  
    13  They are specified in terms of path/file name patterns; path/file
    14  lists; file age and size, or presence of a file in a directory. Bucket
    15  based remotes without the concept of directory apply filters to object
    16  key, age and size in an analogous way.
    17  
    18  Rclone `purge` does not obey filters.
    19  
    20  To test filters without risk of damage to data, apply them to `rclone
    21  ls`, or with the `--dry-run` and `-vv` flags.
    22  
    23  Rclone filter patterns can only be used in filter command line options, not
    24  in the specification of a remote.
    25  
    26  E.g. `rclone copy "remote:dir*.jpg" /path/to/dir` does not have a filter effect.
    27  `rclone copy remote:dir /path/to/dir --include "*.jpg"` does.
    28  
    29  **Important** Avoid mixing any two of `--include...`, `--exclude...` or
    30  `--filter...` flags in an rclone command. The results might not be what
    31  you expect. Instead use a `--filter...` flag.
    32  
    33  ## Patterns for matching path/file names
    34  
    35  ### Pattern syntax {#patterns}
    36  
    37  Here is a formal definition of the pattern syntax,
    38  [examples](#examples) are below.
    39  
    40  Rclone matching rules follow a glob style:
    41  
    42      *         matches any sequence of non-separator (/) characters
    43      **        matches any sequence of characters including / separators
    44      ?         matches any single non-separator (/) character
    45      [ [ ! ] { character-range } ]
    46                character class (must be non-empty)
    47      { pattern-list }
    48                pattern alternatives
    49      {{ regexp }}
    50                regular expression to match
    51      c         matches character c (c != *, **, ?, \, [, {, })
    52      \c        matches reserved character c (c = *, **, ?, \, [, {, }) or character class
    53  
    54  character-range:
    55  
    56      c         matches character c (c != \, -, ])
    57      \c        matches reserved character c (c = \, -, ])
    58      lo - hi   matches character c for lo <= c <= hi
    59  
    60  pattern-list:
    61  
    62      pattern { , pattern }
    63                comma-separated (without spaces) patterns
    64  
    65  character classes (see [Go regular expression reference](https://golang.org/pkg/regexp/syntax/)) include:
    66  
    67      Named character classes (e.g. [\d], [^\d], [\D], [^\D])
    68      Perl character classes (e.g. \s, \S, \w, \W)
    69      ASCII character classes (e.g. [[:alnum:]], [[:alpha:]], [[:punct:]], [[:xdigit:]])
    70  
    71  regexp for advanced users to insert a regular expression - see [below](#regexp) for more info:
    72  
    73      Any re2 regular expression not containing `}}`
    74  
    75  If the filter pattern starts with a `/` then it only matches
    76  at the top level of the directory tree,
    77  **relative to the root of the remote** (not necessarily the root
    78  of the drive). If it does not start with `/` then it is matched
    79  starting at the **end of the path/file name** but it only matches
    80  a complete path element - it must match from a `/`
    81  separator or the beginning of the path/file.
    82  
    83      file.jpg   - matches "file.jpg"
    84                 - matches "directory/file.jpg"
    85                 - doesn't match "afile.jpg"
    86                 - doesn't match "directory/afile.jpg"
    87      /file.jpg  - matches "file.jpg" in the root directory of the remote
    88                 - doesn't match "afile.jpg"
    89                 - doesn't match "directory/file.jpg"
    90  
    91  The top level of the remote might not be the top level of the drive.
    92  
    93  E.g. for a Microsoft Windows local directory structure
    94  
    95      F:
    96      ├── bkp
    97      ├── data
    98      │   ├── excl
    99      │   │   ├── 123.jpg
   100      │   │   └── 456.jpg
   101      │   ├── incl
   102      │   │   └── document.pdf
   103  
   104  To copy the contents of folder `data` into folder `bkp` excluding the contents of subfolder
   105  `excl`the following command treats `F:\data` and `F:\bkp` as top level for filtering.
   106  
   107  `rclone copy F:\data\ F:\bkp\ --exclude=/excl/**`
   108  
   109  **Important** Use `/` in path/file name patterns and not `\` even if
   110  running on Microsoft Windows.
   111  
   112  Simple patterns are case sensitive unless the `--ignore-case` flag is used.
   113  
   114  Without `--ignore-case` (default)
   115  
   116      potato - matches "potato"
   117             - doesn't match "POTATO"
   118  
   119  With `--ignore-case`
   120  
   121      potato - matches "potato"
   122             - matches "POTATO"
   123  
   124  ## Using regular expressions in filter patterns {#regexp}
   125  
   126  The syntax of filter patterns is glob style matching (like `bash`
   127  uses) to make things easy for users. However this does not provide
   128  absolute control over the matching, so for advanced users rclone also
   129  provides a regular expression syntax.
   130  
   131  The regular expressions used are as defined in the [Go regular
   132  expression reference](https://golang.org/pkg/regexp/syntax/). Regular
   133  expressions should be enclosed in `{{` `}}`. They will match only the
   134  last path segment if the glob doesn't start with `/` or the whole path
   135  name if it does. Note that rclone does not attempt to parse the
   136  supplied regular expression, meaning that using any regular expression
   137  filter will prevent rclone from using [directory filter rules](#directory_filter),
   138  as it will instead check every path against
   139  the supplied regular expression(s).
   140  
   141  Here is how the `{{regexp}}` is transformed into an full regular
   142  expression to match the entire path:
   143  
   144      {{regexp}}  becomes (^|/)(regexp)$
   145      /{{regexp}} becomes ^(regexp)$
   146  
   147  Regexp syntax can be mixed with glob syntax, for example
   148  
   149      *.{{jpe?g}} to match file.jpg, file.jpeg but not file.png
   150  
   151  You can also use regexp flags - to set case insensitive, for example
   152  
   153      *.{{(?i)jpg}} to match file.jpg, file.JPG but not file.png
   154  
   155  Be careful with wildcards in regular expressions - you don't want them
   156  to match path separators normally. To match any file name starting
   157  with `start` and ending with `end` write
   158  
   159      {{start[^/]*end\.jpg}}
   160  
   161  Not
   162  
   163      {{start.*end\.jpg}}
   164  
   165  Which will match a directory called `start` with a file called
   166  `end.jpg` in it as the `.*` will match `/` characters.
   167  
   168  Note that you can use `-vv --dump filters` to show the filter patterns
   169  in regexp format - rclone implements the glob patterns by transforming
   170  them into regular expressions.
   171  
   172  ## Filter pattern examples {#examples}
   173  
   174  | Description | Pattern | Matches | Does not match |
   175  | ----------- |-------- | ------- | -------------- |
   176  | Wildcard    | `*.jpg` | `/file.jpg`     | `/file.png`    |
   177  |             |         | `/dir/file.jpg` | `/dir/file.png` |
   178  | Rooted      | `/*.jpg` | `/file.jpg`    | `/file.png`    |
   179  |             |          | `/file2.jpg`    | `/dir/file.jpg` |
   180  | Alternates  | `*.{jpg,png}` | `/file.jpg`     | `/file.gif`    |
   181  |             |         | `/dir/file.png` | `/dir/file.gif` |
   182  | Path Wildcard | `dir/**` | `/dir/anyfile`     | `file.png`    |
   183  |             |          | `/subdir/dir/subsubdir/anyfile` | `/subdir/file.png` |
   184  | Any Char    | `*.t?t` | `/file.txt`     | `/file.qxt`    |
   185  |             |         | `/dir/file.tzt` | `/dir/file.png` |
   186  | Range       | `*.[a-z]` | `/file.a`     | `/file.0`    |
   187  |             |         | `/dir/file.b` | `/dir/file.1` |
   188  | Escape      | `*.\?\?\?` | `/file.???`     | `/file.abc`    |
   189  |             |         | `/dir/file.???` | `/dir/file.def` |
   190  | Class       | `*.\d\d\d` | `/file.012`     | `/file.abc`    |
   191  |             |         | `/dir/file.345` | `/dir/file.def` |
   192  | Regexp      | `*.{{jpe?g}}` | `/file.jpeg`     | `/file.png`    |
   193  |             |         | `/dir/file.jpg` | `/dir/file.jpeeg` |
   194  | Rooted Regexp | `/{{.*\.jpe?g}}` | `/file.jpeg`  | `/file.png`    |
   195  |             |                  | `/file.jpg`   | `/dir/file.jpg` |
   196  
   197  ## How filter rules are applied to files {#how-filter-rules-work}
   198  
   199  Rclone path/file name filters are made up of one or more of the following flags:
   200  
   201    * `--include`
   202    * `--include-from`
   203    * `--exclude`
   204    * `--exclude-from`
   205    * `--filter`
   206    * `--filter-from`
   207  
   208  There can be more than one instance of individual flags.
   209  
   210  Rclone internally uses a combined list of all the include and exclude
   211  rules. The order in which rules are processed can influence the result
   212  of the filter.
   213  
   214  All flags of the same type are processed together in the order
   215  above, regardless of what order the different types of flags are
   216  included on the command line.
   217  
   218  Multiple instances of the same flag are processed from left
   219  to right according to their position in the command line.
   220  
   221  To mix up the order of processing includes and excludes use `--filter...`
   222  flags.
   223  
   224  Within `--include-from`, `--exclude-from` and `--filter-from` flags
   225  rules are processed from top to bottom of the referenced file.
   226  
   227  If there is an `--include` or `--include-from` flag specified, rclone
   228  implies a `- **` rule which it adds to the bottom of the internal rule
   229  list. Specifying a `+` rule with a `--filter...` flag does not imply
   230  that rule.
   231  
   232  Each path/file name passed through rclone is matched against the
   233  combined filter list. At first match to a rule the path/file name
   234  is included or excluded and no further filter rules are processed for
   235  that path/file.
   236  
   237  If rclone does not find a match, after testing against all rules
   238  (including the implied rule if appropriate), the path/file name
   239  is included.
   240  
   241  Any path/file included at that stage is processed by the rclone
   242  command.
   243  
   244  `--files-from` and `--files-from-raw` flags over-ride and cannot be
   245  combined with other filter options.
   246  
   247  To see the internal combined rule list, in regular expression form,
   248  for a command add the `--dump filters` flag. Running an rclone command
   249  with `--dump filters` and `-vv` flags lists the internal filter elements
   250  and shows how they are applied to each source path/file. There is not
   251  currently a means provided to pass regular expression filter options into
   252  rclone directly though character class filter rules contain character
   253  classes. [Go regular expression reference](https://golang.org/pkg/regexp/syntax/)
   254  
   255  ### How filter rules are applied to directories {#directory_filter}
   256  
   257  Rclone commands are applied to path/file names not
   258  directories. The entire contents of a directory can be matched
   259  to a filter by the pattern `directory/*` or recursively by
   260  `directory/**`.
   261  
   262  Directory filter rules are defined with a closing `/` separator.
   263  
   264  E.g. `/directory/subdirectory/` is an rclone directory filter rule.
   265  
   266  Rclone commands can use directory filter rules to determine whether they
   267  recurse into subdirectories. This potentially optimises access to a remote
   268  by avoiding listing unnecessary directories. Whether optimisation is
   269  desirable depends on the specific filter rules and source remote content.
   270  
   271  If any [regular expression filters](#regexp) are in use, then no
   272  directory recursion optimisation is possible, as rclone must check
   273  every path against the supplied regular expression(s).
   274  
   275  Directory recursion optimisation occurs if either:
   276  
   277  * A source remote does not support the rclone `ListR` primitive. local,
   278  sftp, Microsoft OneDrive and WebDAV do not support `ListR`. Google
   279  Drive and most bucket type storage do. [Full list](https://rclone.org/overview/#optional-features)
   280  
   281  * On other remotes (those that support `ListR`), if the rclone command is not naturally recursive, and
   282  provided it is not run with the `--fast-list` flag. `ls`, `lsf -R` and
   283  `size` are naturally recursive but `sync`, `copy` and `move` are not.
   284  
   285  * Whenever the `--disable ListR` flag is applied to an rclone command.
   286  
   287  Rclone commands imply directory filter rules from path/file filter
   288  rules. To view the directory filter rules rclone has implied for a
   289  command specify the `--dump filters` flag.
   290  
   291  E.g. for an include rule
   292  
   293      /a/*.jpg
   294  
   295  Rclone implies the directory include rule
   296  
   297      /a/
   298  
   299  Directory filter rules specified in an rclone command can limit
   300  the scope of an rclone command but path/file filters still have
   301  to be specified.
   302  
   303  E.g. `rclone ls remote: --include /directory/` will not match any
   304  files. Because it is an `--include` option the `--exclude **` rule
   305  is implied, and the `/directory/` pattern serves only to optimise
   306  access to the remote by ignoring everything outside of that directory.
   307  
   308  E.g. `rclone ls remote: --filter-from filter-list.txt` with a file
   309  `filter-list.txt`:
   310  
   311      - /dir1/
   312      - /dir2/
   313      + *.pdf
   314      - **
   315  
   316  All files in directories `dir1` or `dir2` or their subdirectories
   317  are completely excluded from the listing. Only files of suffix
   318  `pdf` in the root of `remote:` or its subdirectories are listed.
   319  The `- **` rule prevents listing of any path/files not previously
   320  matched by the rules above.
   321  
   322  Option `exclude-if-present` creates a directory exclude rule based
   323  on the presence of a file in a directory and takes precedence over
   324  other rclone directory filter rules.
   325  
   326  When using pattern list syntax, if a pattern item contains either
   327  `/` or `**`, then rclone will not able to imply a directory filter rule
   328  from this pattern list.
   329  
   330  E.g. for an include rule
   331  
   332      {dir1/**,dir2/**}
   333  
   334  Rclone will match files below directories `dir1` or `dir2` only,
   335  but will not be able to use this filter to exclude a directory `dir3`
   336  from being traversed.
   337  
   338  Directory recursion optimisation may affect performance, but normally
   339  not the result. One exception to this is sync operations with option
   340  `--create-empty-src-dirs`, where any traversed empty directories will
   341  be created. With the pattern list example `{dir1/**,dir2/**}` above,
   342  this would create an empty directory `dir3` on destination (when it exists
   343  on source). Changing the filter to `{dir1,dir2}/**`, or splitting it into
   344  two include rules `--include dir1/** --include dir2/**`, will match the
   345  same files while also filtering directories, with the result that an empty
   346  directory `dir3` will no longer be created.
   347  
   348  ### `--exclude` - Exclude files matching pattern
   349  
   350  Excludes path/file names from an rclone command based on a single exclude
   351  rule.
   352  
   353  This flag can be repeated. See above for the order filter flags are
   354  processed in.
   355  
   356  `--exclude` should not be used with `--include`, `--include-from`,
   357  `--filter` or `--filter-from` flags.
   358  
   359  `--exclude` has no effect when combined with `--files-from` or
   360  `--files-from-raw` flags.
   361  
   362  E.g. `rclone ls remote: --exclude *.bak` excludes all .bak files
   363  from listing.
   364  
   365  E.g. `rclone size remote: --exclude "/dir/**"` returns the total size of
   366  all files on `remote:` excluding those in root directory `dir` and sub
   367  directories.
   368  
   369  E.g. on Microsoft Windows `rclone ls remote: --exclude "*\[{JP,KR,HK}\]*"`
   370  lists the files in `remote:` without `[JP]` or `[KR]` or `[HK]` in
   371  their name. Quotes prevent the shell from interpreting the `\`
   372  characters.`\` characters escape the `[` and `]` so an rclone filter
   373  treats them literally rather than as a character-range. The `{` and `}`
   374  define an rclone pattern list. For other operating systems single quotes are
   375  required ie `rclone ls remote: --exclude '*\[{JP,KR,HK}\]*'`
   376  
   377  ### `--exclude-from` - Read exclude patterns from file
   378  
   379  Excludes path/file names from an rclone command based on rules in a
   380  named file. The file contains a list of remarks and pattern rules.
   381  
   382  For an example `exclude-file.txt`:
   383  
   384      # a sample exclude rule file
   385      *.bak
   386      file2.jpg
   387  
   388  `rclone ls remote: --exclude-from exclude-file.txt` lists the files on
   389  `remote:` except those named `file2.jpg` or with a suffix `.bak`. That is
   390  equivalent to `rclone ls remote: --exclude file2.jpg --exclude "*.bak"`.
   391  
   392  This flag can be repeated. See above for the order filter flags are
   393  processed in.
   394  
   395  The `--exclude-from` flag is useful where multiple exclude filter rules
   396  are applied to an rclone command.
   397  
   398  `--exclude-from` should not be used with `--include`, `--include-from`,
   399  `--filter` or `--filter-from` flags.
   400  
   401  `--exclude-from` has no effect when combined with `--files-from` or
   402  `--files-from-raw` flags.
   403  
   404  `--exclude-from` followed by `-` reads filter rules from standard input.
   405  
   406  ### `--include` - Include files matching pattern
   407  
   408  Adds a single include rule based on path/file names to an rclone
   409  command.
   410  
   411  This flag can be repeated. See above for the order filter flags are
   412  processed in.
   413  
   414  `--include` has no effect when combined with `--files-from` or
   415  `--files-from-raw` flags.
   416  
   417  `--include` implies `--exclude **` at the end of an rclone internal
   418  filter list. Therefore if you mix `--include` and `--include-from`
   419  flags with `--exclude`, `--exclude-from`, `--filter` or `--filter-from`,
   420  you must use include rules for all the files you want in the include
   421  statement. For more flexibility use the `--filter-from` flag.
   422  
   423  E.g. `rclone ls remote: --include "*.{png,jpg}"` lists the files on
   424  `remote:` with suffix `.png` and `.jpg`. All other files are excluded.
   425  
   426  E.g. multiple rclone copy commands can be combined with `--include` and a
   427  pattern-list.
   428  
   429      rclone copy /vol1/A remote:A
   430      rclone copy /vol1/B remote:B
   431  
   432  is equivalent to:
   433  
   434      rclone copy /vol1 remote: --include "{A,B}/**"
   435  
   436  E.g. `rclone ls remote:/wheat --include "??[^[:punct:]]*"` lists the
   437  files `remote:` directory `wheat` (and subdirectories) whose third
   438  character is not punctuation. This example uses
   439  an [ASCII character class](https://golang.org/pkg/regexp/syntax/).
   440  
   441  ### `--include-from` - Read include patterns from file
   442  
   443  Adds path/file names to an rclone command based on rules in a
   444  named file. The file contains a list of remarks and pattern rules.
   445  
   446  For an example `include-file.txt`:
   447  
   448      # a sample include rule file
   449      *.jpg
   450      file2.avi
   451  
   452  `rclone ls remote: --include-from include-file.txt` lists the files on
   453  `remote:` with name `file2.avi` or suffix `.jpg`. That is equivalent to
   454  `rclone ls remote: --include file2.avi --include "*.jpg"`.
   455  
   456  This flag can be repeated. See above for the order filter flags are
   457  processed in.
   458  
   459  The `--include-from` flag is useful where multiple include filter rules
   460  are applied to an rclone command.
   461  
   462  `--include-from` implies `--exclude **` at the end of an rclone internal
   463  filter list. Therefore if you mix `--include` and `--include-from`
   464  flags with `--exclude`, `--exclude-from`, `--filter` or `--filter-from`,
   465  you must use include rules for all the files you want in the include
   466  statement. For more flexibility use the `--filter-from` flag.
   467  
   468  `--exclude-from` has no effect when combined with `--files-from` or
   469  `--files-from-raw` flags.
   470  
   471  `--exclude-from` followed by `-` reads filter rules from standard input.
   472  
   473  ### `--filter` - Add a file-filtering rule
   474  
   475  Specifies path/file names to an rclone command, based on a single
   476  include or exclude rule, in `+` or `-` format.
   477  
   478  This flag can be repeated. See above for the order filter flags are
   479  processed in.
   480  
   481  `--filter +` differs from `--include`. In the case of `--include` rclone
   482  implies an `--exclude *` rule which it adds to the bottom of the internal rule
   483  list. `--filter...+` does not imply
   484  that rule.
   485  
   486  `--filter` has no effect when combined with `--files-from` or
   487  `--files-from-raw` flags.
   488  
   489  `--filter` should not be used with `--include`, `--include-from`,
   490  `--exclude` or `--exclude-from` flags.
   491  
   492  E.g. `rclone ls remote: --filter "- *.bak"` excludes all `.bak` files
   493  from a list of `remote:`.
   494  
   495  ### `--filter-from` - Read filtering patterns from a file
   496  
   497  Adds path/file names to an rclone command based on rules in a
   498  named file. The file contains a list of remarks and pattern rules. Include
   499  rules start with `+ ` and exclude rules with `- `. `!` clears existing
   500  rules. Rules are processed in the order they are defined.
   501  
   502  This flag can be repeated. See above for the order filter flags are
   503  processed in.
   504  
   505  Arrange the order of filter rules with the most restrictive first and
   506  work down.
   507  
   508  E.g. for `filter-file.txt`:
   509  
   510      # a sample filter rule file
   511      - secret*.jpg
   512      + *.jpg
   513      + *.png
   514      + file2.avi
   515      - /dir/Trash/**
   516      + /dir/**
   517      # exclude everything else
   518      - *
   519  
   520  `rclone ls remote: --filter-from filter-file.txt` lists the path/files on
   521  `remote:` including all `jpg` and `png` files, excluding any
   522  matching `secret*.jpg` and including `file2.avi`.  It also includes
   523  everything in the directory `dir` at the root of `remote`, except
   524  `remote:dir/Trash` which it excludes.  Everything else is excluded.
   525  
   526  
   527  E.g. for an alternative `filter-file.txt`:
   528  
   529      - secret*.jpg
   530      + *.jpg
   531      + *.png
   532      + file2.avi
   533      - *
   534  
   535  Files `file1.jpg`, `file3.png` and `file2.avi` are listed whilst
   536  `secret17.jpg` and files without the suffix `.jpg` or `.png` are excluded.
   537  
   538  E.g. for an alternative `filter-file.txt`:
   539  
   540      + *.jpg
   541      + *.gif
   542      !
   543      + 42.doc
   544      - *
   545  
   546  Only file 42.doc is listed. Prior rules are cleared by the `!`.
   547  
   548  ### `--files-from` - Read list of source-file names
   549  
   550  Adds path/files to an rclone command from a list in a named file.
   551  Rclone processes the path/file names in the order of the list, and
   552  no others.
   553  
   554  Other filter flags (`--include`, `--include-from`, `--exclude`,
   555  `--exclude-from`, `--filter` and `--filter-from`) are ignored when
   556  `--files-from` is used.
   557  
   558  `--files-from` expects a list of files as its input. Leading or
   559  trailing whitespace is stripped from the input lines. Lines starting
   560  with `#` or `;` are ignored.
   561  
   562  Rclone commands with a `--files-from` flag traverse the remote,
   563  treating the names in `--files-from` as a set of filters.
   564  
   565  If the `--no-traverse` and `--files-from` flags are used together
   566  an rclone command does not traverse the remote. Instead it addresses
   567  each path/file named in the file individually. For each path/file name, that
   568  requires typically 1 API call. This can be efficient for a short `--files-from`
   569  list and a remote containing many files.
   570  
   571  Rclone commands do not error if any names in the `--files-from` file are
   572  missing from the source remote.
   573  
   574  The `--files-from` flag can be repeated in a single rclone command to
   575  read path/file names from more than one file. The files are read from left
   576  to right along the command line.
   577  
   578  Paths within the `--files-from` file are interpreted as starting
   579  with the root specified in the rclone command.  Leading `/` separators are
   580  ignored. See [--files-from-raw](#files-from-raw-read-list-of-source-file-names-without-any-processing) if
   581  you need the input to be processed in a raw manner.
   582  
   583  E.g. for a file `files-from.txt`:
   584  
   585      # comment
   586      file1.jpg
   587      subdir/file2.jpg
   588  
   589  `rclone copy --files-from files-from.txt /home/me/pics remote:pics`
   590  copies the following, if they exist, and only those files.
   591  
   592      /home/me/pics/file1.jpg        → remote:pics/file1.jpg
   593      /home/me/pics/subdir/file2.jpg → remote:pics/subdir/file2.jpg
   594  
   595  E.g. to copy the following files referenced by their absolute paths:
   596  
   597      /home/user1/42
   598      /home/user1/dir/ford
   599      /home/user2/prefect
   600  
   601  First find a common subdirectory - in this case `/home`
   602  and put the remaining files in `files-from.txt` with or without
   603  leading `/`, e.g.
   604  
   605      user1/42
   606      user1/dir/ford
   607      user2/prefect
   608  
   609  Then copy these to a remote:
   610  
   611      rclone copy --files-from files-from.txt /home remote:backup
   612  
   613  The three files are transferred as follows:
   614  
   615      /home/user1/42       → remote:backup/user1/important
   616      /home/user1/dir/ford → remote:backup/user1/dir/file
   617      /home/user2/prefect  → remote:backup/user2/stuff
   618  
   619  Alternatively if `/` is chosen as root `files-from.txt` will be:
   620  
   621      /home/user1/42
   622      /home/user1/dir/ford
   623      /home/user2/prefect
   624  
   625  The copy command will be:
   626  
   627      rclone copy --files-from files-from.txt / remote:backup
   628  
   629  Then there will be an extra `home` directory on the remote:
   630  
   631      /home/user1/42       → remote:backup/home/user1/42
   632      /home/user1/dir/ford → remote:backup/home/user1/dir/ford
   633      /home/user2/prefect  → remote:backup/home/user2/prefect
   634  
   635  ### `--files-from-raw` - Read list of source-file names without any processing
   636  
   637  This flag is the same as `--files-from` except that input is read in a
   638  raw manner. Lines with leading / trailing whitespace, and lines starting
   639  with `;` or `#` are read without any processing. [rclone lsf](/commands/rclone_lsf/) has
   640  a compatible format that can be used to export file lists from remotes for
   641  input to `--files-from-raw`.
   642  
   643  ### `--ignore-case` - make searches case insensitive
   644  
   645  By default, rclone filter patterns are case sensitive. The `--ignore-case`
   646  flag makes all of the filters patterns on the command line case
   647  insensitive.
   648  
   649  E.g. `--include "zaphod.txt"` does not match a file `Zaphod.txt`. With
   650  `--ignore-case` a match is made.
   651  
   652  ## Quoting shell metacharacters
   653  
   654  Rclone commands with filter patterns containing shell metacharacters may
   655  not as work as expected in your shell and may require quoting.
   656  
   657  E.g. linux, OSX (`*` metacharacter)
   658  
   659    * `--include \*.jpg`
   660    * `--include '*.jpg'`
   661    * `--include='*.jpg'`
   662  
   663  Microsoft Windows expansion is done by the command, not shell, so
   664  `--include *.jpg` does not require quoting.
   665  
   666  If the rclone error
   667  `Command .... needs .... arguments maximum: you provided .... non flag arguments:`
   668  is encountered, the cause is commonly spaces within the name of a
   669  remote or flag value. The fix then is to quote values containing spaces.
   670  
   671  ## Other filters
   672  
   673  ### `--min-size` - Don't transfer any file smaller than this
   674  
   675  Controls the minimum size file within the scope of an rclone command.
   676  Default units are `KiB` but abbreviations `K`, `M`, `G`, `T` or `P` are valid.
   677  
   678  E.g. `rclone ls remote: --min-size 50k` lists files on `remote:` of 50 KiB
   679  size or larger.
   680  
   681  See [the size option docs](/docs/#size-option) for more info.
   682  
   683  ### `--max-size` - Don't transfer any file larger than this
   684  
   685  Controls the maximum size file within the scope of an rclone command.
   686  Default units are `KiB` but abbreviations `K`, `M`, `G`, `T` or `P` are valid.
   687  
   688  E.g. `rclone ls remote: --max-size 1G` lists files on `remote:` of 1 GiB
   689  size or smaller.
   690  
   691  See [the size option docs](/docs/#size-option) for more info.
   692  
   693  ### `--max-age` - Don't transfer any file older than this
   694  
   695  Controls the maximum age of files within the scope of an rclone command.
   696  
   697  `--max-age` applies only to files and not to directories.
   698  
   699  E.g. `rclone ls remote: --max-age 2d` lists files on `remote:` of 2 days
   700  old or less.
   701  
   702  See [the time option docs](/docs/#time-option) for valid formats.
   703  
   704  ### `--min-age` - Don't transfer any file younger than this
   705  
   706  Controls the minimum age of files within the scope of an rclone command.
   707  (see `--max-age` for valid formats)
   708  
   709  `--min-age` applies only to files and not to directories.
   710  
   711  E.g. `rclone ls remote: --min-age 2d` lists files on `remote:` of 2 days
   712  old or more.
   713  
   714  See [the time option docs](/docs/#time-option) for valid formats.
   715  
   716  ## Other flags
   717  
   718  ### `--delete-excluded` - Delete files on dest excluded from sync
   719  
   720  **Important** this flag is dangerous to your data - use with `--dry-run`
   721  and `-v` first.
   722  
   723  In conjunction with `rclone sync`, `--delete-excluded` deletes any files
   724  on the destination which are excluded from the command.
   725  
   726  E.g. the scope of `rclone sync --interactive A: B:` can be restricted:
   727  
   728      rclone --min-size 50k --delete-excluded sync A: B:
   729  
   730  All files on `B:` which are less than 50 KiB are deleted
   731  because they are excluded from the rclone sync command.
   732  
   733  ### `--dump filters` - dump the filters to the output
   734  
   735  Dumps the defined filters to standard output in regular expression
   736  format.
   737  
   738  Useful for debugging.
   739  
   740  ## Exclude directory based on a file
   741  
   742  The `--exclude-if-present` flag controls whether a directory is
   743  within the scope of an rclone command based on the presence of a
   744  named file within it. The flag can be repeated to check for
   745  multiple file names, presence of any of them will exclude the
   746  directory.
   747  
   748  This flag has a priority over other filter flags.
   749  
   750  E.g. for the following directory structure:
   751  
   752      dir1/file1
   753      dir1/dir2/file2
   754      dir1/dir2/dir3/file3
   755      dir1/dir2/dir3/.ignore
   756  
   757  The command `rclone ls --exclude-if-present .ignore dir1` does
   758  not list `dir3`, `file3` or `.ignore`.
   759  
   760  ## Metadata filters {#metadata}
   761  
   762  The metadata filters work in a very similar way to the normal file
   763  name filters, except they match [metadata](/docs/#metadata) on the
   764  object.
   765  
   766  The metadata should be specified as `key=value` patterns. This may be
   767  wildcarded using the normal [filter patterns](#patterns) or [regular
   768  expressions](#regexp).
   769  
   770  For example if you wished to list only local files with a mode of
   771  `100664` you could do that with:
   772  
   773      rclone lsf -M --files-only --metadata-include "mode=100664" .
   774  
   775  Or if you wished to show files with an `atime`, `mtime` or `btime` at a given date:
   776  
   777      rclone lsf -M --files-only --metadata-include "[abm]time=2022-12-16*" .
   778  
   779  Like file filtering, metadata filtering only applies to files not to
   780  directories.
   781  
   782  The filters can be applied using these flags.
   783  
   784  - `--metadata-include`      - Include metadatas matching pattern
   785  - `--metadata-include-from` - Read metadata include patterns from file (use - to read from stdin)
   786  - `--metadata-exclude`      - Exclude metadatas matching pattern
   787  - `--metadata-exclude-from` - Read metadata exclude patterns from file (use - to read from stdin)
   788  - `--metadata-filter`       - Add a metadata filtering rule
   789  - `--metadata-filter-from`  - Read metadata filtering patterns from a file (use - to read from stdin)
   790  
   791  Each flag can be repeated. See the section on [how filter rules are
   792  applied](#how-filter-rules-work) for more details - these flags work
   793  in an identical way to the file name filtering flags, but instead of
   794  file name patterns have metadata patterns.
   795  
   796  
   797  ## Common pitfalls
   798  
   799  The most frequent filter support issues on
   800  the [rclone forum](https://forum.rclone.org/) are:
   801  
   802  * Not using paths relative to the root of the remote
   803  * Not using `/` to match from the root of a remote
   804  * Not using `**` to match the contents of a directory
   805