Я пытаюсь скопировать все PDF-файлы из списка каталогов в свой временный каталог. У меня есть эта команда, чтобы получить список соответствующих каталогов:
dirname $(grep -r <my search criteria> /c01/app/*sup) | sort -u
Это просматривает все .sup
файлы по моим критериям поиска. В этих каталогах находятся PDF-файлы, которые я хочу скопировать.
EDIT: При запуске обновленной команды:
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
Вы можете использовать цикл оболочки:
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
не вызывает оболочку, а вместо этого вызывает любые утилиты, которые вы ему напрямую указываете, он не будет расширяться *pdf
до списка файлов. Это означает, что вам нужно будет вызвать его с помощью оболочки явно:
dirname $(grep -r <my search criteria> /c01/app/*sup) |
sort -u |
xargs -I {} sh -c "cp -- {}/*pdf /path/to/target/dir"