mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 07:08:01 +00:00
Add Exclude Certain Files From An rsync Run as a unix til
This commit is contained in:
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
|
||||
|
||||
For a steady stream of TILs, [sign up for my newsletter](https://tinyletter.com/jbranchaud).
|
||||
|
||||
_1083 TILs and counting..._
|
||||
_1084 TILs and counting..._
|
||||
|
||||
---
|
||||
|
||||
@@ -1016,6 +1016,7 @@ _1083 TILs and counting..._
|
||||
- [Do Not Overwrite Existing Files](unix/do-not-overwrite-existing-files.md)
|
||||
- [Enable Multi-Select Of Results With fzf](unix/enable-multi-select-of-results-with-fzf.md)
|
||||
- [Exclude A Directory With Find](unix/exclude-a-directory-with-find.md)
|
||||
- [Exclude Certain Files From An rsync Run](unix/exclude-certain-files-from-an-rsync-run.md)
|
||||
- [Figure Out The Week Of The Year From The Terminal](unix/figure-out-the-week-of-the-year-from-the-terminal.md)
|
||||
- [File Type Info With File](unix/file-type-info-with-file.md)
|
||||
- [Find Files With fd](unix/find-files-with-fd.md)
|
||||
|
||||
33
unix/exclude-certain-files-from-an-rsync-run.md
Normal file
33
unix/exclude-certain-files-from-an-rsync-run.md
Normal file
@@ -0,0 +1,33 @@
|
||||
# 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.
|
||||
Reference in New Issue
Block a user