Go to: Synopsis. Return value. Flags. MEL examples.

Synopsis

filetest [-L] [-b] [-c] [-d] [-e] [-f] [-g] [-h] [-k] [-l] [-p] [-r] [-s] [-u] [-w] [-x] [-z] string

filetest is NOT undoable, NOT queryable, and NOT editable.

This is a file access and type checking command. It evaluates a test based on a single flag given to it and returns 1 if the value is true; otherwise, 0. Filetest also returns 0 if the test is invalid. When permissions are tested, the effective user ID of the process is used.

The unary negation operator, "!", may precede the test.

Special Note:

If you test a file you own (the -r, -w, or -x tests), but the permission tested does not have the owner bit set, a non-zero (false) exit status will be returned even though the file may have the group or other bit set for that permission. The correct exit status will be set if you are super-user.

If more than one test is specified, only the first test is executed; the others are ignored.

Note:

Return value

intTest result

Flags

L, b, c, d, e, f, g, h, k, l, p, r, s, u, w, x, z
Long name (short name) Argument types Properties
-L(-L) create
true if file exists and is a symbolic link.
-b(-b) create
true if file exists and is a block special file.
-c(-c) create
true if file exists and is a character special file.
-d(-d) create
true if file exists and is a directory.
-e(-e) create
true if file (or directory) exists
-f(-f) create
true if file exists and is a regular file.
-g(-g) create
true if file exists and its set-group-ID bit is set.
-h(-h) create
true if file exists and is a symbolic link.
-k(-k) create
true if file exists and its sticky bit is set.
-l(-l) create
true if file exists and is a symbolic link.
-p(-p) create
true if file exists and is a named pipe (fifo).
-r(-r) create
true if file exists and is readable.
-s(-s) create
true if file exists and has a size greater than zero.
-u(-u) create
true if file exists and its set-user-ID bit is set.
-w(-w) create
true if file exists and is writable.
-x(-x) create
true if file exists and is executable.
-z(-z) create
true if file is a Unix domain socket file (not supported on Windows)

Flag can appear in Create mode of command Flag can appear in Edit mode of command
Flag can appear in Query mode of command Flag can be used more than once in a command.

MEL examples

// Test whether the temp directory exists
//
string $tmpDir = `internalVar -userTmpDir`;
filetest -d $tmpDir;
// Result: 1 //

// The following will fail because the temp dir is not a regular file
//
filetest -f $tmpDir;
// Result: 0 //