1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-02 22:58:01 +00:00

Add Copying Nested Directories With Ditto as a unix til

This commit is contained in:
jbranchaud
2019-10-22 15:07:21 -05:00
parent c67ac399bb
commit 1235443b1b
2 changed files with 49 additions and 1 deletions

View File

@@ -10,7 +10,7 @@ smart people at [Hashrocket](http://hashrocket.com/).
For a steady stream of TILs from a variety of rocketeers, checkout
[til.hashrocket.com](https://til.hashrocket.com/).
_857 TILs and counting..._
_858 TILs and counting..._
---
@@ -756,6 +756,7 @@ _857 TILs and counting..._
- [Command Line Length Limitations](unix/command-line-length-limitations.md)
- [Configure cd To Behave Like pushd In Zsh](unix/configure-cd-to-behave-like-pushd-in-zsh.md)
- [Copying File Contents To System Paste Buffer](unix/copying-file-contents-to-system-paste-buffer.md)
- [Copying Nested Directories With Ditto](unix/copying-nested-directories-with-ditto.md)
- [Create A File Descriptor with Process Substitution](unix/create-a-file-descriptor-with-process-substitution.md)
- [Curling For Headers](unix/curling-for-headers.md)
- [Curling With Basic Auth Credentials](unix/curling-with-basic-auth-credentials.md)

View File

@@ -0,0 +1,47 @@
# Copying Nested Directories With Ditto
You can copy nested directories with `cp` using the `-R` (_recursive_) flag.
The way `cp` works is that it replaces the target location with the source
directory, wiping out whatever files or directories reside at the target
location.
Conversely, the `ditto` utility, available on OS X's version of Unix, does
_recursive_ directory copies by default and merges the contents of any existing
directories.
As an example, here are two folders, `folder1` and `folder2`:
```bash
exa -T folder1
folder1
├── cats
│ └── sneaky
└── dogs
└── fido
exa -T folder2
folder2
└── cats
└── oreo
```
Using `ditto` to copy `folder1` to `folder2`
```bash
ditto folder1 folder2
```
we get a `folder2` where directories from `folder1` are created and existing
directories are merged together.
```bash
exa -T folder2
folder2
├── cats
│ ├── oreo
│ └── sneaky
└── dogs
└── fido
```
See `man ditto` for more details.