Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I can't seem to find a solution for this and it's driving me crazy. I know I can use awk to print a column(s). I'm having trouble printing a specific column though because of the way my file system is arranged.

This is what I have when I run df:

Filesystem           1K-blocks      Used Available Use% Mounted on
                      36623968   4484592  30278976  13% /
tmpfs                   961312         0    961312   0% /dev/shm
/dev/sda1               516040    102896    386932  22% /boot

If I awk for the 1K-blocks column it returns values from other columns because of the length of the filesystem location. Basically this happens:



How can I list the right column info?

share|improve this question
Try using df -P. See also GNU stat. – Stéphane Chazelas May 17 '13 at 19:46
@StephaneChazelas: that's an answer ;) – tink May 17 '13 at 21:02
Worked. Thanks. – mister mister May 17 '13 at 21:37

3 Answers 3

If you're piping df into awk, pipe df -P instead. It's designed to be easily parsable, and in particular doesn't break lines. Remember to skip the header line (NR >= 2).

If you need to parse some existing output with weird line breaks, you can tell a continuation line because it starts with a space.

awk '
  NR==1 {next}
  /^ / {print $1}
  !/^ / {print $2}

Beware however that there are unix variants (OSX, at least — and I wouldn't be surprised if it was the only one where this happens in practice) where the filesystem designation can contain spaces, which makes any column-based parsing problematic (unfortunately, df -P doesn't use tabs).

share|improve this answer

I don't have an unusually long FS name but you can try this:

df |grep "%" |grep -v Use |awk {'print $(NF-4)'}

This is assuming you don't need the title line with the 1K-Blocks.

share|improve this answer
df -Pk|tail -n +2|column -t | awk '{print $4}'
  • df -Pk: will list the file system.
  • tail -n +2: will remove header.
  • column -t: used to format the output.
  • awk '{print $4}': will print the contents of fourth column.
share|improve this answer
Please don't answer with one-liner commands. Even if they work, OP will have to figure out what is this, why does it work, etc. Please add an explanation to your answer. – psimon Jul 7 '14 at 7:22
df -Pk : will list the file system....tail -n +2 : will remove header.....column -t: used to format the ouput.....awk '{print $4}' :will print the contents of fourth column................... – Sorav Jul 7 '14 at 7:42

Your Answer


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.