Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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
    
Thank you , thats it. –  djangofan Aug 3 '11 at 19:49
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
add comment

1 Answer 1

up vote 5 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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.