Moving specific files

Hello, I am trying to move specific files to a specific folder. I have a virus script that runs and quarantines the files by changing the ownership to -r--------. This has worked fine but I am wanting to actually move the infected files to a folder called quarantine. I have came up with a basic script but it does not seem to be working properly. I am doing a "find" on the ownership specified above, which is also working fine. I am stuck on the part of moving the files once they have been found. Any help or suggestions is greatly appreciated.

#!/bin/sh

archive=/home/quarantine
cd /home
find . -user root -perm 0400 -type f | while read file; do
dir=`dirname "$file"`
mkdir -p "$archive/$dir"
mv $file "$archive/$dir"
done

You are using dirname to grab the directory from a path. Now use basename to grab the filename from the path.

$
$
$ basename /etc/passwd
passwd
$ dirname /etc/passwd
/etc
$

archive=/home/quarantine
cd /home
find . -user root -perm 0400 -type f |
 while IFS= read -r file
 do
    dir=${file%/*}
    mkdir -p "$archive/$dir"
    mv "$file" "$archive/$dir"
 done

Where is the basename of the file needed?

if it is, there's no point to using a slow external command when the shell has the neccessary parameter expansion:

var=/etc/passwd
printf "%s\n" "${var##*/}"

Except that the OP indicated the use of /bin/sh and didn't give an indication of the OS. In this case I would err on the side of caution and assume the use of the bourne shell, not a POSIX shell.