Best Way to Continue a Terminated Move Operation By Merging Directories

It is not recommended to use mv for moving folders. In Windows, when I move stuff from memory sticks or portable hard drives to my laptop and some error occurs, I usually loose data.

Use copy instead of mv!

$ cp /home/source_folder /home/target_folder && rm /home/source_folder

Instead of:

$ mv /home/source_folder /home/target_folder

When the data transfer gets an error and gets interrupted, there will be two folders, one in the source_folder and one in the target_folder. You have to move the data from the source_folder to the target_folder, again, by hand.

Another solution is to use rsync for this:

rsync -va -n /home/source_folder /home/target_folder

Explenation:

The -n option will simulate the moving, showing you what it would do without doing anything.

If it is what you need, do it without the -n option:

$ rsync -va /home/source_folder /home/target_folder

How I do this:

I don’t like rsync, so I have created a function like this (add this to your ~/.bashrc):

$ move2() { cp -R “$1" "$2” && rm -R "$1" "$2" }

This function gets the what_to_move and where_to_move folders as parameters and does a simple recursive copy on them, and deletes the what_to_move dir if the copy finishes successfully.

You use it like this: move2 what_to_move where_to_move . It does recursive copies, so you don’t need to put a special argument for making it recursive.

Tagged with: , , , , , , , , ,
Posted in The Linux and Unix Articles!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Subscribe

  

Subscribe to get the latest Linux news and how to guides directly on your e-mail!