I'm trying to compare the file systems among many other basic services, before and after server reboot to check if any mismatches are present.

I'm currently saving the data to a file and am comparing using diff command

As there are many servers this is not being effective, as this is also checking the difference in the FS size too; as can be seen from below.

diff -rs ./prechecks/file ./postchecks/file
< udev                                                                  7.8G  164K  7.8G   1% /dev
> udev                                                                  7.8G  156K  7.8G   1% /dev
< /dev/mapper/vg01-lvopt_IBM                                            9.9G  8.2G  1.2G  88% /opt/IBM
> /dev/mapper/vg01-lvopt_IBM                                            9.9G  8.3G  1.2G  88% /opt/IBM

I've tried If we can use ignore option, but I couldn't get through the logic.

I want to check if we can overcome this.? This is taking toll as I have to deal with many hundreds of servers each time.

Else, Is there a way to ignore the tabs - Size; Used; Avail; Use%; in the output of df -h as seen below which will eliminate the check in the first place.

Filesystem                                      Size  Used Avail Use% Mounted on
/dev/mapper/vg00-lvroot                          20G   16G  4.5G  78% /

Help me solve the challenge. Thanks.!

EDIT1: df --output=source,fstype,target is my first choice, but I'm unable to do it on another servers df: unrecognized option '--output=source,fstype,target' Try `df --help' for more information. Any other workaround.?


4 Answers 4


You may want to compare the output of the mount command rather than the df command if you want to compare only the mount points.

This would also compare the mount options and file system types, which may be good too.

$ mount
server:/export/client/root on / type nfs (v3, udp, timeo=100, retrans=101)
server:/export/shared/usr on /usr type nfs (nodev, wxallowed, v3, tcp, soft, intr, timeo=100)
amd:20004 on /home type nfs (v2, udp, intr, timeo=100, retrans=101)
server:/export/shared/home on /tmp_mnt/server/export/shared/home type nfs (nodev, nosuid, v2, udp, soft, intr, timeo=100)
  • Mount options was my first goto thought, but the client requires df -h output too... :( As df -h is simple.
    – Hemanth
    Commented May 6, 2017 at 21:59
  • @Hemanth Which df output? After removing those bits of information, it's just the device and mountpoint left.
    – Kusalananda
    Commented May 7, 2017 at 8:09
  • I know. But the clients compare just the Filesystems and mount points; df gives it in human readable format unlike mount. And I also feel that I don't have to trouble them with the tit bits of mount output, when I can happily give them the same info with much less complications. Any way thanks for the answer. I truly have thought about it.!
    – Hemanth
    Commented May 7, 2017 at 10:55

Is there a way to ignore the tabs - Size; Used; Avail; Use%;

The df command output fields are adjustable via --output option:

df -h --output='source'

The above will output only filesystem names list


use the output format defined by FIELD_LIST, or print all fields if FIELD_LIST is omitted.

If some options are unsupported try the following workaround with awk:

df -h | awk '{print $1}'
  • Thank you. Sorry, I forgot to mention that, I've already tried it, It is not working on many of the servers. df: unrecognized option '--output=source,fstype,target' Try df --help' for more information.` Any work around that you know.?
    – Hemanth
    Commented May 6, 2017 at 21:54
  • 1
    @Hemanth, try the workaround that I've added to my answer Commented May 6, 2017 at 22:06

GNU diff has two kinds of ways to ignore changes. There are options to ignore certain kinds of differences, such as whitespace or case, but these are limited to a few presets. And there is an option to ignore lines that match certain patterns, but that only lets you ignore lines, not ignore certain changes within the lines. Ignoring whitespace changes (diff -w) can help you, in case columns get formatted to different widths, but to ignore some numbers, you need something else.

The usual way to ignore certain differences is to preprocess the two files in order to remove or canonicalize the parts you want to ignore. For example, if you want to ignore the used/available/percentage columns, assuming that your volume names and mount points don't contain whitespace, you can use

awk '{print $1, $2, $6}'

as the preprocessor. You may also want to sort the files, unless you're doing that already, because a difference in the enumeration order from df is not significant. In a shell with process substitution (ksh, bash, zsh):

diff <(<./prechecks/file awk '{print $1, $2, $6}' | sort) \
     <(<./postchecks/file awk '{print $1, $2, $6}' | sort)

If you were doing this over many files, instead of using diff -rs, build your own loop to call diff on files individually.

  • But Gilles, the file will have other checks too apart from df output. So it wont be sensible to do as suggested.
    – Hemanth
    Commented May 6, 2017 at 22:02
  • @Hemanth What do you mean by “other checks”, and why would preprocessing the file not be sensible? Commented May 6, 2017 at 22:07
  • I also take fstab entries, run levels, routes among other checks.. So preprocessing file isn't a option. But after rereading your answer again, it makes sense. I can process the df output and then append it to file later which was suggested in another answer above. But thank you, your answer throws great insight to ignore some numbers. I'll put it good use.! :)
    – Hemanth
    Commented May 7, 2017 at 6:37

You might also consider the output of the lsblk command. This is a Linux-only utility, but it lists all block devices, even if they're not mounted. See the man page for the -n option, which disables the headers, and the -o option, which lets you specify what columns you want.

  • lsblk lists only block devices as you say.. but won't get nfs shares details. Also I guess there won't be any changes in lsblk output after reboot.
    – Hemanth
    Commented May 7, 2017 at 6:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .