Edit online

Compare Directories

Attention: To run this script, you are required to purchase a special scripting commercial license.

The Compare Directories script (compareDirs.sh) can be used to compare two directories and get the comparison results in various formats.

Arguments for the Compare Directories Script

sh scripts/compareDirs.sh firstDirPath secondDirPath [[-if includeFilesFilter] [-ia includeArchives] [-ef excludeFilesFilter] [-ed excludeSubdirsFilter] [-cm comparisonMode] [-alg comparisonAlg] [-als algStrength] [-iws ignoreWS] [-ipi ignorePI] [-icm ignoreComments] [-idt ignoreDocType] [-itn ignoreText] [-ins ignoreNS] [-ind ignoreNSDecl] [-inp ignorePrefixes] [-iao ignoreAttrOrder] [-iee ignoreExpStateForEmptyElems] [-out outputFormat]] [-help | --help | -h | --h]
firstDirPath
Mandatory argument that specifies the first directory path.
secondDirPath
Mandatory argument that specifies the second directory path.
-if includeFilesFilter
Use this argument to only include files that match the specified pattern in the comparison (e.g. .xml, .json). Default value = *.
-ia includeArchives
If set to true, files from archives are included in the comparison. Default value = false.
-ef excludeFilesFilter
Use this argument to exclude files that match the specified pattern from the comparison (e.g. *.jpg).
-ed excludeSubdirsFilter
Use this argument to exclude sub-directories that match the specified pattern from the comparison (e.g. .svn, _svn, .git).
-cm comparisonMode
Specifies the comparison mode. There are three modes available: content, binary, and timestamp. Default value = content.
-alg comparisonAlg
Specifies the algorithm to be used for the comparison. Possible values: auto, chars, words, lines, syntax_aware, xml_fast, and xml_accurate. Default value = auto.
-als algStrength
Specifies the strength of the algorithm to be used for the comparison. Possible values: low, medium, high, and very_high. Default value = medium.
-iws ignoreWS
If set to true, whitespaces are ignored if differences consist only of whitespaces. Default value = false.
-ipi ignorePI (only for the XML-aware algorithms)
If set to true, processing instructions are ignored in the comparison. Default value = false.
-icm ignoreComments (only for the XML-aware algorithms)
If set to true, comments are ignored in the comparison. Default value = false.
-idt ignoreDocType (only for the XML-aware algorithms)
If set to true, DOCTYPE sections are ignored in the comparison. Default value = false.
-itn ignoreText (only for the XML-aware algorithms)
If set to true, text content is ignored in the comparison. Default value = false.
-ins ignoreNS (only for the XML-aware algorithms)
If set to true, namespaces are ignored in the comparison. Default value = false.
-ind ignoreNSDecl (only for the XML-aware algorithms)
If set to true, namespace declarations are ignored in the comparison. Default value = false.
-inp ignorePrefixes (only for the XML-aware algorithms)
If set to true, prefixes are ignored in the comparison. Default value = false.
-iao ignoreAttrOrder (only for the XML-aware algorithms)
If set to true, the order of attributes is ignored in the comparison. Default value = false.
-iee ignoreExpStateForEmptyElems (only for the XML-aware algorithms)
If set to true, the expansion state for empty elements is ignored in the comparison. Default value = false.
-out outputFormat
Specifies the format of the output files. Possible values: yaml/grouped, yaml/raw, json/grouped, json/raw, xml/grouped, or xml/raw. Default value = yaml/grouped.
Note: If you choose to redirect the console output to a file, this argument establishes the type of the output file and its content is formatted accordingly. If you skip specifying the "/grouped" or the "/raw" qualifiers, "/grouped" is the one considered.
-help | --help | -h | --h
Displays help text.
Notes:
  • For boolean arguments, it is not necessary to provide the "true" value. Their presence in the argument list is equivalent to setting their value to "true" (and their absence from the argument list is equivalent to setting their value to "false"). However, constructs of the form bool_option true|false are accepted and interpreted accordingly.
  • File markers used in reports are as follows: M = modified, O1 = only found in 1st directory, O2 = only found in 2nd directory.

Examples of Compare Directories Script

  • sh scripts/compareDirs.sh dir1 dir2 -ia true -ef *.jpg

    Includes archives, but excludes JPEGs from the comparison.

  • sh scripts/compareDirs.sh dir1 dir2 -if *.xml -ia -iao -icm

    Only XML files (even from archives) are included in the comparison, ignoring the comments and attribute order.

  • sh scripts/compareDirs.sh dir1 dir2 -out json/raw > results.json

    Redirects the console output to a JSON file named "results.json", with "raw" mode formatting.