复制目录列表中的所有 PDF

复制目录列表中的所有 PDF

我正在尝试将目录列表中的所有 PDF 复制到我的临时目录。我有这个命令来获取适用目录的列表:

dirname $(grep -r <my search criteria> /c01/app/*sup) | sort -u

这会在所有.sup文件中搜索我的搜索条件。在这些目录中是我想要复制的 PDF。

编辑:运行更新的命令时:

dirname $(grep -r <my search criteria> /c01/app/09/*/*/*/*/*/system/output/*sup)) | sort -u | xargs -I {} cp -- {}/*pdf .

我收到此错误: cp: cannot stat ‘/c01/app/09/ba/016/500/000/082/system/output/*pdf’: No such file or directory

更多输出:

[user@server payment]$ dirname $(grep -r <my search> /c01/app/09/*/*/*/*/*/system/output/*sup) | sort -u | xargs -I {} cp -- {}/*pdf .

cp: cannot stat ‘./*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/ad/016/500/000/026/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/ad/016/500/000/030/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/ad/016/500/000/033/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/ad/016/500/000/086/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/ad/016/500/000/0a7/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/ad/016/500/000/112/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/ad/016/500/000/191/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/ae/016/500/000/030/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/ae/016/500/000/033/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/ae/016/500/000/036/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/ae/016/500/000/03b/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/ae/016/500/000/043/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/ae/016/500/000/04b/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/ae/016/500/000/04e/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/ae/016/500/000/087/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/ae/016/500/000/08d/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/ae/016/500/000/096/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/ae/016/500/000/09a/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/ae/016/500/000/0a0/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/ae/016/500/000/0a3/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/ae/016/500/000/185/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/ae/016/500/000/1c1/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/ae/016/500/000/1c4/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/af/016/500/000/007/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/af/016/500/000/00a/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/af/016/500/000/00d/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/af/016/500/000/011/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/af/016/500/000/01c/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/af/016/500/000/01f/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/af/016/500/000/02a/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/af/016/500/000/042/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/af/016/500/000/08b/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/b2/016/500/000/006/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/b2/016/500/000/00b/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/b2/016/500/000/018/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/b2/016/500/000/024/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/b2/016/500/000/026/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/b2/016/500/000/02e/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/b2/016/500/000/037/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/b3/016/500/000/007/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/b3/016/500/000/00a/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/b3/016/500/000/00e/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/b3/016/500/000/012/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/b3/016/500/000/017/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/b3/016/500/000/021/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/b3/016/500/000/08d/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/b3/016/500/000/15e/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/b4/016/500/000/016/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/b4/016/500/000/018/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/b4/016/500/000/061/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/b4/016/500/000/076/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/b4/016/500/000/086/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/b4/016/500/000/088/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/b4/016/500/000/0df/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/b5/016/500/000/00a/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/b5/016/500/000/032/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/b5/016/500/000/05b/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/b5/016/500/000/066/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/b9/016/500/000/004/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/b9/016/500/000/014/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/b9/016/500/000/01a/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/b9/016/500/000/02e/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/b9/016/500/000/03b/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/b9/016/500/000/081/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/b9/016/500/000/08b/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/b9/016/500/000/08e/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/b9/016/500/000/091/system/output/*pdf’: No such file or directory
cp: cannot stat ‘/c01/app/09/b9/016/500/000/098/system/output/*pdf’: No such file or directory

建议命令的输出:

[user@server payment]$ dirname $(grep <my search> /c01/app/09/*/*/*/*/*/system/output/*sup) | sort -u | head
.
/c01/app/09/ad/016/500/000/026/system/output
/c01/app/09/ad/016/500/000/086/system/output
/c01/app/09/ad/016/500/000/0a7/system/output
/c01/app/09/ad/016/500/000/112/system/output
/c01/app/09/ad/016/500/000/191/system/output
/c01/app/09/ae/016/500/000/030/system/output
/c01/app/09/ae/016/500/000/033/system/output
/c01/app/09/ae/016/500/000/036/system/output
/c01/app/09/ae/016/500/000/03b/system/output

答案1

您可以使用 shell 循环:

dirname $(grep -r <my search criteria> /c01/app/*sup) | 
    sort -u |
        while IFS= read -r dir; do
            cp -- "$dir"/*pdf /path/to/target/dir
        done

您也可以使用 执行此操作xargs,但由于xargs不调用 shell 而是调用您直接告诉它的任何实用程序,因此它不会扩展*pdf到文件列表。这意味着您需要使用 shell 显式调用它:

    dirname $(grep -r <my search criteria> /c01/app/*sup) | 
        sort -u |
            xargs -I {} sh -c "cp -- {}/*pdf /path/to/target/dir"

相关内容