The MonadLUG Man Page of the Month was presented by RayCote on find:

MonadLUG man page of the month presentation: find
14 September 2006

What is find? 

Find searches a directory tree for files and/or directories that meet the specified criteria. Find is available on Linux, Unix, and Mac OS X. It first appeared in Version 1 of AT&T Unix.

Simplest example: find everything in this directory or below:
    find . 
Default behaviors of find are different on different OSs or distributions. 
Single biggest default behavior difference is whether or not you get a list of ofund files when you run "find .". If no files appear (and you think you should see some) try "find . -print".

Look at the order in which the directory tree just appeared. You'll see the directory name before you see the files in that directory. If you want to see all the files in a directory before you see the directory iteself, run: 
    find -d . 
This is a depth-first search.

Find a specific file: 
    find . -name camera.gif
Note you need to first tell find where to start, and then what to find. 

Find supports regular expressions: 
    find . -name *.dat
    find . -name \*.dat
Some shells require the shell wildcard character be escaped. Otherwise, the shell will expand the filename before it is handed off to find. 

Find only files, not directories:
    find . -type f
Find directories, not files:
    find . -type d

Find files that do not match a pattern:
    find . ! -name *.dat
Find files changed in the last five minutes:
    find . -type f -mmin -5
Find files changed in the last 24 hours
    find . -mtime 0
    find . -mtime -1
Find files changed more than 24 hours ago:
    find . -mtime +1
Find files modified between 24 and 48 hours ago
    find . -mtime 1
When specifying time with find options such as -mmin (minutes) or -mtime (24 hour periods, starting from now), use "n" to mean exactly n, "-n" to mean less than n, and "+n" to mean more than n. 

Find non-hidden (no loading dot) files in the current directory only (no subdirectories) with an arbitrary output format (see the man page for the dozens of possibilities with the -printf action):
    find . -maxdepth 1 -name '[!.]*' -printf 'Name: %16f Size: %6s\n'
    (did not work on OS X, worked on Slackware)
You can execute a command on each file/directory found. 
Change write permission on all files that match a pattern:
    find . -name *.dat -exec chmod +w {} ';'
Delete old files. Useful for deleting old log files.
    find . -name "*.log" -mtime -10 -delete
Refer to your friendly man page or Google for
    linux find tutorial
for lots of information.

Presented by Ray Côté
Appropriate Solutions, Inc.
"We build software."
14 September 2006

-- TedRoche - 27 Nov 2006
Topic revision: r1 - 2006-11-27 - TedRoche

All content is Copyright © 1999-2024 by, and the property of, the contributing authors.
Questions, comments, or concerns? Contact GNHLUG.
All use of this site subject to our Legal Notice (includes Terms of Service).