Léo Coco
Léo Coco

Reputation: 4282

Equivalent to robocopy on MacOs - Copy full folder structure but with empty files

What I want to achieve

I would like to copy the structure of an existing folder including folders and files but I would like the size of the files to be 0. So it would create an empty file, with the same name and extension.

Windows

I know how to do it by running : robocopy source destination /create /e /xc /xn /xo

Question

What is the equivalent command I could use on Mac ?

Upvotes: 1

Views: 1729

Answers (1)

Jetchisel
Jetchisel

Reputation: 7801

Here is a script that might do what you want.

#!/usr/bin/env bash

source=$1
dest=$2

while IFS= read -rd '' file; do
  mkdir -p "$dest${file%/*}" || exit
  touch -r "$file" "$dest$file"
done < <(find "$source" -type f -print0)

Howto use

./myscript source/ destination/

Upvotes: 1

Related Questions