find -- search for files in a directory hierarchy

  1. find can be used for many things and has many options and expressions.  This is simply an overview and list of the most common ones that DTO might use, as well as some other examples.
  2. Usage:  find [starting directory] [options] [filename] [expression]
    • Note:  -print is used by default if nothing is specified.
    • find / -name myfile
  3. Find examples
    • find / -perms 4755 -print
      • Find all set-user-id files on a *nix system.
    • find /opt -mtime -1 -print | cpio -pvmud /SAN1/backup/opt
      • Find all files in /opt that changed in the past day and copy them to /SAN1/backup/opt
    • find /home -executable -print > /tmp/home.exec.txt
      • Find all files in /home directory that are executable
    • find ${cdir} -mtime +8 -print -exec /usr/bin/mv {} ${cdir}/ARCHIVE \; >> ${log}
      • Find files that haven’t changed in last 8 days and move them to ARCHIVE directory
    • find ${cdir}/ARCHIVE -mtime +21 -print -exec /usr/bin/rm {} \; >> ${log}
      • Find files in ARCHIVE unchanged in 21 days, and remove them
    • find ${i} -depth -print | grep -v .tar | grep -v .gz | cpio -ocv > ${bufile}
      • Find files, including all subdirectories, except .tar and .gz files and create a cpio backup
    • find ${d7site} -depth -print -exec chown ${webuser}:${webgrp} \; >> ${log}
      • Find files in this directory and all subdirectories, print names and change ownership