使用 CSV 中的文件名列表将文件从一个目录复制到另一个目录的 Shell 脚本
我有一个需要复制的文件列表。我想递归搜索驱动器并将这些文件复制到设定位置(如果该文件名存在于列表中)。该列表是一个文本文件/
文本文件看起来像这样:
A/ART-FHKFX1.jpg
B/BIG-085M.jpg
B/BIG-085XL.jpg
L/LL-CJFK.jpg
N/NRT-56808EA.jpg
P/PFE-25.10.jpg
P/PFE-7/60.jpg
P/PFE-7L.20.jpg
P/PFE-8.25.jpg
P/PFE-9.15.jpg
P/PFE-D11.1.tiff
P/PFE-D11.1.tiff
P/PFE-D12.2.tiff
P/PFE-D12.2.tiff
I have a list of files that I need to copy. I want to recursively search a drive and copy those files to a set location if that filename exists in the list. The list is a text file/
the text file would look something like this:
A/ART-FHKFX1.jpg
B/BIG-085M.jpg
B/BIG-085XL.jpg
L/LL-CJFK.jpg
N/NRT-56808EA.jpg
P/PFE-25.10.jpg
P/PFE-7/60.jpg
P/PFE-7L.20.jpg
P/PFE-8.25.jpg
P/PFE-9.15.jpg
P/PFE-D11.1.tiff
P/PFE-D11.1.tiff
P/PFE-D12.2.tiff
P/PFE-D12.2.tiff
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
find
会花费很多时间,如果可能的话尝试使用locate
。当有几场比赛时会发生什么?就像搜索 foo.bar 并拥有 a/foo.bar 和 b/foo.bar 在这种情况下你会做什么?
你的csv似乎包含一个路径,考虑到前面的内容,我假设这些路径实际上在脚本运行的地方是有效的,所以在这种情况下只需这样做:
然后像这样调用它:
using
find
will take a lot of time, try to uselocate
if possible.what will happen when there's several matches? like searching for foo.bar and having a/foo.bar and also b/foo.bar what would you do in that case?
your csv seems to include a path, given the previous I'll assume those paths are actually valid from where the script is run so in that case just do this:
then call it like this: