TrueVFS Command Line Utility

The TrueVFS command line utility implemented by the class showcases the features of the TrueVFS Access API.

The TrueVFS command line utility allows you to work with entries in any archive file which is supported by an archive driver module on the class path like TrueVFS Driver ZIP, TrueVFS Driver TAR, TrueVFS Driver TAR.GZIP, TrueVFS Driver TAR.BZIP2 et al using Unix like commands like cat, cp, mv, rm, mkdir, mkdirs, ls, ll , llr , touch et al. You can use this utility to conveniently copy entire directory trees into an archive file or from an archive file or any other virtual or non-virtual directory.

Setting The Stage

Before the examples are shown below, a little preparation is required in order to make it easier to start the utility class from the command line. With plain Java, you would have to start the utility class with a command like this:

$ java -jar truevfs-samples-0.12.0-standalone.jar %ARGS%

Where %ARGS% is a variable for arbitrary command line arguments - see below. This example uses TrueVFS's all-in-one JAR.

However, on Windows we would like to use something like this instead:

$ truevfs %ARGS%

This can be done by copying the following script file with the name truevfs.cmd in some directory on your %PATH%:

@echo off

rem set PROPS=-Djava.awt.headless=true
rem set
set JAR=%USERPROFILE%\.m2\repository\net\java\truevfs\truevfs-samples\0.12.0\truevfs-samples-0.12.0-standalone.jar

java %PROPS% -jar "%JAR%" %*

On Unix/Linux, this should be a bash script with the name truevfs - I leave this as an exercise to you, however.


Following are some examples using the TrueVFS command line utility class. If you need help with the available commands and options, just run the TrueVFS command line utility class without parameters and it will print some help on standard error output.

Command Description
$ truevfs ll truevfs-samples-0.12.0-standalone.jar Prints a detailed listing of the contents of the root directory of the JAR file from which the tool is actually running.
$ truevfs llr truevfs-samples-0.12.0-standalone.jar Prints a recursive long listing of the contents of the root directory of the JAR file from which the tool is actually running.
$ truevfs cp truevfs-samples-0.12.0-standalone.jar/net/java/truevfs/samples/access/TrueVFS.class Copies the file entry net/java/truevfs/samples/access/TrueVFS.class from the distribution JAR into the ZIP file
$ truevfs rm Removes the file entry TrueVFS.class from
$ truevfs rmr Recursively removes the directory entry de from
$ truevfs mkdir Creates the new ZIP file in the existing ZIP file Remember that this API treats archive files like directories, so you can simply create a ZIP file by calling the mkdir() method on a File object.
$ truevfs mkdirs Creates the new directory a containing the new ZIP file, containing the new directory c containing the new ZIP file within the existing
$ truevfs rm Removes the empty ZIP file Note that similar to regular directories, this succeeds on empty ZIP files only.
$ truevfs touch Updates the last modification time of the existing ZIP file to the current time. Note that if the given file does not exist, it is created as a plain file - you cannot create ZIP files using this method (use mkdir instead).
$ truevfs mv . Moves the entry TrueVFS.class from the ZIP file to the current directory . .

Note: Although TrueVFS has been designed to provide optimum performance, the TrueVFS command line utility is a feature showcase which should not serve as a performance benchmark: The utility uses some optional archive drivers which are not normally used but provide extra safety and extra features at the price of performance, such as CRC-32 checking, scanning .exe files for self extracting ZIP files et al. Furthermore, the start up time of the JVM makes Java almost useless for short running command line utilities anyway.

Of course, you can substitute the .zip extension in the examples above with any other file type extension recognized by the archive drivers modules on the class path.

For example, if you would like to use RAES encrypted ZIP files you would simply name the extension .tzp in a path. So in order to copy the directory directory to a RAES encrypted ZIP file secure.tzp, you can run:

$ truevfs cp -r directory secure.tzp

If you want to copy a plain file file instead, then run:

$ truevfs cp file secure.tzp/file

New Options for ZIP Files

The cp command provides some options to control additional features as follows.

Use the following option in order to create a ZIP entry which is encrypted according to the WinZip AES encryption specification.

$ truevfs cp -encrypt file

Use the following option in order to append a ZIP entry to the end of an existing ZIP file instead of updating the ZIP file. This might be useful if the ZIP file is pretty large compared to the single entry to add.

$ truevfs cp -grow file

Sometimes you might want to use the STORED method rather than the DEFLATED method when writing an entry to a ZIP file. There's an option for this, too:

$ truevfs cp -store file

For completeness, there's also an option to use the DEFLATED method. This is the default however, so you don't need to specify it:

$ truevfs cp -compress file