I've got this script to loop through all folders and move files that are more than 2 years old. I'm using the install command because it creates the necessary directories on the destination path and then I remove the source. I'd like to change the script to use the mv command since it is much faster than copying the file then deleting it. But I don't know how to get the path without the filename to pass to the mkdir -p command? How should I modify the script?
for d in *; do
find "$d" -type f -mtime +730 -exec sh -c '
echo "moving $d/{}" &&
install -Dp "/data/Customer Files$d/{}" "/data/Customer Files Over 2 Years Old$d/{}" &&
rm -f "/data/Customer Files$d/{}"' \;
done
This method still uses a copy. These are large files and therefore the cp takes way longer than mv since mv just changes the file pointer and doesn't actually copy the file. Can you post it with using mv?
Note also that if the source and destination directories are on different filesystems, the mv utility will internally act as though cp and rm (and, possibly, chmod ) had been done instead).