33 lines
710 B
Bash
Executable File
33 lines
710 B
Bash
Executable File
#!/bin/bash
|
|
|
|
set -e
|
|
function helpexit() {
|
|
echo Usage: $( basename "$0" ) source/ target/ [include] [[include]]
|
|
echo Copy files with a glob inclusion, keeping folder structure.
|
|
echo Example: fromfolder/ to/folder/ '*.jpg' '*.png'
|
|
echo This command always
|
|
echo '* recurses to folders!'
|
|
echo '* overwrites existing files'
|
|
exit
|
|
}
|
|
|
|
for ((i=1; i<=${#@}; i++)) {
|
|
[[ "${!i}" = "-h" ]] && helpexit
|
|
[[ "${!i}" = "--help" ]] && helpexit
|
|
}
|
|
|
|
if [[ -z "$3" ]]; then
|
|
helpexit
|
|
fi
|
|
|
|
SRC="$1"
|
|
TGT="$2"
|
|
|
|
for ((i=3; i<=${#@}; i++)) {
|
|
includes="$includes --include=\"${!i}\""
|
|
}
|
|
|
|
eval rsync -av --no-i-r --prune-empty-dirs \
|
|
--include="*/" "$includes" --exclude="*" \
|
|
"$SRC" "$TGT"
|