Skip to content

Instantly share code, notes, and snippets.

@blech75
Created July 14, 2015 18:59
Show Gist options
  • Select an option

  • Save blech75/ce73dcf8479982fe761e to your computer and use it in GitHub Desktop.

Select an option

Save blech75/ce73dcf8479982fe761e to your computer and use it in GitHub Desktop.
copy a given list of paths (via stdin) into a new dir
#!/usr/bin/env bash
if [ $# -ne 1 ] ; then
echo "Usage: $0 target_dir " >&2
exit 1
fi
TARGET_DIR=$1
while IFS= read -r f || [[ -n "$f" ]]; do
parent_dir=`dirname $f`
dest="$TARGET_DIR/$parent_dir"
mkdir -p $dest
echo -n "copying $f to ${dest}..."
cp -p $f $dest && echo " done!"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment