Those of you using Linux -I know we are a lot, looking for software to sync your home folder to an external USB drive, stop that. You don’t need to purchase software or look outside of your own machine to do that in a pretty consistent manner. Just using the tools Linux itself provides for free.

We talk about rsync in this case. We have down below a script that will read and transfer only the newer files -created or modified, from a source directory to a destination directory. Then afterwards, it will do the same the other way around, just in case something is newer in the external drive.

Consider it has the -n option set, so this example will only do a dry-run, nothing will be really done even if it looks like that. Once you are comfortable with what will happen when you run the script, you can get rid of the -n option.

Consider also changing all the appearances of source and destination in the script as these are dummy names just for the example. I wrote this thinking on syncing your home folder to an external USB HDD, so here’s what works for me.

    #!/bin/sh
    exitcode=1
    #do check if usb hdd is mounted
    echo "CHECKING IF USB HDD IS AVAILABLE..."
    if test -e '/path_to_the_mountpoint/'; then
    exitcode=0
    #from home folder to usb hdd if local files are newer
    echo "SYNCING UP FROM PC TO USB HDD"
    rsync -avun --inplace --info=progress2 --info=name0 /source/ /path_to_the_mountpoint/
    #from usb hdd to home folder if usb hdd files are newer
    echo "SYNCING UP FROM USB HDD TO PC"
    rsync -avun --inplace --info=progress2 --info=name0 /path_to_the_mountpoint/ /source/
    fi
    #if the usb hdd is not mounted exit wit exitcode=1
    echo "USB HDD NOT MOUNTED!"
    exit $exitcode