“df -h” command puts line breaks in output. How do I fix?











up vote
13
down vote

favorite
3












My "df -h" command on my Linux box has some devices with longer names and so the "df -h" output has line breaks (or tabs??) in it, which makes it difficult to parse the output in a script.



Does anyone know how I can suppress the linebreaks so that the latter of the following outputs is what I get:



[root@me ~]# df -kh
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
3.9G 404M 3.3G 11% /
/dev/mapper/VolGroup00-LogVol05
3.9G 442M 3.3G 12% /home
/dev/mapper/VolGroup00-LogVol04
3.9G 261M 3.5G 7% /var
/dev/mapper/VolGroup00-LogVol03
3.9G 137M 3.6G 4% /tmp
/dev/mapper/VolGroup00-LogVol02
7.8G 3.6G 3.8G 49% /usr


And the desired format is:



[root@me ~]# df -kh
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00 3.9G 404M 3.3G 11% /
/dev/mapper/VolGroup00-LogVol05 3.9G 442M 3.3G 12% /home
/dev/mapper/VolGroup00-LogVol04 3.9G 261M 3.5G 7% /var
/dev/mapper/VolGroup00-LogVol03 3.9G 137M 3.6G 4% /tmp
/dev/mapper/VolGroup00-LogVol02 7.8G 3.6G 3.8G 49% /usr









share|improve this question




















  • 1




    I can't test this because my drive paths aren't huge like yours. Try df -Pkh
    – user606723
    Aug 3 '11 at 19:48








  • 1




    @user606723: why do not put it in an answer?
    – enzotib
    Aug 3 '11 at 19:51










  • I did just now. =p. I didn't put it in an answer at first because it was a blatant guess from looking at the man file for two seconds.
    – user606723
    Aug 3 '11 at 19:53








  • 1




    The use of -h and -k together is pointless as they contradict each other and the last one given "wins" (i.e. df -hk gives 1024 blocks output while df -kh gives human readable output).
    – PerlDuck
    Nov 27 at 14:13















up vote
13
down vote

favorite
3












My "df -h" command on my Linux box has some devices with longer names and so the "df -h" output has line breaks (or tabs??) in it, which makes it difficult to parse the output in a script.



Does anyone know how I can suppress the linebreaks so that the latter of the following outputs is what I get:



[root@me ~]# df -kh
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
3.9G 404M 3.3G 11% /
/dev/mapper/VolGroup00-LogVol05
3.9G 442M 3.3G 12% /home
/dev/mapper/VolGroup00-LogVol04
3.9G 261M 3.5G 7% /var
/dev/mapper/VolGroup00-LogVol03
3.9G 137M 3.6G 4% /tmp
/dev/mapper/VolGroup00-LogVol02
7.8G 3.6G 3.8G 49% /usr


And the desired format is:



[root@me ~]# df -kh
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00 3.9G 404M 3.3G 11% /
/dev/mapper/VolGroup00-LogVol05 3.9G 442M 3.3G 12% /home
/dev/mapper/VolGroup00-LogVol04 3.9G 261M 3.5G 7% /var
/dev/mapper/VolGroup00-LogVol03 3.9G 137M 3.6G 4% /tmp
/dev/mapper/VolGroup00-LogVol02 7.8G 3.6G 3.8G 49% /usr









share|improve this question




















  • 1




    I can't test this because my drive paths aren't huge like yours. Try df -Pkh
    – user606723
    Aug 3 '11 at 19:48








  • 1




    @user606723: why do not put it in an answer?
    – enzotib
    Aug 3 '11 at 19:51










  • I did just now. =p. I didn't put it in an answer at first because it was a blatant guess from looking at the man file for two seconds.
    – user606723
    Aug 3 '11 at 19:53








  • 1




    The use of -h and -k together is pointless as they contradict each other and the last one given "wins" (i.e. df -hk gives 1024 blocks output while df -kh gives human readable output).
    – PerlDuck
    Nov 27 at 14:13













up vote
13
down vote

favorite
3









up vote
13
down vote

favorite
3






3





My "df -h" command on my Linux box has some devices with longer names and so the "df -h" output has line breaks (or tabs??) in it, which makes it difficult to parse the output in a script.



Does anyone know how I can suppress the linebreaks so that the latter of the following outputs is what I get:



[root@me ~]# df -kh
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
3.9G 404M 3.3G 11% /
/dev/mapper/VolGroup00-LogVol05
3.9G 442M 3.3G 12% /home
/dev/mapper/VolGroup00-LogVol04
3.9G 261M 3.5G 7% /var
/dev/mapper/VolGroup00-LogVol03
3.9G 137M 3.6G 4% /tmp
/dev/mapper/VolGroup00-LogVol02
7.8G 3.6G 3.8G 49% /usr


And the desired format is:



[root@me ~]# df -kh
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00 3.9G 404M 3.3G 11% /
/dev/mapper/VolGroup00-LogVol05 3.9G 442M 3.3G 12% /home
/dev/mapper/VolGroup00-LogVol04 3.9G 261M 3.5G 7% /var
/dev/mapper/VolGroup00-LogVol03 3.9G 137M 3.6G 4% /tmp
/dev/mapper/VolGroup00-LogVol02 7.8G 3.6G 3.8G 49% /usr









share|improve this question















My "df -h" command on my Linux box has some devices with longer names and so the "df -h" output has line breaks (or tabs??) in it, which makes it difficult to parse the output in a script.



Does anyone know how I can suppress the linebreaks so that the latter of the following outputs is what I get:



[root@me ~]# df -kh
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
3.9G 404M 3.3G 11% /
/dev/mapper/VolGroup00-LogVol05
3.9G 442M 3.3G 12% /home
/dev/mapper/VolGroup00-LogVol04
3.9G 261M 3.5G 7% /var
/dev/mapper/VolGroup00-LogVol03
3.9G 137M 3.6G 4% /tmp
/dev/mapper/VolGroup00-LogVol02
7.8G 3.6G 3.8G 49% /usr


And the desired format is:



[root@me ~]# df -kh
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00 3.9G 404M 3.3G 11% /
/dev/mapper/VolGroup00-LogVol05 3.9G 442M 3.3G 12% /home
/dev/mapper/VolGroup00-LogVol04 3.9G 261M 3.5G 7% /var
/dev/mapper/VolGroup00-LogVol03 3.9G 137M 3.6G 4% /tmp
/dev/mapper/VolGroup00-LogVol02 7.8G 3.6G 3.8G 49% /usr






disk fstab disk-usage disk-management






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 3 '11 at 20:02









user606723

1,6811014




1,6811014










asked Aug 3 '11 at 19:44









djangofan

1,58121727




1,58121727








  • 1




    I can't test this because my drive paths aren't huge like yours. Try df -Pkh
    – user606723
    Aug 3 '11 at 19:48








  • 1




    @user606723: why do not put it in an answer?
    – enzotib
    Aug 3 '11 at 19:51










  • I did just now. =p. I didn't put it in an answer at first because it was a blatant guess from looking at the man file for two seconds.
    – user606723
    Aug 3 '11 at 19:53








  • 1




    The use of -h and -k together is pointless as they contradict each other and the last one given "wins" (i.e. df -hk gives 1024 blocks output while df -kh gives human readable output).
    – PerlDuck
    Nov 27 at 14:13














  • 1




    I can't test this because my drive paths aren't huge like yours. Try df -Pkh
    – user606723
    Aug 3 '11 at 19:48








  • 1




    @user606723: why do not put it in an answer?
    – enzotib
    Aug 3 '11 at 19:51










  • I did just now. =p. I didn't put it in an answer at first because it was a blatant guess from looking at the man file for two seconds.
    – user606723
    Aug 3 '11 at 19:53








  • 1




    The use of -h and -k together is pointless as they contradict each other and the last one given "wins" (i.e. df -hk gives 1024 blocks output while df -kh gives human readable output).
    – PerlDuck
    Nov 27 at 14:13








1




1




I can't test this because my drive paths aren't huge like yours. Try df -Pkh
– user606723
Aug 3 '11 at 19:48






I can't test this because my drive paths aren't huge like yours. Try df -Pkh
– user606723
Aug 3 '11 at 19:48






1




1




@user606723: why do not put it in an answer?
– enzotib
Aug 3 '11 at 19:51




@user606723: why do not put it in an answer?
– enzotib
Aug 3 '11 at 19:51












I did just now. =p. I didn't put it in an answer at first because it was a blatant guess from looking at the man file for two seconds.
– user606723
Aug 3 '11 at 19:53






I did just now. =p. I didn't put it in an answer at first because it was a blatant guess from looking at the man file for two seconds.
– user606723
Aug 3 '11 at 19:53






1




1




The use of -h and -k together is pointless as they contradict each other and the last one given "wins" (i.e. df -hk gives 1024 blocks output while df -kh gives human readable output).
– PerlDuck
Nov 27 at 14:13




The use of -h and -k together is pointless as they contradict each other and the last one given "wins" (i.e. df -hk gives 1024 blocks output while df -kh gives human readable output).
– PerlDuck
Nov 27 at 14:13










2 Answers
2






active

oldest

votes

















up vote
16
down vote



accepted










Try: df -Pkh



The P stands for "portable", and will force it to follow POSIX standard output.

I have a hunch will fix any clever formatting that df tries to do.



In the future when you try to solve problems like these, try man df and see if you can find anything that looks like it might work... cause thats what I did =)






share|improve this answer





















  • Ack. I was using "df --help" rather than "man df" . thanks for the reminder.
    – djangofan
    Aug 3 '11 at 22:06




















up vote
2
down vote













 df -Ph | awk '{printf "%-35s%-10s%-10s%-10s%-5s%sn",$1,$2,$3,$4,$5,$6}'





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%2f55702%2fdf-h-command-puts-line-breaks-in-output-how-do-i-fix%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    16
    down vote



    accepted










    Try: df -Pkh



    The P stands for "portable", and will force it to follow POSIX standard output.

    I have a hunch will fix any clever formatting that df tries to do.



    In the future when you try to solve problems like these, try man df and see if you can find anything that looks like it might work... cause thats what I did =)






    share|improve this answer





















    • Ack. I was using "df --help" rather than "man df" . thanks for the reminder.
      – djangofan
      Aug 3 '11 at 22:06

















    up vote
    16
    down vote



    accepted










    Try: df -Pkh



    The P stands for "portable", and will force it to follow POSIX standard output.

    I have a hunch will fix any clever formatting that df tries to do.



    In the future when you try to solve problems like these, try man df and see if you can find anything that looks like it might work... cause thats what I did =)






    share|improve this answer





















    • Ack. I was using "df --help" rather than "man df" . thanks for the reminder.
      – djangofan
      Aug 3 '11 at 22:06















    up vote
    16
    down vote



    accepted







    up vote
    16
    down vote



    accepted






    Try: df -Pkh



    The P stands for "portable", and will force it to follow POSIX standard output.

    I have a hunch will fix any clever formatting that df tries to do.



    In the future when you try to solve problems like these, try man df and see if you can find anything that looks like it might work... cause thats what I did =)






    share|improve this answer












    Try: df -Pkh



    The P stands for "portable", and will force it to follow POSIX standard output.

    I have a hunch will fix any clever formatting that df tries to do.



    In the future when you try to solve problems like these, try man df and see if you can find anything that looks like it might work... cause thats what I did =)







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Aug 3 '11 at 19:52









    user606723

    1,6811014




    1,6811014












    • Ack. I was using "df --help" rather than "man df" . thanks for the reminder.
      – djangofan
      Aug 3 '11 at 22:06




















    • Ack. I was using "df --help" rather than "man df" . thanks for the reminder.
      – djangofan
      Aug 3 '11 at 22:06


















    Ack. I was using "df --help" rather than "man df" . thanks for the reminder.
    – djangofan
    Aug 3 '11 at 22:06






    Ack. I was using "df --help" rather than "man df" . thanks for the reminder.
    – djangofan
    Aug 3 '11 at 22:06














    up vote
    2
    down vote













     df -Ph | awk '{printf "%-35s%-10s%-10s%-10s%-5s%sn",$1,$2,$3,$4,$5,$6}'





    share|improve this answer



























      up vote
      2
      down vote













       df -Ph | awk '{printf "%-35s%-10s%-10s%-10s%-5s%sn",$1,$2,$3,$4,$5,$6}'





      share|improve this answer

























        up vote
        2
        down vote










        up vote
        2
        down vote









         df -Ph | awk '{printf "%-35s%-10s%-10s%-10s%-5s%sn",$1,$2,$3,$4,$5,$6}'





        share|improve this answer














         df -Ph | awk '{printf "%-35s%-10s%-10s%-10s%-5s%sn",$1,$2,$3,$4,$5,$6}'






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 12 '15 at 5:17









        muru

        135k19288488




        135k19288488










        answered Jan 12 '15 at 4:40









        Sumit Chauhan

        211




        211






























            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%2f55702%2fdf-h-command-puts-line-breaks-in-output-how-do-i-fix%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 change which sound is reproduced for terminal bell?

            Can I use Tabulator js library in my java Spring + Thymeleaf project?

            Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents