除了使用tar tf
以外,是否有更有效的方法來執行此操作,並根據所查找的文件檢查每個文件的輸出?找到一個文件是否存在於一些gzipped tarballs中的最快方法?
這是我做的,現在的方式,但它的速度很慢(大約有600-1000檔案是符合search_patterns
):
ARRAY=()
ARRAY[0]=/path/to/archives/*search_pattern1*
ARRAY[1]=/path/to/archives/*search_pattern2*
ARRAY[2]=/path/to/archives/*search_pattern3*
for f in ${ARRAY[@]}
do
if [[ $f =~ "matching_pattern1" ]]; then
if tar -tf "$f" | grep "matching_pattern2" ; then
printf "%s\n" $f;
exit 0;
fi
fi
done
對於它的價值,我search_patterns
是連續3天,我希望首先找到與matching_pattern1
匹配的檔案,然後查看所有這些檔案的matching_pattern2
並輸出包含它的tar
文件。
你有一個文本文件名稱或文件glob(用於tarball中的文件)? – 2014-10-28 17:43:08
你可能最好不要將globes粘在單個數組索引上,而是讓globs直接填充數組索引。 'arr =(/ path/to/archives/* search_pattern1 */path/to/archives/* search_pattern2 */path/to/archives/* search_pattern3 *)''。 – 2014-10-28 17:47:33
@EtanReisner它也是一個glob – confused00 2014-10-28 17:47:52