Copy files preserving folder structure

2019-08-05 05:59发布

Could anyone help me to make a shell script to:

Having a certain folders and subfolders structure, copy from it to some other location all the files modified from a given date (or from a number of days on) and always preserving the folder structure.

So the result would be a subset of the origin having only the files that match the modified date condition. No need to place this new subset in any remote location... just another folder in the same file system.

Any idea on doing this?

I can think of some manual methods, but if there were something more "automatic", I'd like to know.

Thanks a lot

标签: linux file shell
1条回答
Root(大扎)
2楼-- · 2019-08-05 06:22

You could use this script:

#!/bin/bash
mkdir -p "$2" && find . -type f ! -mtime +$1 | tar -cT - -f - |tar -C "$2" -xf -

usage:

copyscript <not-older-than-N-days> <destination dir>
查看更多
登录 后发表回答