디렉토리 목록 내의 모든 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
쉘 루프를 사용할 수 있습니다.
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"