[英]Grep Pattern From TAR Output
===UPDATE=== ===更新===
@Cyrus answer was the one that worked, but, this led to another issue that's related that I missed. @Cyrus的答案是可行的,但是,这导致了我错过的另一个相关问题。
There are some folders with folders within folders, so httpdocs/<folder1>/<folder2>/<etc>/index.php
and so the '*' is picking them up too. 文件夹中有一些文件夹,其中有一些文件夹,因此
httpdocs/<folder1>/<folder2>/<etc>/index.php
,因此'*'也将它们拾取。
Really all I want is to match the pattern httpdocs/<folder>/index.php
我真正想要的就是匹配模式
httpdocs/<folder>/index.php
I'm rubbish with RegEx so unsure of what I could put. 我对RegEx感到不满,所以不确定我可以放什么。 Any ideas?
有任何想法吗?
I have a 25GB tar.gz
file, and from this I want to extract certain files. 我有一个25GB的
tar.gz
文件,因此我要提取某些文件。 The file location is: 文件位置是:
httpdocs/<account>/index.php
The <account>
just means that it's just a name - not overly important. <account>
只是意味着它只是一个名称-不太重要。
There's around 70+ of these index.php
files in this exact format, and I need to extract only them files from the TAR. 这些
index.php
文件大约有70多种以这种精确格式存在,我只需要从TAR中提取它们即可。
I can do it per individual file, like so ( tar -xf site_support_server.com_user-data_1509221232.tgz httpdocs/hotel/index.php
) but as I say their's around 70 of these and I don't want to go through it 1 by 1. 我可以按单个文件来执行此操作,就像这样(
tar -xf site_support_server.com_user-data_1509221232.tgz httpdocs/hotel/index.php
),但是正如我所说的那样,它们大约有70个,我不想通过它1。
I thought maybe tar -xf site_support_server.com_user-data_1509221232.tgz httpdocs/*/index.php
would work, but I don't think it recognizes the '*' as a wildcard. 我认为
tar -xf site_support_server.com_user-data_1509221232.tgz httpdocs/*/index.php
可以工作,但我认为它不会将'*'识别为通配符。
Am I missing something or does anybody else have any suggestions on how to quickly do this? 我是否缺少某些东西,或者其他人对如何快速执行此操作有任何建议吗?
Many thanks! 非常感谢!
With GNU tar: 使用GNU tar:
tar -xvzf your_file.tgz --wildcards "*/index.php"
Update 更新资料
tar -tvzf your_file.tgz --wildcards "httpdocs/*/index.php" --exclude="httpdocs/*/*/index.php"
You can list multiple archive members in one command. 您可以在一个命令中列出多个归档成员。 That means you can do:
这意味着您可以:
tar -tf some.tar.gz | grep '/index.php$' | xargs tar -xf some.tar.gz
Watch out for spaces in the paths though - maybe you need to replace newlines with null bytes and use xargs -0
但是请注意路径中的空格-也许您需要用空字节替换换行符并使用
xargs -0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.