0

Similar to the question asked here, I'm trying to move a list of files from one folder to another whilst preserving the directory structure. The move command happens after a chain of events earlier in the bash script.

In the linked example, the mv command happens on the fly (in a separate C shell?) while the script is doing its finding. This will not work for me, as I need to process the files in the list through an AV scan first. Once they have passed the AV scan, I then want to move them to their destination, preserving directory structure.

My original solution was

while read moveitems; do
  printf "mv \"$moveitems\" \"$hotfolder\"\n"
done <"$filesin" | tee -a "filemoves" >/dev/null
chmod +x $filemoves
$filemoves >> $scanlog

Which only worked as far as moving all files into a single folder, which isn't suitable for this situation.

I'm sure there are many more elegant, efficient solutions to this problem, unfortunately I'm a right-brain person and this kind of thing doesn't come easy to me. Please help! Thanks

0

Mention all the filenames in file. Below mention command will move all the filenames to target directory:

awk '{print "mv " " " $1  " " "/Destinationpath"}' filename|sh
  • This suffers from the same problem as my original script, in that the directory structure is not maintained and everything is dumped into a single folder. Also it can't handle whitespace in filenames. – hallicks Jul 8 at 9:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.