使用 CSV 中的文件名列表将文件从一个目录复制到另一个目录的 Shell 脚本

发布于 2024-12-28 16:45:37 字数 340 浏览 5 评论 0原文

我有一个需要复制的文件列表。我想递归搜索驱动器并将这些文件复制到设定位置(如果该文件名存在于列表中)。该列表是一个文本文件/

文本文件看起来像这样:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

十秒萌定你 2025-01-04 16:45:37

使用find会花费很多时间,如果可能的话尝试使用locate

当有几场比赛时会发生什么?就像搜索 foo.bar 并拥有 a/foo.bar 和 b/foo.bar 在这种情况下你会做什么?

你的csv似乎包含一个路径,考虑到前面的内容,我假设这些路径实际上在脚本运行的地方是有效的,所以在这种情况下只需这样做:

#!/bin/bash

while read path; do
    cp "$path" "$1"
done

然后像这样调用它:

teh_script /path/to/destination < csv-file.csv

using find will take a lot of time, try to use locate 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:

#!/bin/bash

while read path; do
    cp "$path" "$1"
done

then call it like this:

teh_script /path/to/destination < csv-file.csv
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文