Using zsh
:
autoload -U zmv
zmv -v -C -o -R -- 'dir/(group<->)/(sub<->)/**/DCM' 'dir/Base/$1/$2/Time1/'
The zmv
command above takes an extended globbing pattern and a destination pathname. The globbing pattern may contain "capture groups" (parenthesized expressions) that you may refer to with $1
, $2
, etc. in the destination pathname. The command above captures the names of the group
and sub
subdirectories (where <->
matches any number).
The options used here are -n
for a "dry-run" (don't actually carry out any copying; remove this when certain that it works), -v
for "verbose" operation, and -C
to do copying rather than moving. We use -o -R
to pass -R
to cp
.
Testing:
$ tree
.
`-- dir
|-- Base
| |-- group1
| | `-- sub01
| | `-- Time1
| `-- group2
| `-- sub01
| `-- Time1
|-- group1
| `-- sub01
| `-- a
| `-- b
| `-- c
| `-- DCM
`-- group2
`-- sub01
`-- a
`-- b
`-- DCM
$ zmv -v -C -o -R -- 'dir/(group<->)/(sub<->)/**/DCM' 'dir/Base/$1/$2/Time1/'
cp -R -- dir/group1/sub01/a/b/c/DCM dir/Base/group1/sub01/Time1/
cp -R -- dir/group2/sub01/a/b/DCM dir/Base/group2/sub01/Time1/
$ tree
.
`-- dir
|-- Base
| |-- group1
| | `-- sub01
| | `-- Time1
| | `-- DCM
| `-- group2
| `-- sub01
| `-- Time1
| `-- DCM
|-- group1
| `-- sub01
| `-- a
| `-- b
| `-- c
| `-- DCM
`-- group2
`-- sub01
`-- a
`-- b
`-- DCM