쉘스크립트 문의 드려요. find로 찾은 설정 파일 백업하기

안녕하세요.
아래와 같이 찾고 진행 했는데.. 더 이상 진행이 안되서 문의 드려요..
고수님들의 가이드 부탁 드려요..
가. 하려는 것
설정 파일들을 찾아서 해당 파일을 복사 하려고 합니다.
나. 문제점
파일 위치는 틀리지만 파일명이 같을 경우 덮어 씌우거나 복사하지 못합니다.
파일을 이름을 바꿀 경우 어느 위치에 있는 설정 값인지 알 수 없다는 문제가 발생.
다. 해결 방법
파일의 경로까지 가져 와서 복사 하면 될 것 같다는 생각을 함.
라. 실행 명령어
A. 아래 파일을 복사 하려고 합니다
[root@ufw ~]# find /opt -name "*.conf" | grep local
/opt/splunkforwarder/etc/apps/learned/local/props.conf
/opt/splunkforwarder/etc/apps/Splunk_TA_stream/local/streamfwdlog.conf
/opt/splunkforwarder/etc/apps/Splunk_TA_stream/local/inputs.conf
/opt/splunkforwarder/etc/system/local/inputs.conf
/opt/splunkforwarder/etc/system/local/server.conf
/opt/splunkforwarder/etc/system/local/outputs.conf
B. 위 파일을 아래 경로로 복사 하려고 합니다.
/opt/test/splunkforwarder/etc/apps/learned/local/props.conf
/opt/test/splunkforwarder/etc/apps/Splunk_TA_stream/local/streamfwdlog.conf
/opt/test/splunkforwarder/etc/apps/Splunk_TA_stream/local/inputs.conf
/opt/test/splunkforwarder/etc/system/local/inputs.conf
/opt/test/splunkforwarder/etc/system/local/server.conf
/opt/test/splunkforwarder/etc/system/local/outputs.conf
C. 내가 찾은 방법
dirname을 이용해서 경로만을 가져 올 수 있음
sed 's/opt/opt\/test/g' 를 이용해 경로를 바꿀 수 있음
cp -rp 옵션을 사용 할 경우 /opt/test 디렉토리만 있으면 아래 디렉토리는 알아서 생성됨
D. 아래 쉘스크립트를 통해 각각 list는 가져 올 수 있으나..
dirname, sed, cp -rp 명령어를 적용 할 수가 없어요.
실력이 부족 합니다.
#!/bin/bash
count=$(find /opt -name "*.conf" | grep local | wc -l )
file_name=$(find /opt -name "*.conf" | grep local )
for ((i=1; i<=$count; i++ ))
do
echo $file_name | awk -F " " '{print $'$i'}'
done
.
.
지금 보니 경로가 잘못되었네요.
이 부분을 알아서 수정하기 바랍니다.
댓글 달기