Finding files (find command)

Use the find command to recursively search the directory tree for each specified Path, seeking files that match a Boolean expression written using the terms given in the following text.

The output from the find command depends on the terms specified by the Expression parameter.

The following are examples of how to use the find command:
  • To list all files in the file system with the name .profile, type the following:
    find / -name .profile
    This searches the entire file system and writes the complete path names of all files named .profile. The slash (/) tells the find command to search the /(root) directory and all of its subdirectories.

    To save time, limit the search by specifying the directories where you think the files might be.

  • To list files having a specific permission code of 0600 in the current directory tree, type the following:
    find . -perm 0600
    This lists the names of the files that have only owner-read and owner-write permission. The dot (.) tells the find command to search the current directory and its subdirectories. For an explanation of permission codes, see the chmod command.
  • To search several directories for files with certain permission codes, type the following:
    find manual clients proposals -perm -0600
    This lists the names of the files that have owner-read and owner-write permission and possibly other permissions. The manual, clients, and proposals directories and their subdirectories are searched. In the previous example, -perm 0600 selects only files with permission codes that match 0600 exactly. In this example, -perm -0600 selects files with permission codes that allow the accesses indicated by 0600 and other accesses above the 0600 level. This also matches the permission codes 0622 and 2744.
  • To list all files in the current directory that have been changed during the current 24-hour period, type the following:
    find . -ctime 1 
  • To search for regular files with multiple links, type the following:
    find . -type f -links +1
    This lists the names of the ordinary files (-type f) that have more than one link (-links +1).
    Note: Every directory has at least two links: the entry in its parent directory and its own .(dot) entry. For more information on multiple file links, see the ln command.
  • To search for all files that are exactly 414 bytes in length, type the following:
    find . -size 414c 

See the find command in the Commands Reference, Volume 2 for the complete syntax.