Created
November 26, 2020 15:33
-
-
Save vpnry/d75f1b1ed11270bbcc9f19ca7d7a248e to your computer and use it in GitHub Desktop.
Move files with specific exts while preserving their directory structures
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Move files while preserving its directory structures | |
| # From https://unix.stackexchange.com/a/59159 | |
| FILEext=".*\.\(avi\|mp3\|mp4\)" | |
| SOURCE=/home/d/dev/dev/D/A/ | |
| DEST=/home/d/dev/dev/D/BB/ | |
| mkdir -p "$DEST" | |
| destination=$(cd -- "$DEST" && pwd) # make it an absolute path | |
| cd -- "$SOURCE" && | |
| find . -type f -iregex "$FILEext" -exec sh -c ' | |
| for x do | |
| mkdir -p "$0/${x%/*}" | |
| mv "$x" "$0/$x" | |
| done | |
| ' "$destination" {} + | |
| # FILEext=(mpg avi mp3 mp4) | |
| # for f in ${FILEext[@]}; do | |
| # echo $f | |
| # done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment