Zz.unkrig.de
A set of command-line tools that handle not only directories and files, but also ZIP and GZIP files, and even nested ZIP files.
Description
zzdiff
Computes the differences between files, directory trees, ZIP file entries, GZIPped files and prints them in various formats; widely compatible with the UNIX™ DIFF command line utility.
zzdiff Command Line Tool
Usage: java de.unkrig.zz.diff.Main -help java de.unkrig.zz.diff.Main [ <option> ] ... <file1> <file2> Show contents differences between <file1> and <file2> in DIFF format. java de.unkrig.zz.diff.Main [ <option> ] ... <dir1> <dir2> Show which files were added (missing in <dir1>) or deleted (missing in <dir2>) and their subdirectories, and any contents differences for the remaining files in DIFF format. Valid options are: File selection: -exclude <glob> -x <glob> Ignore matching files, e.g. 'dir/zipfile!dir/file' or '**/file'. '<exc>' is a 'combined wildcard pattern', see below. -zip -z Look into ZIP format files instead of comparing the plain file -nested-zip -zz Recurse into ZIP format files instead of comparing the plain file -name-equivalence <regex> -ne <regex> Files with different names map iff their names match the <regex> and all capturing groups are equal Contents processing: -disassemble -da Disassemble .class files -da-no-lines Don't display lines debug info -da-no-vars Don't display local variables debug info -line-equivalence <name> <regex> Lines in files <name> that contain <regex> and all capturing groups are equal are regarded as equal -ignore <name> <regex> -I <name> <regex> Ignore differences in files <name> where all lines (deleted, changed or added) match the given <regex> -ignore-whitespace -w Ignore whitespace differences -encoding <enc> Encoding of the files being compared (defaults to 'UTF-8') Output generation: -out <file> Write DIFF to <file> instead of STDOUT -quiet -q Report only which files were added, deleted or changed -context -c Output 'context diff' format with three lines of context -Context <N> -C <N> Output 'context diff' format with <N> lines of context -unified -u Output 'unified diff' format with three lines of context -Unified <N> -U <N> Output 'unified diff' format with <N> lines of context -keep-going Report errors and continue with next file%n" Logging: -nowarn Suppress all messages except errors -verbose Log verbose messages -debug Log verbose and debug messages -log <level>:<logger>:<handler>:<formatter> Add logging at level FINE on the root logger to STDERR, using the FormatFormatter and MESSAGE_AND_EXCEPTION format, or the given arguments which are all optional. A 'combined wildcard pattern' can have the form *~*.c~*.h+foo.c , which means 'foo.c plus all that don't end with .c or .h'
<zzdiff> Ant Task
<taskdef resource="de/unkrig/zz/antlib.xml" classpath="path/to/de.unkrig.zz.jar" /> ... <zzdiff ...>
Attributes
Default values are underlined.
ignoreWhitespace="true|false"
- Ignore whitespace differences
absentFileMode="REPORT_AS_ADDED_OR_DELETED|COMPARE_ADDED_AND_DELETED_WITH_EMPTY|COMPARE_ADDED_WITH_EMPTY"
REPORT_AS_ADDED_OR_DELETED
: Report about added and deleted files and directoriesCOMPARE_ADDED_AND_DELETED_WITH_EMPTY
: Compare added or deleted file with the empty document; compare added and deleted directories with the empty directoryCOMPARE_ADDED_WITH_EMPTY
: Compare added files with the empty document; compare added directories with the empty directory; report about deleted files and directories
zip="true|false"
- Look into ZIP format files instead of comparing the plain file
nestedZip="true|false"
- Recurse into ZIP format files instead of comparing the plain file
disassembleClassFiles="true|false"
- Disassemble .class files
disassembleClassFilesButHideLines="true|false"
- Don't display lines debug info
disassembleClassFilesButHideVars="true|false"
- Don't display local variables debug info
encoding="UTF-8|ISO-8859-1|any-other-valid-charset"
- Encoding of the files being compared (defaults to default platform encoding)
diffMode="EXIST|QUIET|NORMAL|CONTEXT|UNIFIED"
- EXIST: Report only which files were added or deleted
- QUIET: Report only which files were added, deleted or changed
- NORMAL: Output 'normal diff' format
- CONTEXT: Output 'context diff' format
- UNIFIED: Output 'unified diff' format
contextSize="n"
- Amount of 'context' which is reported with each difference; default is +- three lines (only relevant for 'context diff' and 'unified diff' formats)
keepGoing="true|false"
- Report errors and continue with next file
out="file-name"
- Write DIFF to the named file instead of STDOUT
file1="file-or-dir"
file2="file-or-dir"
- The two files or the two directories to compare
property="property-name"
(optional)- Set the named property to "
true
" iff there are no differences betweenfile1="..."
andfile2="..."
(particularly useful withdiffMode="QUIET"
)
Subelements
- <exclude name="..." />
- Ignore matching files, e.g. 'dir/zipfile!dir/file' or '**/file'. 'name' is a 'combined wildcard pattern', see below.
- <equivalentName nameRegex="..." />
- Files with different names map iff their names match the 'nameRegex' and all capturing groups are equal
- <equivalentLine name="..." regex="..." />
- Lines in files 'name' that contain 'regex' and all capturing groups are equal are regarded as equal
- <ignore name="..." regex="..." />
- Ignore differences in files 'name' where all lines (deleted, changed or added) match the given 'regex'
zzfind
Finds files in directory trees and entries in ZIP files by various criteria; widely compatible with the UNIX™ FIND command line utility.
zzfind Command Line Tool
A FIND utility that can recurse into nested files in ZIP format Usage: java de.unkrig.zz.find.Main [ <option> ... ] [ - ] <dir> ... [ <expression> ] Apply <expression> to all files in '<dir> ...'. java de.unkrig.zz.find.Main [ <option> ... ] ( -z | -zz ) [ - ] <file-or-dir> ... [ <expression> ] Apply <expression> to all files and entries in '<file-or-dir> ...'. java de.unkrig.zz.find.Main [ <option> ... ] ( -z | -zz ) - [ <expression> ] Apply <expression> to all entries in STDIN. Valid <option>s are: -help -z -zip Look into ZIP files -zz -nested-zip Look into ZIP files and nested ZIP files -encoding <enc> Contents encoding (only relevant for '-cat'), default is 'windows-1252' -nowarn Suppress all messages except errors -quiet Suppress normal output -verbose Log verbose messages -debug Log verbose and debug messages -log <level>:<logger>:<handler>:<formatter>:<format> Add logging at level FINE on logger 'de.unkrig' to STDERR using the FormatFormatter and SIMPLE format, or the given arguments which are all optional. - Separates the <option>s the from <dir> or <file-or-dir> (useful if these begin with a '-') <expression>s are either tests or actions. Both evaluate to a boolean value. Valid tests are: -name <glob> Name matches '<glob>' (see below). -path <glob> The full path (e.g. 'dir/zipfile!dir/zipfile!dir/file' or 'dir/file') matches '<glob>' (see below). -type f The file or zip entry is of 'file' type. -type d The file is of 'directory' type (directory entries in ZIP files are always ignored). -readable The file is readable -writable The file is writable -size <N> File size is exactly/less than/more than N (e.g. '100', '-1K', '+10M') -mtime <N> The file was last modified <N> days ago (0: 0...24h, 1: 24...48h, ...) -mtime +<N> The file was last modified more than <N> days ago (+0: >=24h, +1: >=48h, ...) -mtime -<N> The file was last modified less than <N> days ago (-1: <=24h, -2: <=48h, ...) <exp1> -a <exp2> <exp1> <exp2> '<exp1>' and '<exp2>' are true. <exp1> -o <exp2> '<exp1>' or '<exp2>' is true. -not <exp> ! <exp> '<exp>' is false. ( <exp> ) '<exp>' is true. Valid actions are: -print Print file path and return true. -ls Print file type, readablity, writability, size, modification time and path, and return true. -exec <word>... ; Execute '<word>...' as an external command; '{}' is replaced with the current file's path (which may contain '!' and would then NOT denote a physical file in the file system). -cat Print file contents and return true. -copy <file> Copy file contents to the named file. The following%n" substitutions are executed:%n" @{name} The file's or zip entry's name, e.g. 'file.ext' @{path} E.g. 'dir/file.zip!file.zip!dir/file.ext' @{entryname} The zip entry's name, e.g. 'dir/file.ext' If no action is given, then '-print' is implictly added. Example <glob>s: dir/file.zip!dir/file Entry 'dir/file' in ZIP file 'dir/file.zip' */x File 'x' in an immediate subdirectory **/x File 'x' in any subdirectory ***/x File 'x' in any subdirectory, or entry 'x' in any ZIP file in any subdirectory a,dir/file.zip!dir/b File 'a' and entry 'dir/b' in ZIP file 'dir/file.zip' ~*.c Files that don't end with '.c' ~*.c~*.h Files that don't end with '.c' or '.h' ~*.c~*.h,foo.c 'foo.c' plus all files that don't end with '.c' or '.h'
<zzfind> Ant Task
<taskdef resource="de/unkrig/zz/antlib.xml" classpath="path/to/de.unkrig.zz.jar" /> ... <zzfind ... />
Attributes
- zip="true"
- Look into ZIP files (default is FALSE)
- nestedZip="true"
- Look into ZIP files and nested ZIP files (default is FALSE)
Subelements
- Resource collection (e.g. <dirset>)
- The set of files and/or directories to apply the tests and actions (see below) to.
- If no resource collection subelement is configured, then STDIN is searched, which can yield results only iff
lookInto[Nested]Zip="true"
is configured.
Actions:
<cat encoding="..." />
- Copies the contents of the current file to a given string consumer and evaluates to TRUE.
<exec command="..." />
- Executes an external command; the special string '{}' within the command is replaced with the full path of the current file. Evaluates to TRUE iff the command exists with status code '0'.
<ls />
- Prints the file type ('d' or '-'), readablity ('r' or '-'), writability ('w' or '-'), size, modification time and path and evaluates to TRUE.
<print />
- Prints the path of the current file to the given string consumer and evaluates to TRUE.
Tests:
<and>...</and>
- Accepts a sequence of operand subelements; evaluates them in sequence until one evaluates to FALSE; evaluates to TRUE iff all operands evaluate to TRUE
<or>...</or>
- Accepts a sequence of operand subelements; evaluates them in sequence until one evaluates to TRUE; evaluates to FALSE iff all operands evaluate to FALSE
<name value="..." />
- Evaluates to TRUE iff the name of the current file matches the given glob.
<path value="..." />
- Evaluates to TRUE iff the path of the current file matches the given glob.
<type value="..." />
- Evaluates to TRUE iff the type of the current file matches the given value (FILE or DIR).
<not>...</not>
- Accepts exactly one operand subelement; evaluates to TRUE if the operand evaluates to FALSE and vice versa.
If more than one action or test is given, then these are implicitly and-connected.
zzgrep
Finds lines in files in directory trees and in entries in ZIP files by regular expressions; widely compatible with the UNIX™ GREP command line utility.
zzgrep Command Line Tool
A GREP utility that can recurse into nested files in ZIP format
Usage:
java de.unkrig.zz.grep.Main [ <option> ... ] <regex> [ <file-or-dir> ... ]
Reads all lines from STDIN or <file> or all files under <dir> and prints those
which contain <regex>.
Valid options are:
-help
-zip
-z Look into ZIP files.
-nested-zip
-zz Look into ZIP files and nested ZIP files.
-gzip Look into GZIP files.
-encoding <enc> Contents encoding, default is 'windows-1252'
-q -quiet Suppress all normal output.
-l -list Print only names of files containing matches.
-i -ignore-case
Ignore case distinctions.
-v -inverted Select non-matching lines.
-da Disassemble .class files on-the-fly.
-da-no-lines Don't print line numbers in the disassembly.
-da-no-vars Don't print variable names in the disassembly.
-include <glob> If given, then only entries that match <glob> are scanned.
-exclude <glob> Entries that match <glob> and their subentries are NOT
scanned.
-nowarn Suppress all messages except errors
-verbose Log verbose messages
-debug Log verbose and debug messages
-log <level>:<logger>:<handler>:<formatter>:<format>
Add logging at level FINE on logger 'de.unkrig' to STDERR
using the FormatFormatter and SIMPLE format, or the given
arguments which are all optional.
<file-or-dir>: Instead of STDIN, read from <file>, or from all files under <dir>
Example <glob>s:
dir/file.zip!dir/file Entry 'dir/file' in ZIP file 'dir/file.zip'
*/x File 'x' in an immediate subdirectory
**/x File 'x' in any subdirectory
***/x File 'x' in any subdirectory, or entry 'x' in any ZIP
file in any subdirectory
a,dir/file.zip!dir/b File 'a' and entry 'dir/b' in ZIP file 'dir/file.zip'
~*.c Files that don't end with '.c'
~*.c~*.h Files that don't end with '.c' or '.h'
~*.c~*.h,foo.c 'foo.c' plus all files that don't end with '.c' or '.h'
Exit status is 0 if any line was selected, 1 otherwise; if any error occurs,
the exit status is 2.
<zzgrep> Ant Task
<taskdef resource="de/unkrig/zz/antlib.xml" classpath="path/to/de.unkrig.zz.jar" />
...
<zzgrep ...>...</zzgrep>
Attributes
- file="file"
- Another file that will be searched.
- dir="directory"
- Another directory who's ancestor files will be searched.
- zip="true|false"
- Whether or not ZZGREP should auto-detect and look into ZIP format files.
- nestedZip="true|false"
- Whether or not ZZGREP should auto-detect and look into ZIP format files and nested ZIP format files.
- gzip="true|false"
- Whether or not ZZGREP should auto-detect and look into GZIP format files.
- encoding
- Contents encoding, default is the 'platform default encoding'.
- operation="NORMAL|LIST|QUIET"
- The operation that should be executed by ZZGREP: NORMAL (for each match, print the file name, a colon, a space and the matched line), LIST (for each match, print the file name), or QUIET (do not print the matches). The default is NORMAL.
- caseInsensitive="true|false"
- Whether the regular expression should be applied case-insensitively.
- inverted="true|false"
- Whether matching lines should be treated as non-matching, and vice versa.
- disassembleClassFiles="true|false"
- Whether to disassemble Java™ class files on-the-fly before matching its contents.
- disassembleClassFilesButHideLines="true|false"
- Whether to hide source line numbers in the Java™ class file disassembly.
- disassembleClassFilesButHideVars="true|false"
- Whether to local variable names in the Java™ class file disassembly.
- regex="regular-expression"
- The regular expression to match each line against.
- property="property-name"
- If set, then ZZGREP sets the named property to 'true' iff at leaset one line or file was selected.
Subelements
- <exclude pattern="..." />
- All files who's names match the given glob are excluded, even if they were previously included.
- <include pattern="..." />
- All files who's names match the given glob are included, even if they were previously excluded through <exclude>.
- Ressource collection, e.g. <fileset>
- File and directory tree which ZZGREP will include in its search.
zzpatch
Modifies the contents of files in directory trees and of entries in ZIP files by various criteria; widely compatible with the UNIX™ PATH command line utility.
zzpatch Command Line Tool
Usage:
java de.unkrig.zz.patch.Main [ <option> ... ] <file-or-dir>
Transforms <file-or-dir> in-place.
java de.unkrig.zz.patch.Main [ <option> ... ] <file-or-dir> <new-file-or-dir>
Transforms <file-or-dir> into <new-file-or-dir>.
java de.unkrig.zz.patch.Main [ <option> ... ] <file-or-dir> ... <out-dir>
Transforms <file-or-dir> and creates the output in <out-dir>.
Valid options are:
-help Shows this text.
-keep If existing files were overwritten, keep copies of the originals.
-update <glob> <update-file>
Replace the contents of files/ZIP entries that match <glob> (see
below) with that of <update-file>.
-substitute <glob> <regex> <replacement>
Substitute occurrences of <regex> in files/zip entries that
match <glob> (see below) with <replacement>.
-patch <glob> <patch-file>
Apply <patch-file> to all files/ZIP entries that match <glob>
(see below). <patch-file> can be in traditional, context or
unified diff format.
-remove <glob>
Remove all in files/ZIP entries that match <glob> (see below).
-rename <glob>
Rename out files/ZIP entries according to <glob> (see below), e.g.
'(*).c=$1.c.orig'. Multiple '-rename' options are applied in the
given order.
-add <glob> <name> <contents-file>
To all directories/ZIP format files that match <glob>, add a
member/entry <name>, and fill it from <contents-file>.
-z
-zip Look into ZIP files.
-nested-zip
-zz Look recursively into ZIP files.
-gzip Look into GZIP files.
-nested-gzip
Look recursively into GZIP files.
-input-encoding <enc>
-output-encoding <enc>
Encoding of input files and output files (only relevant for
'-substitute' and '-patch'); default is 'windows-1252'
-patch-file-encoding <enc>
Encoding of patch files (only relevant for '-patch'); default is
'windows-1252'
-nowarn Suppress all messages except errors
-quiet Suppress normal output
-verbose Log verbose messages
-debug Log verbose and debug messages
-log <level>:<logger>:<handler>:<formatter>:<format>
Add logging at level FINE on logger 'de.unkrig' to STDERR using
the FormatFormatter and SIMPLE format, or the given arguments
which are all optional.
Example <glob>s:
dir/file.zip!dir/file Entry 'dir/file' in ZIP file 'dir/file.zip'
*/x File 'x' in an immediate subdirectory
**/x File 'x' in any subdirectory
***/x File 'x' in any subdirectory, or entry 'x' in any ZIP
file in any subdirectory
a,dir/file.zip!dir/b File 'a' and entry 'dir/b' in ZIP file 'dir/file.zip'
~*.c Files that don't end with '.c'
~*.c~*.h Files that don't end with '.c' or '.h'
~*.c~*.h,foo.c 'foo.c' plus all files that don't end with '.c' or '.h'
<zzpatch> Ant Task
<taskdef resource="de/unkrig/zz/antlib.xml" classpath="path/to/de.unkrig.zz.jar" />
...
<zzpatch ...>
Attributes
- keepOriginals="boolean"
- Whether to keep backup copies of files/entries that are modified or removed. Default is false.
- zip="boolean"
- If false, then files in ZIP format are processed like all other regular files. If true, then the transformations are applied to the entries of ZIP format files, rather than to the ZIP file.
- nestedZip="boolean"
- If false, then files in ZIP format are processed like all other regular files. If true, then the transformations are applied to the entries of ZIP format files (even nested entries), rather than to the ZIP file.
- gzip="boolean"
- If false, then files in GZIP format are processed like all other regular files. If true, then the transformations are applied to the entries of GZIP format files, rather than to the GZIP file.
- file="file"
- Another file that will be patched.
- tofile="file"
- (Only allowed in connection with 'file="file".) Result file after the operations are carried out. (Default if to patch the file in-place.)
- dir="dir"
- Another directory tree that will be patched.
- toDir="dir"
- The result files are created in the given directory after the operations have been carried out. (Default if to patch all files in-place.)
Subelements
- Resource collection (e.g.
<fileset>
, <dirset>
)
- Files and directory trees that will be patched.
<update name="glob" updateFile="file" />
- The contents of files/entries that match
name="glob"
will be replaced with the contents of the updateFile="file"
.
<substitute name="glob" inputEncoding="enc" outputEncoding="enc" regex="regex" replacement="replacement" />
- Replaces all occurrences of
regex="regex"
with replacement="..."
in files/entries that match name="glob"
. Alternatively, regex and replacement can be configured with <regex>
and <replacement>
subelements; the major advantage of subelements is that they can contain <![CDATA[...]]>
sections where you don't have to SGML-escape special characters.
- With the MULTILINE option enabled (by including "
(?m)
" in the regex), you are not limited to line-wise pattern matching, but be careful with using greedy quantifiers, because these may require that the entire contents of each file needs to be loaded into memory.
<patch name="glob" inputEncoding="enc" outputEncoding="enc" patchFile="file" patchFileEncoding="enc" />
- Files/entries that match
name="glob"
will be patched with the DIFF document in the patchFile="file"
. Supported DIFF formats are 'traditional diff', 'context diff' and 'unified diff'.
<remove name="glob" />
- Files/entries that match
name="glob"
will be deleted/removed.
<rename name="glob" />
- Files/entries that match
name="glob"
will be renamed. The glob must be in the 'replacement' format, as described " here.
Resources
These tools make heavy use of commons.unkrig.de.
License
ZZ.UNKRIG.DE is published under the "New BSD License".