stdin에서 tar를 어떻게 만들 수 있습니까?
tar파일 이름 을 지정하도록 정보를 파이프하려면 어떻게 해야합니까?
다음과 같은 것 :
tar cfz foo.tgz -T -
그러나 이것이 가능한 모든 파일 이름에 대해 작동하는 것은 아닙니다. 에서 --null옵션과 피드 tar를 고려해야합니다 find -print0. (이 xargs예제는 여러 tar명령 을 생성하기 때문에 큰 파일 목록에서는 제대로 작동하지 않습니다 .)
geekosaur 이미 지적한 바와 같이, 파이프 필요의 출력이없는 find행 xargs은 파이프의 출력 가능하기 때문에 find직접 tar사용이 find ... -print0 | tar --null ....
사이에 약간의 차이가 유의 gnutar하고 bsdtar있지만 아카이브 파일을 제외에 있습니다.
# exclude file.tar.gz anywhere in the directory tree to be tar'ed and compressed
find . -print0 | gnutar --null --exclude="file.tar.gz" --no-recursion -czf file.tar.gz --files-from -
find . -print0 | bsdtar --null --exclude="file.tar.gz" -n -czf file.tar.gz -T -
# bsdtar excludes ./file.tar.gz in current directory by default
# further file.tar.gz files in subdirectories will get included though
# bsdtar: ./file.tar.gz: Can't add archive to itself
find . -print0 | bsdtar --null -n -czf file.tar.gz -T -
# gnutar does not exclude ./file.tar.gz in current directory by default
find . -print0 | gnutar --null --no-recursion -czf file.tar.gz --files-from -
Geekosaur 답변 확장 :
find /directory | tar -cf archive.tar -T -
-T옵션 과 함께 stdin을 사용할 수 있습니다 .
-name일반적으로 일부 조건 (예 : 옵션)을 사용하여 파일을 필터링하는 경우 파이프에서 디렉토리 를 제외 해야합니다 . 그렇지 않으면 tar가 모든 콘텐츠를 처리하므로 원하는 것이 아닙니다. 따라서 다음을 사용하십시오.
find /directory -type f -name "mypattern" | tar -cf archive.tar -T -
을 사용하지 않으면 -type일치하는 디렉토리의 모든 내용 "mypattern"이 추가됩니다!
파이프를 사용하는 대신 백틱을 사용할 수 있습니다. 예 :
tar cvzf archive.tgz `ls -1 *`
대신 ls -1 *파일을 아카이브하는 데 필요한 목록을 생성하는 다른 명령을 넣을 수 있습니다.
find /directory > filename
tar -T filename -cf archive.tar
이 tar프로그램은 다양한 방식으로 구현되었습니다. 예를 들어, 유닉스, IBM의 버전에 AIX , tar용도 -L옵션을하기보다는 -T, 오히려 허용하는 것보다 파일이 필요합니다 -표준 입력을 나타냅니다 :
Usage: tar -{c|r|t|u|x} [ -BdDEFhilmopRUsvwZ ] [ -Number ] [ -f TarFil e ]
[ -b Blocks ] [ -S [ Feet ] | [ Feet@Density ] | [ Blocksb ] ]
[ -L InputList ] [-X ExcludeFile] [ -N Blocks ] [ -C Directory ] File ...
Usage: tar {c|r|t|u|x} [ bBdDEfFhilLXmNopRsSUvwZ[0-9] ] ]
[ Blocks ] [ TarFile ] [ InputList ] [ ExcludeFile ]
[ [ Feet ] | [ Feet@Density ] | [ Blocksb ] ] [-C Directory ] File ...
참고 URL : https://stackoverflow.com/questions/2597875/how-can-i-build-a-tar-from-stdin
'IT TIP' 카테고리의 다른 글
| npm 오류! (0) | 2020.11.26 |
|---|---|
| 원본 어셈블리를 신뢰할 수 없기 때문에 MSTest 실행이 실패합니다. (0) | 2020.11.26 |
| Android에서 HTML 엔티티 디코딩 (0) | 2020.11.26 |
| 버전 11의 localdb에 대한 연결 문자열은 무엇입니까? (0) | 2020.11.26 |
| 자바 스크립트에서 float를 다음 정수로 반올림 (0) | 2020.11.26 |