简体   繁体   English

在Linux中复制具有目录结构的修改文件

[英]Copy modified files with directory structure in linux

How can I copy a list of files modified today with the directory structure into a new directory. 如何将使用目录结构修改的文件列表复制到新目录中。 As shown in the following command I want to copy all the files modified today from /dev1/Java/src into /dev2/java/src. 如以下命令所示,我想将今天修改的所有文件从/ dev1 / Java / src复制到/ dev2 / java / src。 The src folder has many sub directories. src文件夹有许多子目录。

find /dev1/Java/src -newermt 2014-06-10 > 1.txt 查找/ dev1 / Java / src -newermt 2014-06-10> 1.txt

for f in $(cat 1.txt) ; 为$(cat 1.txt)中的f; do cp $f /dev2/Java/src; 做cp $ f / dev2 / Java / src; done DONE

You can take advantage of find and cpio utility. 您可以利用findcpio实用程序。

cd /dev1/Java/src; find . -mindepth 1 -mtime -1 | cpio -pdmuv /dev2/Java/src

The above command goes to the source directory and finds the list of new files relative to the source directory. 上面的命令转到源目录,并找到相对于源目录的新文件列表。

The output is read by cpio and copies the files into the target directory in the same structure as the source, hence the need for relative pathnames. cpio读取输出,并将文件以与源相同的结构复制到目标目录,因此需要相对路径名。

提取一天之内修改的文件,并将其复制到所需的路径。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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