How to capture disk usage percentage of a partition as an integer?











up vote
14
down vote

favorite












I would like a method to capture the disk usage of a particular partition, by using the directory where the partition is mounted. The output should just be an integer with no padding or following symbols, as I'd like to save it in a variable.



I've used df --output=pcent /mount/point, but need to trim the output as it has an unnecessary header, single space padding before the value, and a % symbol following the value like so:



Use%
83%


In this case the output I would like would simply be 83. I'm not aware of any drawbacks to using the output of df, but am happy to accept other methods that do not rely on it.










share|improve this question


















  • 1




    why not simply parse it?
    – Jacob Vlijm
    Nov 10 '16 at 11:20






  • 1




    I don't see a drawback either, you can remove the header with df then | tr -dc '0-9'
    – bc2946088
    Nov 10 '16 at 11:25












  • I stand corrected, I can't find the switch to remove the header from df.
    – bc2946088
    Nov 10 '16 at 11:32










  • I'd read the man page, and the info page and couldn't find it either @bc2946088, good shout to consider tr, I was getting my head in a mess with sed and awk ideas.
    – Arronical
    Nov 10 '16 at 11:34






  • 3




    I've searched for removing header option,too. Basically GNU developers are reluctant to impleme it. There have been feature requests, and they just said no.
    – Sergiy Kolodyazhnyy
    Nov 10 '16 at 11:49















up vote
14
down vote

favorite












I would like a method to capture the disk usage of a particular partition, by using the directory where the partition is mounted. The output should just be an integer with no padding or following symbols, as I'd like to save it in a variable.



I've used df --output=pcent /mount/point, but need to trim the output as it has an unnecessary header, single space padding before the value, and a % symbol following the value like so:



Use%
83%


In this case the output I would like would simply be 83. I'm not aware of any drawbacks to using the output of df, but am happy to accept other methods that do not rely on it.










share|improve this question


















  • 1




    why not simply parse it?
    – Jacob Vlijm
    Nov 10 '16 at 11:20






  • 1




    I don't see a drawback either, you can remove the header with df then | tr -dc '0-9'
    – bc2946088
    Nov 10 '16 at 11:25












  • I stand corrected, I can't find the switch to remove the header from df.
    – bc2946088
    Nov 10 '16 at 11:32










  • I'd read the man page, and the info page and couldn't find it either @bc2946088, good shout to consider tr, I was getting my head in a mess with sed and awk ideas.
    – Arronical
    Nov 10 '16 at 11:34






  • 3




    I've searched for removing header option,too. Basically GNU developers are reluctant to impleme it. There have been feature requests, and they just said no.
    – Sergiy Kolodyazhnyy
    Nov 10 '16 at 11:49













up vote
14
down vote

favorite









up vote
14
down vote

favorite











I would like a method to capture the disk usage of a particular partition, by using the directory where the partition is mounted. The output should just be an integer with no padding or following symbols, as I'd like to save it in a variable.



I've used df --output=pcent /mount/point, but need to trim the output as it has an unnecessary header, single space padding before the value, and a % symbol following the value like so:



Use%
83%


In this case the output I would like would simply be 83. I'm not aware of any drawbacks to using the output of df, but am happy to accept other methods that do not rely on it.










share|improve this question













I would like a method to capture the disk usage of a particular partition, by using the directory where the partition is mounted. The output should just be an integer with no padding or following symbols, as I'd like to save it in a variable.



I've used df --output=pcent /mount/point, but need to trim the output as it has an unnecessary header, single space padding before the value, and a % symbol following the value like so:



Use%
83%


In this case the output I would like would simply be 83. I'm not aware of any drawbacks to using the output of df, but am happy to accept other methods that do not rely on it.







command-line bash scripts disk-usage






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 10 '16 at 11:02









Arronical

13k84790




13k84790








  • 1




    why not simply parse it?
    – Jacob Vlijm
    Nov 10 '16 at 11:20






  • 1




    I don't see a drawback either, you can remove the header with df then | tr -dc '0-9'
    – bc2946088
    Nov 10 '16 at 11:25












  • I stand corrected, I can't find the switch to remove the header from df.
    – bc2946088
    Nov 10 '16 at 11:32










  • I'd read the man page, and the info page and couldn't find it either @bc2946088, good shout to consider tr, I was getting my head in a mess with sed and awk ideas.
    – Arronical
    Nov 10 '16 at 11:34






  • 3




    I've searched for removing header option,too. Basically GNU developers are reluctant to impleme it. There have been feature requests, and they just said no.
    – Sergiy Kolodyazhnyy
    Nov 10 '16 at 11:49














  • 1




    why not simply parse it?
    – Jacob Vlijm
    Nov 10 '16 at 11:20






  • 1




    I don't see a drawback either, you can remove the header with df then | tr -dc '0-9'
    – bc2946088
    Nov 10 '16 at 11:25












  • I stand corrected, I can't find the switch to remove the header from df.
    – bc2946088
    Nov 10 '16 at 11:32










  • I'd read the man page, and the info page and couldn't find it either @bc2946088, good shout to consider tr, I was getting my head in a mess with sed and awk ideas.
    – Arronical
    Nov 10 '16 at 11:34






  • 3




    I've searched for removing header option,too. Basically GNU developers are reluctant to impleme it. There have been feature requests, and they just said no.
    – Sergiy Kolodyazhnyy
    Nov 10 '16 at 11:49








1




1




why not simply parse it?
– Jacob Vlijm
Nov 10 '16 at 11:20




why not simply parse it?
– Jacob Vlijm
Nov 10 '16 at 11:20




1




1




I don't see a drawback either, you can remove the header with df then | tr -dc '0-9'
– bc2946088
Nov 10 '16 at 11:25






I don't see a drawback either, you can remove the header with df then | tr -dc '0-9'
– bc2946088
Nov 10 '16 at 11:25














I stand corrected, I can't find the switch to remove the header from df.
– bc2946088
Nov 10 '16 at 11:32




I stand corrected, I can't find the switch to remove the header from df.
– bc2946088
Nov 10 '16 at 11:32












I'd read the man page, and the info page and couldn't find it either @bc2946088, good shout to consider tr, I was getting my head in a mess with sed and awk ideas.
– Arronical
Nov 10 '16 at 11:34




I'd read the man page, and the info page and couldn't find it either @bc2946088, good shout to consider tr, I was getting my head in a mess with sed and awk ideas.
– Arronical
Nov 10 '16 at 11:34




3




3




I've searched for removing header option,too. Basically GNU developers are reluctant to impleme it. There have been feature requests, and they just said no.
– Sergiy Kolodyazhnyy
Nov 10 '16 at 11:49




I've searched for removing header option,too. Basically GNU developers are reluctant to impleme it. There have been feature requests, and they just said no.
– Sergiy Kolodyazhnyy
Nov 10 '16 at 11:49










6 Answers
6






active

oldest

votes

















up vote
19
down vote



accepted










I'd use...



df --output=pcent /mount/point | tr -dc '0-9'


Not sure if sed is faster, but I can't ever remember the sed values.






share|improve this answer



















  • 1




    Using time to test it comes out as being just as fast as sed.
    – Arronical
    Nov 10 '16 at 11:54






  • 4




    @Arronical unless your outputs are waaaaaaaaaaaay greater than 100%, I doubt you'd see much difference. :P
    – muru
    Nov 10 '16 at 12:15










  • @Arronical What muru said; invocation time is likely to dominate.
    – a CVn
    Nov 11 '16 at 13:23






  • 1




    In this instance, tr is easier to read than sed.
    – Paddy Landau
    Nov 15 '16 at 12:49


















up vote
9
down vote













Here's awk solution:



$ df --output=pcent /mnt/HDD | awk -F'%' 'NR==2{print $1}'   
37


Basically what happens here is that we treat '%' character as field separator ( column delimiter ), and print first column $1 only when number of records equals to two ( the NR==2 part )



If we wanted to use bash-only tools, we could do something like this:



bash-4.3$ df --output=pcent / | while IFS= read -r line; do 
> ((c++));
> [ $c -eq 2 ] && echo "${line%%*}" ;
> done
74


And for fun, alternative sed via capture group and -r for extended regex:



df --output=pcent | sed -nr '/[[:digit:]]/{s/[[:space:]]+([[:digit:]]+)%/1/;p}'





share|improve this answer






























    up vote
    7
    down vote













    sed solution



    df --output=pcent /mount/point | sed '1d;s/^ //;s/%//'




    • 1d delete the first line


    • ; to separate commands


    • s/^ // remove a space from the start of lines


    • s/%// remove % sign






    share|improve this answer






























      up vote
      7
      down vote













      You can pipe to a grep that just extracts digits:



      df --output=pcent /mount/point | grep -o '[0-9]*'


      See it live:



      $ echo "Use%
      > 83%" | grep -o '[0-9]*'
      83





      share|improve this answer




























        up vote
        1
        down vote













        Bash two-step solution



        Being somewhat of a bash (Borne Again SHell) fan the last year I thought I'd propose a solution using it.



        $ DF_PCT=$(df --output=pcent /mnt/d)
        $ echo ${DF_PCT//[!0-9]/}
        5



        • Line 1 captures df output to variable DF_PCT.

        • Line 2 strips everything that is not a digit in DF_PCT and displays it on screen.

        • Advantage over accepted answer is line feed after percentage (5 in this case) is generated.






        share|improve this answer




























          up vote
          0
          down vote













          I came upon a server where --output=pcent was not yet implemented, so I used the normal output, filtered by column, followed by the regex: df /mount/point | awk '{print $5}' | tr -dc '0-9'






          share|improve this answer





















            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "89"
            };
            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',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            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%2faskubuntu.com%2fquestions%2f847752%2fhow-to-capture-disk-usage-percentage-of-a-partition-as-an-integer%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            6 Answers
            6






            active

            oldest

            votes








            6 Answers
            6






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            19
            down vote



            accepted










            I'd use...



            df --output=pcent /mount/point | tr -dc '0-9'


            Not sure if sed is faster, but I can't ever remember the sed values.






            share|improve this answer



















            • 1




              Using time to test it comes out as being just as fast as sed.
              – Arronical
              Nov 10 '16 at 11:54






            • 4




              @Arronical unless your outputs are waaaaaaaaaaaay greater than 100%, I doubt you'd see much difference. :P
              – muru
              Nov 10 '16 at 12:15










            • @Arronical What muru said; invocation time is likely to dominate.
              – a CVn
              Nov 11 '16 at 13:23






            • 1




              In this instance, tr is easier to read than sed.
              – Paddy Landau
              Nov 15 '16 at 12:49















            up vote
            19
            down vote



            accepted










            I'd use...



            df --output=pcent /mount/point | tr -dc '0-9'


            Not sure if sed is faster, but I can't ever remember the sed values.






            share|improve this answer



















            • 1




              Using time to test it comes out as being just as fast as sed.
              – Arronical
              Nov 10 '16 at 11:54






            • 4




              @Arronical unless your outputs are waaaaaaaaaaaay greater than 100%, I doubt you'd see much difference. :P
              – muru
              Nov 10 '16 at 12:15










            • @Arronical What muru said; invocation time is likely to dominate.
              – a CVn
              Nov 11 '16 at 13:23






            • 1




              In this instance, tr is easier to read than sed.
              – Paddy Landau
              Nov 15 '16 at 12:49













            up vote
            19
            down vote



            accepted







            up vote
            19
            down vote



            accepted






            I'd use...



            df --output=pcent /mount/point | tr -dc '0-9'


            Not sure if sed is faster, but I can't ever remember the sed values.






            share|improve this answer














            I'd use...



            df --output=pcent /mount/point | tr -dc '0-9'


            Not sure if sed is faster, but I can't ever remember the sed values.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 10 '16 at 12:04









            muru

            135k20289492




            135k20289492










            answered Nov 10 '16 at 11:47









            bc2946088

            3,18021129




            3,18021129








            • 1




              Using time to test it comes out as being just as fast as sed.
              – Arronical
              Nov 10 '16 at 11:54






            • 4




              @Arronical unless your outputs are waaaaaaaaaaaay greater than 100%, I doubt you'd see much difference. :P
              – muru
              Nov 10 '16 at 12:15










            • @Arronical What muru said; invocation time is likely to dominate.
              – a CVn
              Nov 11 '16 at 13:23






            • 1




              In this instance, tr is easier to read than sed.
              – Paddy Landau
              Nov 15 '16 at 12:49














            • 1




              Using time to test it comes out as being just as fast as sed.
              – Arronical
              Nov 10 '16 at 11:54






            • 4




              @Arronical unless your outputs are waaaaaaaaaaaay greater than 100%, I doubt you'd see much difference. :P
              – muru
              Nov 10 '16 at 12:15










            • @Arronical What muru said; invocation time is likely to dominate.
              – a CVn
              Nov 11 '16 at 13:23






            • 1




              In this instance, tr is easier to read than sed.
              – Paddy Landau
              Nov 15 '16 at 12:49








            1




            1




            Using time to test it comes out as being just as fast as sed.
            – Arronical
            Nov 10 '16 at 11:54




            Using time to test it comes out as being just as fast as sed.
            – Arronical
            Nov 10 '16 at 11:54




            4




            4




            @Arronical unless your outputs are waaaaaaaaaaaay greater than 100%, I doubt you'd see much difference. :P
            – muru
            Nov 10 '16 at 12:15




            @Arronical unless your outputs are waaaaaaaaaaaay greater than 100%, I doubt you'd see much difference. :P
            – muru
            Nov 10 '16 at 12:15












            @Arronical What muru said; invocation time is likely to dominate.
            – a CVn
            Nov 11 '16 at 13:23




            @Arronical What muru said; invocation time is likely to dominate.
            – a CVn
            Nov 11 '16 at 13:23




            1




            1




            In this instance, tr is easier to read than sed.
            – Paddy Landau
            Nov 15 '16 at 12:49




            In this instance, tr is easier to read than sed.
            – Paddy Landau
            Nov 15 '16 at 12:49












            up vote
            9
            down vote













            Here's awk solution:



            $ df --output=pcent /mnt/HDD | awk -F'%' 'NR==2{print $1}'   
            37


            Basically what happens here is that we treat '%' character as field separator ( column delimiter ), and print first column $1 only when number of records equals to two ( the NR==2 part )



            If we wanted to use bash-only tools, we could do something like this:



            bash-4.3$ df --output=pcent / | while IFS= read -r line; do 
            > ((c++));
            > [ $c -eq 2 ] && echo "${line%%*}" ;
            > done
            74


            And for fun, alternative sed via capture group and -r for extended regex:



            df --output=pcent | sed -nr '/[[:digit:]]/{s/[[:space:]]+([[:digit:]]+)%/1/;p}'





            share|improve this answer



























              up vote
              9
              down vote













              Here's awk solution:



              $ df --output=pcent /mnt/HDD | awk -F'%' 'NR==2{print $1}'   
              37


              Basically what happens here is that we treat '%' character as field separator ( column delimiter ), and print first column $1 only when number of records equals to two ( the NR==2 part )



              If we wanted to use bash-only tools, we could do something like this:



              bash-4.3$ df --output=pcent / | while IFS= read -r line; do 
              > ((c++));
              > [ $c -eq 2 ] && echo "${line%%*}" ;
              > done
              74


              And for fun, alternative sed via capture group and -r for extended regex:



              df --output=pcent | sed -nr '/[[:digit:]]/{s/[[:space:]]+([[:digit:]]+)%/1/;p}'





              share|improve this answer

























                up vote
                9
                down vote










                up vote
                9
                down vote









                Here's awk solution:



                $ df --output=pcent /mnt/HDD | awk -F'%' 'NR==2{print $1}'   
                37


                Basically what happens here is that we treat '%' character as field separator ( column delimiter ), and print first column $1 only when number of records equals to two ( the NR==2 part )



                If we wanted to use bash-only tools, we could do something like this:



                bash-4.3$ df --output=pcent / | while IFS= read -r line; do 
                > ((c++));
                > [ $c -eq 2 ] && echo "${line%%*}" ;
                > done
                74


                And for fun, alternative sed via capture group and -r for extended regex:



                df --output=pcent | sed -nr '/[[:digit:]]/{s/[[:space:]]+([[:digit:]]+)%/1/;p}'





                share|improve this answer














                Here's awk solution:



                $ df --output=pcent /mnt/HDD | awk -F'%' 'NR==2{print $1}'   
                37


                Basically what happens here is that we treat '%' character as field separator ( column delimiter ), and print first column $1 only when number of records equals to two ( the NR==2 part )



                If we wanted to use bash-only tools, we could do something like this:



                bash-4.3$ df --output=pcent / | while IFS= read -r line; do 
                > ((c++));
                > [ $c -eq 2 ] && echo "${line%%*}" ;
                > done
                74


                And for fun, alternative sed via capture group and -r for extended regex:



                df --output=pcent | sed -nr '/[[:digit:]]/{s/[[:space:]]+([[:digit:]]+)%/1/;p}'






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Dec 5 at 19:18

























                answered Nov 10 '16 at 11:57









                Sergiy Kolodyazhnyy

                69k9143303




                69k9143303






















                    up vote
                    7
                    down vote













                    sed solution



                    df --output=pcent /mount/point | sed '1d;s/^ //;s/%//'




                    • 1d delete the first line


                    • ; to separate commands


                    • s/^ // remove a space from the start of lines


                    • s/%// remove % sign






                    share|improve this answer



























                      up vote
                      7
                      down vote













                      sed solution



                      df --output=pcent /mount/point | sed '1d;s/^ //;s/%//'




                      • 1d delete the first line


                      • ; to separate commands


                      • s/^ // remove a space from the start of lines


                      • s/%// remove % sign






                      share|improve this answer

























                        up vote
                        7
                        down vote










                        up vote
                        7
                        down vote









                        sed solution



                        df --output=pcent /mount/point | sed '1d;s/^ //;s/%//'




                        • 1d delete the first line


                        • ; to separate commands


                        • s/^ // remove a space from the start of lines


                        • s/%// remove % sign






                        share|improve this answer














                        sed solution



                        df --output=pcent /mount/point | sed '1d;s/^ //;s/%//'




                        • 1d delete the first line


                        • ; to separate commands


                        • s/^ // remove a space from the start of lines


                        • s/%// remove % sign







                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Nov 10 '16 at 12:04









                        muru

                        135k20289492




                        135k20289492










                        answered Nov 10 '16 at 11:33









                        Zanna

                        49.4k13128236




                        49.4k13128236






















                            up vote
                            7
                            down vote













                            You can pipe to a grep that just extracts digits:



                            df --output=pcent /mount/point | grep -o '[0-9]*'


                            See it live:



                            $ echo "Use%
                            > 83%" | grep -o '[0-9]*'
                            83





                            share|improve this answer

























                              up vote
                              7
                              down vote













                              You can pipe to a grep that just extracts digits:



                              df --output=pcent /mount/point | grep -o '[0-9]*'


                              See it live:



                              $ echo "Use%
                              > 83%" | grep -o '[0-9]*'
                              83





                              share|improve this answer























                                up vote
                                7
                                down vote










                                up vote
                                7
                                down vote









                                You can pipe to a grep that just extracts digits:



                                df --output=pcent /mount/point | grep -o '[0-9]*'


                                See it live:



                                $ echo "Use%
                                > 83%" | grep -o '[0-9]*'
                                83





                                share|improve this answer












                                You can pipe to a grep that just extracts digits:



                                df --output=pcent /mount/point | grep -o '[0-9]*'


                                See it live:



                                $ echo "Use%
                                > 83%" | grep -o '[0-9]*'
                                83






                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered Nov 11 '16 at 9:28









                                fedorqui

                                6,06611032




                                6,06611032






















                                    up vote
                                    1
                                    down vote













                                    Bash two-step solution



                                    Being somewhat of a bash (Borne Again SHell) fan the last year I thought I'd propose a solution using it.



                                    $ DF_PCT=$(df --output=pcent /mnt/d)
                                    $ echo ${DF_PCT//[!0-9]/}
                                    5



                                    • Line 1 captures df output to variable DF_PCT.

                                    • Line 2 strips everything that is not a digit in DF_PCT and displays it on screen.

                                    • Advantage over accepted answer is line feed after percentage (5 in this case) is generated.






                                    share|improve this answer

























                                      up vote
                                      1
                                      down vote













                                      Bash two-step solution



                                      Being somewhat of a bash (Borne Again SHell) fan the last year I thought I'd propose a solution using it.



                                      $ DF_PCT=$(df --output=pcent /mnt/d)
                                      $ echo ${DF_PCT//[!0-9]/}
                                      5



                                      • Line 1 captures df output to variable DF_PCT.

                                      • Line 2 strips everything that is not a digit in DF_PCT and displays it on screen.

                                      • Advantage over accepted answer is line feed after percentage (5 in this case) is generated.






                                      share|improve this answer























                                        up vote
                                        1
                                        down vote










                                        up vote
                                        1
                                        down vote









                                        Bash two-step solution



                                        Being somewhat of a bash (Borne Again SHell) fan the last year I thought I'd propose a solution using it.



                                        $ DF_PCT=$(df --output=pcent /mnt/d)
                                        $ echo ${DF_PCT//[!0-9]/}
                                        5



                                        • Line 1 captures df output to variable DF_PCT.

                                        • Line 2 strips everything that is not a digit in DF_PCT and displays it on screen.

                                        • Advantage over accepted answer is line feed after percentage (5 in this case) is generated.






                                        share|improve this answer












                                        Bash two-step solution



                                        Being somewhat of a bash (Borne Again SHell) fan the last year I thought I'd propose a solution using it.



                                        $ DF_PCT=$(df --output=pcent /mnt/d)
                                        $ echo ${DF_PCT//[!0-9]/}
                                        5



                                        • Line 1 captures df output to variable DF_PCT.

                                        • Line 2 strips everything that is not a digit in DF_PCT and displays it on screen.

                                        • Advantage over accepted answer is line feed after percentage (5 in this case) is generated.







                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered Dec 6 at 4:12









                                        WinEunuuchs2Unix

                                        41.5k1070158




                                        41.5k1070158






















                                            up vote
                                            0
                                            down vote













                                            I came upon a server where --output=pcent was not yet implemented, so I used the normal output, filtered by column, followed by the regex: df /mount/point | awk '{print $5}' | tr -dc '0-9'






                                            share|improve this answer

























                                              up vote
                                              0
                                              down vote













                                              I came upon a server where --output=pcent was not yet implemented, so I used the normal output, filtered by column, followed by the regex: df /mount/point | awk '{print $5}' | tr -dc '0-9'






                                              share|improve this answer























                                                up vote
                                                0
                                                down vote










                                                up vote
                                                0
                                                down vote









                                                I came upon a server where --output=pcent was not yet implemented, so I used the normal output, filtered by column, followed by the regex: df /mount/point | awk '{print $5}' | tr -dc '0-9'






                                                share|improve this answer












                                                I came upon a server where --output=pcent was not yet implemented, so I used the normal output, filtered by column, followed by the regex: df /mount/point | awk '{print $5}' | tr -dc '0-9'







                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered Jan 3 at 18:55









                                                Ramon Fincken

                                                11




                                                11






























                                                    draft saved

                                                    draft discarded




















































                                                    Thanks for contributing an answer to Ask Ubuntu!


                                                    • 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.





                                                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                                    Please pay close attention to the following guidance:


                                                    • 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%2faskubuntu.com%2fquestions%2f847752%2fhow-to-capture-disk-usage-percentage-of-a-partition-as-an-integer%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

                                                    flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

                                                    Mangá

                                                     ⁒  ․,‪⁊‑⁙ ⁖, ⁇‒※‌, †,⁖‗‌⁝    ‾‸⁘,‖⁔⁣,⁂‾
”‑,‥–,‬ ,⁀‹⁋‴⁑ ‒ ,‴⁋”‼ ⁨,‷⁔„ ‰′,‐‚ ‥‡‎“‷⁃⁨⁅⁣,⁔
⁇‘⁔⁡⁏⁌⁡‿‶‏⁨ ⁣⁕⁖⁨⁩⁥‽⁀  ‴‬⁜‟ ⁃‣‧⁕‮ …‍⁨‴ ⁩,⁚⁖‫ ,‵ ⁀,‮⁝‣‣ ⁑  ⁂– ․, ‾‽ ‏⁁“⁗‸ ‾… ‹‡⁌⁎‸‘ ‡⁏⁌‪ ‵⁛ ‎⁨ ―⁦⁤⁄⁕