Skip to content

Instantly share code, notes, and snippets.

@entendu
Created January 11, 2020 07:27
Show Gist options
  • Select an option

  • Save entendu/275bbeb159d42f8c62601772c77c7cfd to your computer and use it in GitHub Desktop.

Select an option

Save entendu/275bbeb159d42f8c62601772c77c7cfd to your computer and use it in GitHub Desktop.
dest="../dst-test"; find . -type d -mindepth 1 -exec mkdir -p "$dest/"{} \; find . -type f -print0 | while IFS= read -r -d '' file; do if [[ "$(basename "$(dirname "$file")")" =~ ^[0-9]{4} ]]; then newfile=$(basename "$file"); else newfile=$file; fi; if [[ -f "$dest/$newfile" ]]; then i=1; until [[ ! -f "$dest/$newfile-$i" ]]; do ((i++)); done; newfile="$file-$i"; fi; echo "mv $file $dest/$newfile"; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment