VMS-to-Unix Phrase Book
<=  Return           

2.4  Finding Files

Problem

You want to find one or more files, possibly across multiple directories based on a variety of criteria.

Solution

Use the find command in situations where you would have used the directory command.

Discussion

The Unix ls command and the VMS directory command are both used for listing the contents of directories and information about the file's attributes. The VMS directory command also includes options for selecting targeted sets of files based on various file attributes. Under Unix, this functionality is provided by a specialized program called find.

Probably the number one use of the find command is for recursively searching directory trees. In VMS, the file notation "..." is used to indicate that subdirectories are to be searched. For example:

    dir [wfc...]
means to search the entire directory tree starting at the home directory of "WFC". In contrast, Unix does not support this notion as part of the file specification syntax. Consequently a few common utility programs, such as ls and rm provide a recursive search (-r) option, but many do not. Instead, using either pipes or back-ticks as appropriate, find is used in combination with other programs and utilities to achieve the same effect. The find command can also be used to repeatedly call a script or program on each file found.

Like grep (2.2) find is a feature rich and thus complex utility, so much so that there is a whole chapter in Unix Power Tools devoted to just this one utility. So it is beyond the scope of this article to cover all of its features. But hopefully the following translation phrases will help the VMS user to get a leg-up in using this key utility.

VMS UNIX Action
direct/nohead/notrail [...]
find . -print
Print full filespecs of all files in current directory tree.
direct/nohead/notrail [...]*.for
find . -name '*.f' -print
Find all FORTRAN files in current directory tree.
direct/modified/since=-45-00 [wfc...]
find /wfc -mtime -45 -print
Find all files in the specified user's directory tree that have been modified within the last 45 days.
delete/confirm -
/modified/before=-45-00 -
[wfc...]*.bak
find /wfc -name '*.bak' \
-mtime +45 -ok rm -f {} \;
Interactively (-i) prompt to delete all backup files that have been modified more than 45 days ago.

IMPORTANT NOTE: In the last example, the Unix command line was continued by entering a backslash immediately followed by pressing the return. And the final portion of the command \; must be entered as shown -- the trailing semicolon is not optional.

See Also

2.3 - Matching Multiple Files Using Wildcards;
Chapter 8 of Unix for OpenVMS Users ;
Chapter 18 of Unix Power Tools .


<=  Return           

Colophon:
Best Viewed With Any Browser
This page maintained by:
    Bill.Costa@unh.edu
    of the Enterprise Computing Group
    in the dept of Computing & Information Sevices
    at the University of New Hampshire

Typographical
Conventions

Created:  31-Jan-2001 BC
Revised:  27-Mar-2001 BC