Print percentage (%) of files used by a command

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












0















I'm building docker images to be used in CI/CD pipelines by other developers. After the image build is complete, I run a few commands to do some test coverage. I'm curious if there's a Linux command that will print out the percentage of files access by a command (or series of commands).



Example:



# ls -l /var/opt | how-many-files-were-used-on-the-os
> 4%


Obviously, this doesn't work so well on a system that is in a constant running state, but I believe this could really help in containers where a minimal number of commands are running










share|improve this question



















  • 1





    unix.stackexchange.com/q/58887/255251

    – P_Yadav
    Jan 9 at 16:25















0















I'm building docker images to be used in CI/CD pipelines by other developers. After the image build is complete, I run a few commands to do some test coverage. I'm curious if there's a Linux command that will print out the percentage of files access by a command (or series of commands).



Example:



# ls -l /var/opt | how-many-files-were-used-on-the-os
> 4%


Obviously, this doesn't work so well on a system that is in a constant running state, but I believe this could really help in containers where a minimal number of commands are running










share|improve this question



















  • 1





    unix.stackexchange.com/q/58887/255251

    – P_Yadav
    Jan 9 at 16:25













0












0








0








I'm building docker images to be used in CI/CD pipelines by other developers. After the image build is complete, I run a few commands to do some test coverage. I'm curious if there's a Linux command that will print out the percentage of files access by a command (or series of commands).



Example:



# ls -l /var/opt | how-many-files-were-used-on-the-os
> 4%


Obviously, this doesn't work so well on a system that is in a constant running state, but I believe this could really help in containers where a minimal number of commands are running










share|improve this question
















I'm building docker images to be used in CI/CD pipelines by other developers. After the image build is complete, I run a few commands to do some test coverage. I'm curious if there's a Linux command that will print out the percentage of files access by a command (or series of commands).



Example:



# ls -l /var/opt | how-many-files-were-used-on-the-os
> 4%


Obviously, this doesn't work so well on a system that is in a constant running state, but I believe this could really help in containers where a minimal number of commands are running







linux docker command






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 9 at 21:48







Rakaim

















asked Jan 9 at 16:03









RakaimRakaim

1467




1467







  • 1





    unix.stackexchange.com/q/58887/255251

    – P_Yadav
    Jan 9 at 16:25












  • 1





    unix.stackexchange.com/q/58887/255251

    – P_Yadav
    Jan 9 at 16:25







1




1





unix.stackexchange.com/q/58887/255251

– P_Yadav
Jan 9 at 16:25





unix.stackexchange.com/q/58887/255251

– P_Yadav
Jan 9 at 16:25










1 Answer
1






active

oldest

votes


















0














This looks like something that could use work. I can only give you a start of an answer:



strace -f -v ls -l /var/opt 2>&1 > /dev/null | perl -ne '/(access|open(?:at)?|statfs|lgetxattr|lstat)(.*?"([^"]+)"/ && !$file$2++ && print "$2n"'


will show you a bunch of filenames accessed. However, that's a woefully incomplete answer; there are over 400 system calls on Linux, and while probably most of them don't access files, there's a lot more than just those few. It's also likely that some of them will require a different pattern to get the file that they access; that regex just looks for the first double-quoted string on the line, and probably some of them have their filename listed at a different point on the line. (If I have it grab the last double-quoted string on the line, it'll grab the selinux contexts as well, which is not what you want.)



Once you have something that returns all of the files accessed, you can then compare that with what you know to be the count of the files in the docker image. (Or you could run something like 'find / -xdev -print|wc' to get it. Note that if you have your docker image mounting things to other places than just /, you would need to list each of those for find to search, since I used -xdev to filter out everything like /proc and /dev that you don't want because they're not real files.)






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%2f493491%2fprint-percentage-of-files-used-by-a-command%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









    0














    This looks like something that could use work. I can only give you a start of an answer:



    strace -f -v ls -l /var/opt 2>&1 > /dev/null | perl -ne '/(access|open(?:at)?|statfs|lgetxattr|lstat)(.*?"([^"]+)"/ && !$file$2++ && print "$2n"'


    will show you a bunch of filenames accessed. However, that's a woefully incomplete answer; there are over 400 system calls on Linux, and while probably most of them don't access files, there's a lot more than just those few. It's also likely that some of them will require a different pattern to get the file that they access; that regex just looks for the first double-quoted string on the line, and probably some of them have their filename listed at a different point on the line. (If I have it grab the last double-quoted string on the line, it'll grab the selinux contexts as well, which is not what you want.)



    Once you have something that returns all of the files accessed, you can then compare that with what you know to be the count of the files in the docker image. (Or you could run something like 'find / -xdev -print|wc' to get it. Note that if you have your docker image mounting things to other places than just /, you would need to list each of those for find to search, since I used -xdev to filter out everything like /proc and /dev that you don't want because they're not real files.)






    share|improve this answer



























      0














      This looks like something that could use work. I can only give you a start of an answer:



      strace -f -v ls -l /var/opt 2>&1 > /dev/null | perl -ne '/(access|open(?:at)?|statfs|lgetxattr|lstat)(.*?"([^"]+)"/ && !$file$2++ && print "$2n"'


      will show you a bunch of filenames accessed. However, that's a woefully incomplete answer; there are over 400 system calls on Linux, and while probably most of them don't access files, there's a lot more than just those few. It's also likely that some of them will require a different pattern to get the file that they access; that regex just looks for the first double-quoted string on the line, and probably some of them have their filename listed at a different point on the line. (If I have it grab the last double-quoted string on the line, it'll grab the selinux contexts as well, which is not what you want.)



      Once you have something that returns all of the files accessed, you can then compare that with what you know to be the count of the files in the docker image. (Or you could run something like 'find / -xdev -print|wc' to get it. Note that if you have your docker image mounting things to other places than just /, you would need to list each of those for find to search, since I used -xdev to filter out everything like /proc and /dev that you don't want because they're not real files.)






      share|improve this answer

























        0












        0








        0







        This looks like something that could use work. I can only give you a start of an answer:



        strace -f -v ls -l /var/opt 2>&1 > /dev/null | perl -ne '/(access|open(?:at)?|statfs|lgetxattr|lstat)(.*?"([^"]+)"/ && !$file$2++ && print "$2n"'


        will show you a bunch of filenames accessed. However, that's a woefully incomplete answer; there are over 400 system calls on Linux, and while probably most of them don't access files, there's a lot more than just those few. It's also likely that some of them will require a different pattern to get the file that they access; that regex just looks for the first double-quoted string on the line, and probably some of them have their filename listed at a different point on the line. (If I have it grab the last double-quoted string on the line, it'll grab the selinux contexts as well, which is not what you want.)



        Once you have something that returns all of the files accessed, you can then compare that with what you know to be the count of the files in the docker image. (Or you could run something like 'find / -xdev -print|wc' to get it. Note that if you have your docker image mounting things to other places than just /, you would need to list each of those for find to search, since I used -xdev to filter out everything like /proc and /dev that you don't want because they're not real files.)






        share|improve this answer













        This looks like something that could use work. I can only give you a start of an answer:



        strace -f -v ls -l /var/opt 2>&1 > /dev/null | perl -ne '/(access|open(?:at)?|statfs|lgetxattr|lstat)(.*?"([^"]+)"/ && !$file$2++ && print "$2n"'


        will show you a bunch of filenames accessed. However, that's a woefully incomplete answer; there are over 400 system calls on Linux, and while probably most of them don't access files, there's a lot more than just those few. It's also likely that some of them will require a different pattern to get the file that they access; that regex just looks for the first double-quoted string on the line, and probably some of them have their filename listed at a different point on the line. (If I have it grab the last double-quoted string on the line, it'll grab the selinux contexts as well, which is not what you want.)



        Once you have something that returns all of the files accessed, you can then compare that with what you know to be the count of the files in the docker image. (Or you could run something like 'find / -xdev -print|wc' to get it. Note that if you have your docker image mounting things to other places than just /, you would need to list each of those for find to search, since I used -xdev to filter out everything like /proc and /dev that you don't want because they're not real files.)







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 10 at 4:05









        Ed GrimmEd Grimm

        1635




        1635



























            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%2f493491%2fprint-percentage-of-files-used-by-a-command%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

            How to check contact read email or not when send email to Individual?

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?