如何在 Linux 中将文件复制到多个目录?
linuxoperating systemfile system
您是否尝试过在 Linux 或 Unix 中将一个文件复制到一大堆备用目录中?那么,本文将指导您在 Linux/Ubuntu 中将文件复制到多个目录。
使用 cp 和 xargs 进行操作
要在 Linux/Ubuntu 中将文件复制到多个目录,请在命令中使用以下命令 –
$ echo dir1 dir2 dir3 | xargs -n 1 cp file1
在上述命令中,我们将 file1 复制到 dir1、dir2 和 dir3 目录。上述命令的示例如下所示 −
$ echo Music Videos Desktop | xargs -n 1 cp httpstat.py
在上面的命令中,我们将 httpstat.py 文件复制到音乐、视频和桌面目录。要验证上述命令,请使用以下命令 –
$ cd Music ~/Music$ ls
示例输出应如下所示 –
httpstat.py
另一个用于验证上述命令的示例如下所示 –
$ cd Desktop ~/Desktop$ ls
示例输出应如下所示 –
httpstat.py
与 cp 和 find 一起使用>
要在 Linux/Ubuntu 中将文件复制到多个目录,请在命令中使用以下命令 –
find dir1 dir2 dir3 -type d -exec cp file1 {} \;
上述命令查找 dir1、dir2 和 dir3 目录,并将 file1 复制到这些目录。示例如下所示 –
$ find Music Desktop -type d -exec cp httpstat.py {} \;
在上述命令中,我们将 httpstat.py 文件复制到 Music 和 Desktop 目录。要验证上述命令,请使用以下命令 –
$ cd Desktop ~/Desktop$ ls
示例输出应如下所示 –
httpstat.py
另一个验证上述命令的示例如下所示 –
$ cd Music ~/Music$ ls
示例输出应如下所示 –
httpstat.py
在上文中,我们学习了 – 如何在 Linux 中将文件复制到多个目录。在下一篇文章中,我们将介绍更多基于 Linux 的技巧和窍门。继续阅读!
相关文章
有用资源
linux 参考教程 - 该教程包含有关 linux 的更多信息:https://www.cainiaomax.com/linux/

