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

前端 未结 5 1729
鱼传尺愫
鱼传尺愫 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条回答
  •  一个人的身影
    2020-12-12 16:19

    I agree with leonbloy's answer - there's no way to do this straightforwardly within the tarball itself.

    Regarding the second part of your question, ls does not have a max depth option. You can recurse everything with ls -R, but that's often not very useful.

    However you can do this with both find and tree. For example to list files and directories one level deep, you can do

    find -maxdepth 2
    

    or

    tree -L 2
    

    tree also has a -d option, which recursively lists directories, but not files, which I find much more useful than -L, in general.

提交回复
热议问题