I'm using mv to move a huge folder from one hard drive to another and I noticed that it waits until the end to delete files it has successfully moved. Is there a reason for this? Is there a way to make it delete files as it goes or is there a different program that does this?
The problem with waiting until the end is that if mv is abnormally aborted it will take a lot longer to resume moving because each file in the destination directory will either need to be overwritten or compared against the one in the source directory. In addition if each file is deleted after a successful copy then space is freed'd up while moving which is important for emergency purposes if one hard drive is about to run out of space and a program is about to try and use more space than available and you have a flash drive or another hard drive available to prevent the already running program from failing.
The command I used was this:
mv -v -t /dst /src/folder
rsync --remove-source-files /dst/ /src/folder/
will do what you want. Test it properly; rsync is sensitive to presence or absence of trailing slashes. Also, the source directories (now empty) will remain, so you have to clean them up manually later, but empty directories don't take a lot of space so this 2-step thing is still better thanmv
for your stated purposes/problems withmv
. – Jun 20 '20 at 11:02