tw recursively descends the file tree rooted at the current directory and lists the pathname of each file found. If
cmd
arg ... is specified then the pathnames are collected and appended to the end of the
arglist and
cmd is executed
by the equivalent of
execvp(2). cmd will be executed 0 or more times,
depending the number of generated pathname arguments.
If the last option is - and --fast was not specified then the pathnames are read, one per line, from the standard
input, the --directory options are ignored, and the directory tree is not traversed.
getconf PATH_RESOLVE determines how symbolic links are handled. This can be explicitly overridden by the --logical,
--metaphysical, and --physical options below. PATH_RESOLVE can be one of:
- logical
Follow all symbolic links.
- metaphysical
Follow command argument symbolic links, otherwise don't follow.
- physical
Don't follow symbolic links.
Expressions are C style and operate on elements of the
stat(2) struct with the
leading
st_ omitted. A function expression is defined by one of:
function-name : statement-list
type function-name() { statement-list }
where function-name is one of:
- begin
Evaluated before the traversal starts. The return value is ignored. The default is a no-op.
- select
Evaluated as each file is visited. A 0 return value skips action for the file;
otherwise action is evaluated. All files are selected by default. select is assumed when function-name: is
omitted.
- action
Evaluated for each select file. The return value is ignored. The default action
list the file path name, with leading ./ stripped, one per line on the standard output.
- end
- Evaluated after the traversal completes. The return value is ignored.
- sort
- A pseudo-function: the statement list is a , separated list of identifiers used to sort the
entries of each directory. If any identifier is preceded by ! then the sort order is reversed. If any identifier is preceded
by ~ then case is ignored.
statement-list is a C style
expr(3) expression that supports:
int
var, ...; and
float var, ...; declarations,
(int) and
(float) casts,
if-
else
conditionals,
for and
while loops, and
{...} blocks. The trailing
; in any expression list is optional.
The expression value is the value of the last evaluated expression in
statement-list. Numbers and comments follow C syntax.
String operands must be quoted with either
"..." or
'...'. String comparisons
== and
!= treat the right
hand operand as a
ksh(1) file match pattern.
The expressions operate on the current pathname file status that is provided by the following field identifiers, most of which are
described under st_field in stat(2). In general, if a status
identifier appears on the left hand side of a binary operator then the right hand side may be a string that is converted to an
integral constant according to the identifier semantics.
- atime
access time; time/date strings are interpreted as
date(1) expressions
- blocks
number of 1k blocks
- checksum
equivalent to sum("tw")
- ctime
status change time
- dev
- file system device
- fstype
file system type name; ufs if it can't be determined
- gid
- owner group id; gid strings are interpreted as group names
- gidok
1 if gid is a valid group id in the system database, 0 otherwise.
- ino
- inode/serial number
- level
the depth of the file relative to the traversal root
- local
an integer valued field associated with each active object in the traversal; This field may
be assigned. The initial value is 0. Multiple local elements may be declared by int local.element1...;. In
this case the local field itself is not accessible.
- md5sum
equivalent to sum("md5")
- mime
- the file contents file(1) --mime type
- mode
- type and permission bits; the FMT constant may be used to mask mask the file type and
permission bits; mode strings are interpreted as chmod(1) expressions
- mtime
modify time
- name
- file name with directory prefix stripped
- nlink
hard link count
- path
- full path name relative to the current active --directory
- perm
- the permission bits of mode
- rdev
- the major.minor device number if the file is a device
- size
- size in bytes
- status
the fts(3) FTS_* or
ftwalk(3) FTW_* status. This field may be assigned:
- AGAIN
visit the file again
- FOLLOW
if the file is a symbolic link then follow it
- NOPOST
cancel any post order visit to this file
- SKIP
- do not consider this file or any subdirectories if it is a directory
- sum("method")
file contents checksum using method; see
sum(1) --method for details.
- symlink
the symbolic link text if the file is a symbolic link
- type
- the type bits of mode:
- BLK
- block special
- CHR
- block special
- DIR
- directory
- DOOR
- door
- FIFO
- fifo
- LNK
- symbolic link
- REG
- regular
- SOCK
- unix domain socket
- uid
- owner user id; uid strings are interpreted as user names
- uidok
1 if uid is a valid user id in the system database, 0 otherwise.
- url
- unprintable chars n path converted to %XX hex
- visit
an integer variable associated with each unique object visited; Objects are identified
using the dev and ino status identifiers. This field may be assigned. The initial value is 0. Multiple visit
elements may be declared by int visit. element...;. In this case the visit field itself is not accessible.
Status identifiers may be prefixed by 1 or more
parent. references, to access ancestor directory information. The parent
status information of a top level object is the same as the object except that
name and
path are undefined. If a
status identifier is immediately preceded by
"string". then string is a file pathname from which the status is taken.
The following expr(3) functions are supported:
- exit(expr)
causes tw to exit with the exit code expr which defaults to 0 if
omitted
- printf(format[,arg...])
print the arguments on the standard output using the
printf(3) specification format.
- eprintf(format[,arg...])
print the arguments on the standard error using the
printf(3) specification format.
- query(format[,arg...])
prompt with the
printf(3) message on the standard error an read an interactive response. An
affirmative response returns 1, q or EOF causes tw to to exit immediately, and any other input returns 0.