Softpanorama
(slightly skeptical) Open Source Software Educational Society

May the source be with you, but remember the KISS principle ;-)

Softpanorama Search

Unix find tutorial

Prev | Contents | Next

Part 11: Summary

Clearly, your use of the UNIX find command is limited only by your knowledge and creativity.

The find command has a lot of options, and to get the full power out of find, xargs, and grep, you need to experiment.

Among other things you can specify:

Selected Examples

Option Meaning Example
-atime n

-atime +n

-atime -n

-size

True if file was accessed n 24-hour periods (days) ago (n), accessed more then n 24-hour periods (days) ago(+n) or less than n 24-hour periods (days) ago (-n)
  • -mtime +7 Matches files modified more than 7 24-hour periods (days) ago
  • -atime -2 Matches files accessed less than 2 24-hour periods (days) ago
  • -size +100 Matches files larger than 100 blocks (50K)
-ctime n True if the file was created n 24-hour periods (days) ago. find . -ctime +30 -type f -exec rm {} ';'
-exec command Execute command. find . -mtime -2 -type f -exec mv {} ../Spam_collector \;
-mtime n True if file was modified n 24-hour periods (days) ago. find . -mtime -2 -type f -exec mv {} ../Spam_collector \;
-name pattern True if filename matches pattern.
-print Print names of files found.
-type c True if file is of type c find . -mtime -2 -type f -exec mv {} ../Spam_collector \;
-user name True if file is owned by user name.

Multiple options are joined by AND by default. OR may be specified with the -o flag and the use of grouped parentheses. For example, to match all files modified more than 90 24-hour periods (days) ago or accessed more than 30 24-hour periods (days) ago, use

\( -mtime +90 -o -atime +30 \)

NOT should be specified with a backslash before exclamation point. For example, to match all files ending in .txt except the file starting with "a-z", use:

\! -name "[a-z]*" -name "*.txt"

Prev | Contents | Next



Copyright © 1996-2009 by Dr. Nikolai Bezroukov. www.softpanorama.org was created as a service to the UN Sustainable Development Networking Programme (SDNP) in the author free time. Submit comments This document is an industrial compilation designed and created exclusively for educational use and is placed under the copyright of the Open Content License(OPL). Site uses AdSense so you need to be aware of Google privacy policy. Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.

Disclaimer:

Created: May 16, 1997; Last modified: August 25, 2009