I am using a simple script to create some directories. Finding some specific files by name and then moving them into the directories that I have created. The code that I am using is below: mkdir ./3DBGB_run   mkdir ./run_optimization   mkdir ./run_optimization/project_mesh   mkdir ./run_optimization/CFD_optimized    find . -name '*.template' -exec mv -i {} ./3DBGB_run \;                 find . -name '3dbgbinput.*.dat' -exec mv -i {} ./3DBGB_run \;           find . -name 'controlinputs.*.dat' -exec mv -i {} ./3DBGB_run \;            find . -name '*.iec' -exec mv -i {} ./run_optimization/project_mesh \;           find . -name '*.trb' -exec mv -i {} ./run_optimization/project_mesh \;  find . -name '*.py' -exec mv -i {} ./run_optimization \;**Code runs and moves the files to the desired directories but then it also display an error message for each file that cannot move file because it is the same file
mv command error already existing file
find;mv
You should avoid search in target directory. So you can add ! -path $TARGET_DIR as for example:find . -name '*.template' ! -path *3DBGB_run/* -exec mv -it ./3DBGB_run {} \+