Sync Files, with Rsync, newer then X days

Posted on Monday, 16 of January of 2017
1245by Octávio Gonçalvessshrsynccommand line

Rsync is a utility that keeps copies of a file on two computer systems.

It is commonly found on Unix-like systems and functions as both a file synchronization and file transfer program. The rsync algorithm is a type of delta encoding, and is used to minimize network usage. Zlib may be used for additional compression and SSH or stunnel can be used for data security.

Rsync is typically used to synchronize files and directories between two different systems. For example, if the command rsync local-file user@remote-host:remote-file is run, rsync will use SSH to connect as user to remote-host. Once connected, it will invoke the remote host's rsync and then the two programs will determine what parts of the file need to be transferred over the connection.

So, how can i use Rsync, if i want to copy files from a source directory, newer then 30 days?

rsync -rav --no-o --no-g  `find /home/source_dir -type f -mtime -50` /home2/target_dir

Explanation:

rsync: Call rsync
-rav: recursive, archive, verbose
--no-o: Dont preserve owner
--no-g: Dont preserve group
find: search for file in source_dir
-type: tell find that you only want files, with flag 'f'
-mtime: teel find that you want all files newer then 50 days (-50)

 

Share or save this article

slashdot