I want to index some files on my NAS after moving them in the correct folder. My command would be something like :
find *.$ext -exec mv "{}" $path \; -exec synoindex -a $(echo $path)$(basename "{}") \;
The first part is working. All files with $ext extension are moved to destination $path. But the second part, which is supposed to index these files in their new $path folder, does not work.
This is strange because :
Thanks for any idea.
Regards,
Your command substitutions $(echo $path)
and $(basename "{}")
are executed by your shell before find
is executed.
And you don't need to echo
the $path
variable. You could execute a small shell script instead:
find . -type f -name "*.$ext" -exec sh -c '
targetpath=$1; shift # get the value of $path
for file; do
mv -i "$file" "$targetpath"
synoindex -a "$targetpath/${file##*/}"
done
' sh "$path" {} +
This starts find
in the current directory .
searching for regular files (-type f
) ending with
the file extension $ext
(-name "*.$ext"
)
and executes a small shell script passing the $path
variable as first argument to the script.
The following arguments are the filepaths found by find
.
The parameter expansion ${file##*/}
removes the longest prefix */
from the file and the result is the basename.
If your $path
variable already contains a trailing slash /
, then omit the /
after $targetpath
.