简体   繁体   中英

How to copy the recent updated multiple files in another directory in Solaris

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.

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/

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM