0

I want to copy the recently updated multiple file into another directory.

I am having 1.xml,2.xml,3.xml.... in this directory recently someone updated file or added new file into the directory,So i want to copy those files into the destination directory ..Its like synchronization of 2 directories.

For that I have tried below commend

find home/deployment/server/services/ -type f  -mtime 1  | xargs cp  /home/application/

and below one also

find home/deployment/server/services/ -type f  -mtime 1  -exec cp  /home/application/

I am not getting any file into destination after updating 1.xml file,So I have added new file 4.xml even that also not updating in destination directory.

How to process recently updated or newly added multiple files.

Thanks in advance.

Faisal
  • 1,469
  • 2
  • 13
  • 25
  • `rsync -aHSP home/deployment/server/services/. /home/application/.` If you don't have `rsync` installed, grab it from sunfreeware... – twalberg Feb 16 '15 at 21:01

2 Answers2

1

Short answer: use xargs to mv the "find" directory into another directory

Long answer: As I recall (not tested) for exec syntax is

find . -type f --mtime 1 -exec cp {} /destination/path/ +

"{}" is an argument which came from command "find"

For xargs

find . -type f --mtime 1 | xargs -0 -I {} cp {} /destination/path/
Community
  • 1
  • 1
  • But where it will find you have not defined source here the where i need to run this commend – Faisal Feb 17 '15 at 12:34
  • xargs: illegal option -- 0 xargs: Usage: xargs: [-t] [-p] [-e[eofstr]] [-E eofstr] [-I replstr] [-i[replstr]] [-L #] [-l[#]] [-n # [-x]] [-s size] [cmd [args ...]] – Faisal Feb 18 '15 at 09:13
0

I do this often but use \; instead of + and usually -cnewer rather than -mtime.

\; executes the cp command on files individually instead of as a group. + executes as a group with as many paths as xterm will take. It may do this multiple time if there are a lot of files.

the \ in front of the ; option is required or bash will think it is the end of the command.

find ./ -mtime -1 -exec cp {} /path/ \; -print

Use the -print at the end to get a list of the files that were copied.

  • But where it will find u have not defined source here the where i need to run this commend – Faisal Feb 17 '15 at 12:33
  • I usually run from the folder the files are listed in. Try this one: find /home/deployment/server/services/ -type f -mtime -1 -exec cp {} /home/application/ \; -print – 12ChocolateBrownies Feb 17 '15 at 16:17
  • find: stat() error home/server/synapse/services/: No such file or directory – Faisal Feb 18 '15 at 09:06
  • above commoned copying only 1 file not morethan that – Faisal Feb 18 '15 at 09:16
  • "home/server/synapse/services/" This isn't the path I put. Where did synapse come from? Did you mean to use "/home/server/synapse/services" in your find? The first / is important if you haven't changed directories into the root folder. -mtime -1 will only find changes made less than 24 hours ago. If your files changes are older than that you will need to use a bigger mtime value like -2 (-2 * 24 = any changes in the last 48 hours) – 12ChocolateBrownies Feb 18 '15 at 14:29