gpt4 book ai didi

linux - 复制目录下所有文件夹中的文件

转载 作者:太空宇宙 更新时间:2023-11-04 04:44:37 27 4
gpt4 key购买 nike

给定源文件路径和目标路径。如何编写shell脚本将源文件复制到目标目录的所有文件夹中?

最佳答案

您不需要脚本。使用 cp -R 进行递归复制:

cp -R source_path dest_path

要在保留文件属性(例如上次修改时间等)的同时进行递归复制,请使用 -p 选项:

cp -Rp source_path dest_path

来自man cp:

 -R

If source_file designates a directory, cp copies the directory and the entire subtree connected at that point. If the source_file ends in a /, the contents of the directory are copied rather than the directory itself. This option also causes symbolic links to be copied, rather than indirected through, and for cp to create special files rather than copying them as normal files. Created directories have the same mode as the corresponding source directory, unmodified by the process' umask.

关于linux - 复制目录下所有文件夹中的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44234630/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com