Linux 列出 tar.gz 中深度一级的目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10837287/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 06:36:04  来源:igfitidea点击:

List the directories on depthlevel one in tar.gz

linuxfindgrep

提问by Skip

How can the directories on the level one can be listed in a tar.gz archive? E.g. \dir1\ \dir2\ \dir3\ \dir4\ \dir1\

如何在 tar.gz 存档中列出一级目录?例如 \dir1\ \dir2\ \dir3\ \dir4\ \dir1\

Not \dir1\bla \dir1\bla2

不是 \dir1\bla \dir1\bla2

采纳答案by Shawn Chin

You can use the --excludeoption to exclude everything that's within a directory.

您可以使用该--exclude选项排除目录中的所有内容。

tar tfz archive.tar.gz --exclude '*/*'

Example:

例子:

[me@home]$ tar tfj CUnit-2.1-2-src.tar.bz2 | head -n5
CUnit-2.1-2/
CUnit-2.1-2/NEWS
CUnit-2.1-2/Makefile.am
CUnit-2.1-2/configure
CUnit-2.1-2/cunit.pc.in

[me@home]$ tar tfj CUnit-2.1-2-src.tar.bz2 --exclude '*/*'
CUnit-2.1-2/