Hi,
I'm starting bash shell script and I'm looping without any solution.
I'm trying to find some files under a folder hierarchy and in case of errors moving these files to a destination folder under the same hierarchy recreating this hierarchy if not exists.
Finding all ._* files under /src and moving them to /dest recreating folder1 or the others which contains ._* files but without moving files which does not correspond to the pattern.
Code:
/src
._file1 -> move it to /dest
._file2 -> move it to /dest
fileX -> nothing to do
/src/folder1 -> recreate folder under /dest
._file3 -> move it to /dest/folder1
._file4 -> move it to /dest/folder1
fileY -> nothing to do
/src/folder1/folder4 -> recreate folder under /dest
._file5 -> move it to /dest/folder1/folder4
fileB -> nothing to do
/src/folder2 -> nothing to do
fileD -> nothing to do
...
as ..
Code:
/dest
._file1
._file2
/dest/folder1
._file3
._file4
/dest/folder1/folder4
._file5
...
I tried find command and I'am getting all needed files
Code:
find ./src/* -type f -name "._*"
But I don't know how to use the output to get the parent folder of files which are found to
1- create folder with mkdir -p /dest/folder1 or /dest/folder1/folder4
2- move found files from /src/... to /dest/... with rm command
I'm working on a find command as this trying to do all in the same line but ... little lost
Code:
find ./src/* -type file -name "._*" -exec dirname "{}" \; -exec basename "{}" \;
If someone could help me thanks in advance.
Kind Regards