You should be able to use -execdir
to make a copy relative to the directory of the found file(s) e.g.
find Italy -name '*.front.*' -execdir cp -- {} 'fanart.jpg' \;
Example: given
$ tree Italy/
Italy/
├── Florence
│ ├── photo.back.001.jpg
│ ├── photo.back.002.jpg
│ ├── photo.back.003.jpg
│ ├── photo.front.001.jpg
│ ├── photo.front.002.jpg
│ └── photo.front.003.jpg
├── Naples
│ ├── photo.back.001.jpg
│ ├── photo.back.002.jpg
│ ├── photo.back.003.jpg
│ ├── photo.front.001.jpg
│ ├── photo.front.002.jpg
│ └── photo.front.003.jpg
└── Rome
├── photo.back.001.jpg
├── photo.back.002.jpg
├── photo.back.003.jpg
├── photo.front.001.jpg
├── photo.front.002.jpg
└── photo.front.003.jpg
3 directories, 18 files
Then
$ find Italy -name '*.front.*' -execdir cp -v -- {} 'fanart.jpg' \;
‘./photo.front.001.jpg’ -> ‘fanart.jpg’
‘./photo.front.003.jpg’ -> ‘fanart.jpg’
‘./photo.front.002.jpg’ -> ‘fanart.jpg’
‘./photo.front.001.jpg’ -> ‘fanart.jpg’
‘./photo.front.003.jpg’ -> ‘fanart.jpg’
‘./photo.front.002.jpg’ -> ‘fanart.jpg’
‘./photo.front.001.jpg’ -> ‘fanart.jpg’
‘./photo.front.003.jpg’ -> ‘fanart.jpg’
‘./photo.front.002.jpg’ -> ‘fanart.jpg’
(note that if there are multiple files matching the *.front.*
pattern, the copy gets successively overwritten - if that's not what you want, add -n
or --no-clobber
), resulting in
$ tree Italy/
Italy/
├── Florence
│ ├── fanart.jpg
│ ├── photo.back.001.jpg
│ ├── photo.back.002.jpg
│ ├── photo.back.003.jpg
│ ├── photo.front.001.jpg
│ ├── photo.front.002.jpg
│ └── photo.front.003.jpg
├── Naples
│ ├── fanart.jpg
│ ├── photo.back.001.jpg
│ ├── photo.back.002.jpg
│ ├── photo.back.003.jpg
│ ├── photo.front.001.jpg
│ ├── photo.front.002.jpg
│ └── photo.front.003.jpg
└── Rome
├── fanart.jpg
├── photo.back.001.jpg
├── photo.back.002.jpg
├── photo.back.003.jpg
├── photo.front.001.jpg
├── photo.front.002.jpg
└── photo.front.003.jpg
If your system's version of find
doesn't support -execdir
an alternate way would be to remove the filename portion of the full pathname - for example using POSIX parameter expansion of the form "${var%/*}"
- and replace it with the newname in a little inline shell command sh -c
find Italy -name '*.front.*' -exec sh -c 'cp -v -- "$1" "${1%/*}/fanart.jpg"' sh {} \;