bash HP-UX - 如何在不解压的情况下从 tar 存档中读取文本文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12802695/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
HP-UX - How can I read a text file from tar archive without extracting it?
提问by Maxbester
I have a tararchive which contains several text files. I would like to write a script to display (stdout) the content of a file without extracting it to the current directory.
我有一个tar包含多个文本文件的存档。我想编写一个脚本来显示(stdout)文件的内容而不将其解压缩到当前目录。
Actually I would like to do the same as:
其实我想做同样的事情:
tar tf myArchive.tar folder/someFile.txt
cat folder/someFile.txt
rm -R folder
but without the rm...
但没有rm...
I tried this way but it didn't work:
我试过这种方式,但没有用:
tar tf myArchive.tar folder/someFile.txt | cat
Thanks
谢谢
回答by Didier Trosset
Use xto extract, with ffrom archive file. Then add also option -Oto direct extracted files to standard output.
用于从存档文件中x提取f。然后添加选项-O以将提取的文件定向到标准输出。
tar xf myArchive.tar folder/someFile.txt -O

