Validate Configuration Files or Scripts in Linux

1. Sudo Command

You can check the sudo configuration file syntax using the visudo command, which supports a --check or -c command line option to only validate a file without an edit. The -f option displays the error message and opens the file for editing:

$ sudo visudo -c
/etc/sudoers: parsed OK
/etc/sudoers.d/README: parsed OK
$ visudo -h
visudo - safely edit the sudoers file

usage: visudo [-chqsV] [[-f] sudoers ]

  -c, --check              check-only mode
  -f, --file=sudoers       specify sudoers file location
  -h, --help               display help message and exit
  -q, --quiet              less verbose (quiet) syntax error messages
  -s, --strict             strict syntax checking
  -V, --version            display version information and exit
$ sudo visudo -V
visudo version 1.8.31
visudo grammar version 46