> For the complete documentation index, see [llms.txt](https://ploegert.gitbook.io/til/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ploegert.gitbook.io/til/os/unix/process/exclude-certain-files-from-an-rsync-run.md).

# Exclude Certain Files From An rsync Run

The `rsync` command can be used to copy files from one directory to another (as well as to or from a remote system). It is generally used to broadly synchronize all files in the source directory to a destination directory.

I recently ran into a situation where I wanted to recursively (`-a`) sync files from a cloned git repository. I didn't want quite everything—namely dotfiles, dot-directories (such as `.git/`), and top-level markdown files.

This is where the `--exclude` flag comes in to play.

The dotfiles and dot-directories can be excluded with the `.*` pattern.

```bash
$ rsync -anv --exclude='.*' dir1/ dir2
```

The top-level markdown files can be excluded, without excluding nested markdown files, with the `./*.md` pattern.

```bash
$ rsync -anv --exclude='.*' --exclude='./.*md' dir1/ dir2
```

The `-n` and `-v` flags together provide a dry run of this with results that I can check. Once I'm ready to do the real thing, I can remove those.

```bash
$ rsync -a --exclude='.*' --exclude='./.*md' dir1/ dir2
```

See `man rsync` for more details.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ploegert.gitbook.io/til/os/unix/process/exclude-certain-files-from-an-rsync-run.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
