Listing the content of a tar file or a directory only down to some level

前端 未结 5 1728
鱼传尺愫
鱼传尺愫 2020-12-12 15:38

I wonder how to list the content of a tar file only down to some level?

I understand tar tvf mytar.tar will list all files, but sometimes I would like

5条回答
  •  猫巷女王i
    2020-12-12 16:07

    It would be nice if we could tell the find command to look inside a tar file, but I doubt that is possible.

    I quick and ugly (and not foolproof) way would be to limit the number of directory separators, for example:

     $ tar tvf myfile.tar | grep -E '^[^/]*(/[^/]*){1,2}$'
    

    The 2 tells to display not more than 2 slashes (in my case one is already generated by the user/group separator), and hence, to display files at depth at most one. You might want to try with different numbers in place of the 2.

提交回复
热议问题