Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List the directories on depthlevel one in tar.gz

Tags:

linux

grep

find

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

Not \dir1\bla \dir1\bla2

like image 323
Skip Avatar asked May 31 '12 16:05

Skip


1 Answers

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

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/
like image 183
Shawn Chin Avatar answered Oct 22 '22 04:10

Shawn Chin