Skip to main content

Sync files from remote system via command line - Linux, Ubuntu, Debian

If you are using more than one laptop/computers in your day to day life for eg: Your personal laptop and Office laptop. Chances of needing a file from one laptop on the other laptop is very common. We don't want to copy the files over the system again and again. We just want the changes to the files made in one system to reflect on the other system.

In this post we will see a simple way to keep files in sync between your multiple laptops/computers. Linux has an wonderful utility called rsync which can be used to sync files/folders between systems in a very optimised way (copy only modified and new files/folders)
If you don't have rsync utility installed on your system, install it by
$ sudo apt-get update
$ sudo apt-get install rsync
Also we are planning to sync files from remote systems, So lets have the openssh-server installed on the both machines
$ sudo apt-get install openssh-server
openssh-client will be by default installed on linux machines, if not install it
$ sudo apt-get install openssh-client

Basic Usage of rsync

$ rsync source destination
The above command will simply send/sync all the files recursively under the directory 'source' to the 'destination'
To send/sync files to a remote systems
$ rsync source username@host:destination
Note: "username@host:"  will point to home directory of username in the host (Please note the colon (:) at the end of hostname)
With some more options from rsync we can create a single line file syncronizer as follows
$ rsync -avzP username@host:source destination
Options used:
-a     - archive mode
-v     - increase verbosity
-P     - To see the file transfer progress with its speed
-z     - compress file data during transfer
         Use this option so that you can utilise your network bandwidth efficiently
Note: I have changed the username@host term to the source option to intimate that remote host can be either source or destination.

Skip Some files from Sync/Copy

$ rsync -avzP --exclude "*.conf" username@host:source destination
--exclude option will exclude the specified file(s) syncing from source to destination. You can give a file name, Directory name or even file globs like (*.something)

To skip more files

Enter your list of files to be skipped/excluded in a text file and use that in rsync with  --exclude-from option
# File exclude-list.txt
*.conf
bin
blib
Now pass this file name to --exclude-from option
$ rsync -avzP --exclude-from exclude-list.txt username@host:source destination

Some more options to make it more finer tool

Sometimes we might have just changed the permissions/groups for a file/folder but we don't want to reflect that change on the other machine.
$ rsync -avzP --no-group --no-perms --no-owner username@host:source destination
You can create an alias of the above command and make life even more easier. rsync utility has many other options available please do check manual of rsync for more options (man rsync).

Comments

Popular posts from this blog

Upgrade your kitchen with latest Tech Gadgets and Make cooking faster

Welcome to our latest blog post, where we embark on an exciting culinary journey to elevate your kitchen experience with cutting-edge technology gadgets. In this fast-paced world, cooking has become more than just a necessity; it's an art form that deserves the finest tools. Join us as we explore the innovative tech solutions that can revolutionize the heart of your home, making cooking not only faster but also more enjoyable and efficient. From smart appliances to intelligent cooking assistants, we'll introduce you to a range of futuristic kitchen companions that are sure to inspire your inner chef and transform the way you create delightful meals for yourself and your loved ones. Get ready to upgrade your kitchen and embrace the future of cooking!  In this blog post, we will narrow down the vast array of available kitchen tech gadgets and present only 10 items, carefully selected based on product ratings, price, and their suitability for Indian kitchens.  Are you a Telegram u

TataSky Refresh after Recharge - Activate after Recharge

If you are using TataSky and doing recharge occasionally and that too after disconnection, this post will be very helpful for you. Most of the time you will not get the channels listed as soon as you make the payment. It will display message to Subscribe for that channel. You can easily get channels back by simply giving a missed a call from your registered mobile number. Note: Make sure your TV and SetupBox is on and showing the error message Give missed call to  +91 80892 80892 (Soft Refresh)   wait for 1 minute and If still not active then try giving missed call to  +91 90405 90405 (Heavy Refresh). Ad: Planning to buy a Best low budget Smart TV? Consider  Acer 109 cm (43 inches) I Series 4K Ultra HD Android Smart LED TV AR43AR2851UDFL (Black)  - You can get this TV as low as for 20,000 Rs - which has Bluetooth, WiFi, Android and good customer ratings (4.4/5). Note: Price based on offers, click on the link to see current price on the web page If the above ste

Duplicate file finder/Remover using perl and SHA1

When you are using a computing devices (either a laptop or PC or a Tab) for your personal use after some time (let take some years) you will realise that your disk is full and most of the space are occupied by duplicate files (Same copy of file located in different locations). For ex: You might have a favourite music file in "My Favourite" folder as well as in the "Album" folder. But finding this duplicate manually is a biggest process. That too if the file names are different OMG!. There are lot of free utilities available to do this in automated way, but if you are a programmer, you will always prefer to do it on your own. Here are the steps we are going to do. This is purely on a linux - Ubuntu system.  (for windows you might need to change the path as per conventions ) Getting SHA1 for all the files recursively in a given directory Compare SHA1 with other files Remove the duplicate file Getting SHA1 of a file Using cpan module   Digest::SHA1 we c