move files that match file names in another directory
Try,
for f in "dir_2"/*; do
filename=${f##*/}
mv -t "dir_3" "dir_1/${filename%.*}".*
done
- Loop files in
dir_2
(use*.txt
to only loop these files) -
${f##*/}
gives you the file name without the path. -
${filename%.*}
gives you the filename without extension. -
mv -t "dir_3" "dir_1/${filename%.*}".*
moves all files with givenfilename
(cleared from the extension) todir_3
. You can specify.mp4
instead of.*
if you want.