CSC 357 Programming Assignment 4
sfind -- A Simplified Find
Utility
In this assignment, you are writing a simplified version of the very useful
UNIX find command. The following excerpt, from the UNIX man page,
summarizes find's operation:
Usage: find path... expression The find utility recursively descends the directory hierarchy for each path, seeking files that match a Boolean expression written in the expression primaries given below.The path argument(s) are the starting point in a directory hierarchy. The first argument that starts with a - or !, and all subsequent arguments, are interpreted as an expression made up of the primaries and operators listed below.
In other words, find searches for files in a directory hierarchy that meet certain search criteria.
The primaries in the simplified version of find are the
following, which constitute a subset of those available in the full
find command:
-atime n True if the difference between the file last access time and the time find was started, rounded up to the next full 24-hour period, is n 24-hour periods. -ctime n True if the difference between the time of last change of file status information and the time find was started, rounded up to the next full 24-hour period, is n 24-hour periods. -exec command [argument ...]; True if the executed command returns a zero value as its exit status. Optional arguments may be passed to the command. The expression must be terminated by a semicolon. If {} appears anywhere in the command arguments, it is replaced by the pathname of the current file. Command is executed from the directory from which find was executed. -group gname True if the file belongs to the group gname; the gname cannot be numeric. -mtime n True if the difference between the file last modification time and the time find was started, rounded up to the next full 24-hour period, is n 24-hour periods. -name pattern True if the last component of the pathname being examined matches pattern. Special shell pattern matching characters may be used as part of pattern. Matches are performed per the specification of the fnmatch system function. A backslash is used as an escape character within the pattern. The pattern should be escaped or quoted when find is invoked from the shell. Name patterns match any files, including those beginning with a '.'. (This is in contrast to /usr/bin/find, but consistent with some other versions of find, e.g., /usr/xpg4/bin/fin on Solaris.) -newer file True if the current file has been modified more recently than the argument file. -print Always true. Causes the current path name to be printed. -size n True if the file is n blocks long (512 bytes per block). -type c True if the type of the file is c, where c is one of d, f, or l, for directory, plain file, or symbolic link, respectively. -user uname True if the file is owned by the user uname, which cannot be numeric.
+n time or size is greater than n
n time or size is exactly n
-n time or size is less than n
Write out the names of all files and directories in the current working directory:
Note that -print is the default, if not explicitly specified.sfind . sfind . -print
Note the use of the backslash, so that '*' is sent to sfind rather than being expanded by the UNIX shell.sfind . -name \*.c
sfind . -name \*.c -newer x
Note the use of the backslash for !, again so it is not expanded by the shell.sfind . \! -name \*.o -newer x -user gfisher
sfind . -type l -exec ls -sal {} ;
The following C library functions may be particularly useful in your
implementation. You can read about these in Stevens and the man pages.
Function Description nftw file tree traversal fnmatch match shell-style regular expression patterns getopts parse command-line options
You must submit a set of .c and .h files plus a
Makefile that compiles your program into an executable named
sfind. The files must follow the 357 design and implementation
conventions. If you want to provide any comments about your implementation,
you may optionally include a plain-text README file.
The testing plan file in the 357 programs/4/testing directory has the
precise point breakdown.
NO collaboration is allowed on this assignment. Everyone must do their own
individual work.
Submit your deliverable using the handin program on falcon/hornet. For Section 1 of 357, the command is
where "..." are your program files.handin gfisher prog4 ... Makefile