Determine the number of directories inside a tar file without extracting itSearch for a file inside a tar.gz file without extracting it and copy the result to another folderTransform a tar archive's paths without extracting itView a file in a tar archive without extracting itTar - Transform stdin without extractingTar: Extract only files (not sub-directories)Exclude some files when extracting with tarExtract specific directories with all subdirectories from a tar fileuntar file without subdirectories containing ittar doesn't find a file in an archive, depending on the command used to try to extract itIs there an efficient command for listing the header of a particular file in tar.bz2 without uncompressing/extracting?

Would a high gravity rocky planet be guaranteed to have an atmosphere?

How to be diplomatic in refusing to write code that breaches the privacy of our users

Method to test if a number is a perfect power?

Purchasing a ticket for someone else in another country?

How to run a prison with the smallest amount of guards?

Customer Requests (Sometimes) Drive Me Bonkers!

A Rare Riley Riddle

Integer addition + constant, is it a group?

Go Pregnant or Go Home

Why are there no referendums in the US?

Do sorcerers' Subtle Spells require a skill check to be unseen?

How to Reset Passwords on Multiple Websites Easily?

Failed to fetch jessie backports repository

Would this custom Sorcerer variant that can only learn any verbal-component-only spell be unbalanced?

How to pronounce the slash sign

Escape a backup date in a file name

Valid Badminton Score?

India just shot down a satellite from the ground. At what altitude range is the resulting debris field?

Why escape if the_content isnt?

Was Spock the First Vulcan in Starfleet?

I'm in charge of equipment buying but no one's ever happy with what I choose. How to fix this?

How do I find the solutions of the following equation?

Tiptoe or tiphoof? Adjusting words to better fit fantasy races

Unreliable Magic - Is it worth it?



Determine the number of directories inside a tar file without extracting it


Search for a file inside a tar.gz file without extracting it and copy the result to another folderTransform a tar archive's paths without extracting itView a file in a tar archive without extracting itTar - Transform stdin without extractingTar: Extract only files (not sub-directories)Exclude some files when extracting with tarExtract specific directories with all subdirectories from a tar fileuntar file without subdirectories containing ittar doesn't find a file in an archive, depending on the command used to try to extract itIs there an efficient command for listing the header of a particular file in tar.bz2 without uncompressing/extracting?













2















I need to count directories inside an archive file (e.g. tar.bz) without extracting the archive. Note that the archive is too big so that it will be hard to extract then count directories using ls | wc -l.










share|improve this question
























  • Top-level directories or including every subdirectory?

    – Jeff Schaller
    yesterday











  • I want to count top-level directories actually? But if you can give a hint on how to recursively count or specify a certain depth, it would be perfect.

    – Tung
    yesterday















2















I need to count directories inside an archive file (e.g. tar.bz) without extracting the archive. Note that the archive is too big so that it will be hard to extract then count directories using ls | wc -l.










share|improve this question
























  • Top-level directories or including every subdirectory?

    – Jeff Schaller
    yesterday











  • I want to count top-level directories actually? But if you can give a hint on how to recursively count or specify a certain depth, it would be perfect.

    – Tung
    yesterday













2












2








2








I need to count directories inside an archive file (e.g. tar.bz) without extracting the archive. Note that the archive is too big so that it will be hard to extract then count directories using ls | wc -l.










share|improve this question
















I need to count directories inside an archive file (e.g. tar.bz) without extracting the archive. Note that the archive is too big so that it will be hard to extract then count directories using ls | wc -l.







directory tar archive wc






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday









Jeff Schaller

44k1161142




44k1161142










asked yesterday









TungTung

1334




1334












  • Top-level directories or including every subdirectory?

    – Jeff Schaller
    yesterday











  • I want to count top-level directories actually? But if you can give a hint on how to recursively count or specify a certain depth, it would be perfect.

    – Tung
    yesterday

















  • Top-level directories or including every subdirectory?

    – Jeff Schaller
    yesterday











  • I want to count top-level directories actually? But if you can give a hint on how to recursively count or specify a certain depth, it would be perfect.

    – Tung
    yesterday
















Top-level directories or including every subdirectory?

– Jeff Schaller
yesterday





Top-level directories or including every subdirectory?

– Jeff Schaller
yesterday













I want to count top-level directories actually? But if you can give a hint on how to recursively count or specify a certain depth, it would be perfect.

– Tung
yesterday





I want to count top-level directories actually? But if you can give a hint on how to recursively count or specify a certain depth, it would be perfect.

– Tung
yesterday










1 Answer
1






active

oldest

votes


















3














This should list all the files from the archive, then find the lines ending with / (folders) and then take the line count of it:



tar -tvf file.tar | grep '/$' | wc -l



edit: if you want to only count the top level dirs:



tar --exclude='./*/*' -tvf file.tar | grep '/$' | wc -l



If you want to go recursively one level deeper:



tar --exclude='./*/*/*' -tvf file.tar | grep '/$' | wc -l



and so on...






share|improve this answer
























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f508711%2fdetermine-the-number-of-directories-inside-a-tar-file-without-extracting-it%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    This should list all the files from the archive, then find the lines ending with / (folders) and then take the line count of it:



    tar -tvf file.tar | grep '/$' | wc -l



    edit: if you want to only count the top level dirs:



    tar --exclude='./*/*' -tvf file.tar | grep '/$' | wc -l



    If you want to go recursively one level deeper:



    tar --exclude='./*/*/*' -tvf file.tar | grep '/$' | wc -l



    and so on...






    share|improve this answer





























      3














      This should list all the files from the archive, then find the lines ending with / (folders) and then take the line count of it:



      tar -tvf file.tar | grep '/$' | wc -l



      edit: if you want to only count the top level dirs:



      tar --exclude='./*/*' -tvf file.tar | grep '/$' | wc -l



      If you want to go recursively one level deeper:



      tar --exclude='./*/*/*' -tvf file.tar | grep '/$' | wc -l



      and so on...






      share|improve this answer



























        3












        3








        3







        This should list all the files from the archive, then find the lines ending with / (folders) and then take the line count of it:



        tar -tvf file.tar | grep '/$' | wc -l



        edit: if you want to only count the top level dirs:



        tar --exclude='./*/*' -tvf file.tar | grep '/$' | wc -l



        If you want to go recursively one level deeper:



        tar --exclude='./*/*/*' -tvf file.tar | grep '/$' | wc -l



        and so on...






        share|improve this answer















        This should list all the files from the archive, then find the lines ending with / (folders) and then take the line count of it:



        tar -tvf file.tar | grep '/$' | wc -l



        edit: if you want to only count the top level dirs:



        tar --exclude='./*/*' -tvf file.tar | grep '/$' | wc -l



        If you want to go recursively one level deeper:



        tar --exclude='./*/*/*' -tvf file.tar | grep '/$' | wc -l



        and so on...







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited yesterday

























        answered yesterday









        Jussi HietanenJussi Hietanen

        725




        725



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f508711%2fdetermine-the-number-of-directories-inside-a-tar-file-without-extracting-it%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            getting Checkpoint VPN SSL Network Extender working in the command lineHow to connect to CheckPoint VPN on Ubuntu 18.04LTS?Will the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayVPN SSL Network Extender in FirefoxLinux Checkpoint SNX tool configuration issuesCheck Point - Connect under Linux - snx + OTPSNX VPN Ububuntu 18.XXUsing Checkpoint VPN SSL Network Extender CLI with certificateVPN with network manager (nm-applet) is not workingWill the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayImport VPN config files to NetworkManager from command lineTrouble connecting to VPN using network-manager, while command line worksStart a VPN connection with PPTP protocol on command linestarting a docker service daemon breaks the vpn networkCan't connect to vpn with Network-managerVPN SSL Network Extender in FirefoxUsing Checkpoint VPN SSL Network Extender CLI with certificate

            Cannot Extend partition with GParted The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election ResultsCan't increase partition size with GParted?GParted doesn't recognize the unallocated space after my current partitionWhat is the best way to add unallocated space located before to Ubuntu 12.04 partition with GParted live?I can't figure out how to extend my Arch home partition into free spaceGparted Linux Mint 18.1 issueTrying to extend but swap partition is showing as Unknown in Gparted, shows proper from fdiskRearrange partitions in gparted to extend a partitionUnable to extend partition even though unallocated space is next to it using GPartedAllocate free space to root partitiongparted: how to merge unallocated space with a partition

            Marilyn Monroe Ny fiainany manokana | Jereo koa | Meny fitetezanafanitarana azy.