Find: Difference between revisions

From Leo's Notes
This page was last edited on 4 May 2013, at 20:14.
Line 24: Line 24:
== Find by time ==
== Find by time ==
Basic usage:
Basic usage:
  find . '''-[a - accessed|c - created|m - modified][time|min]''' <time>
  find . -['''a''' - accessed|'''c''' - created|'''m''' - modified]['''time'''|'''min'''] <time>
 
where time is in days when used with time, or minutes when used with min.


To find files modified within 3 minutes ago:
To find files modified within 3 minutes ago:
  find . -mmin -3
  find . -mmin -3


To find a file accessed within 1 day ago:
To find files created within 1 day ago:
  find . -amin -1
  find . -cmin -1


== Do things on match ==
== Do things on match ==

Revision as of 20:14, 4 May 2013

find is one of those commands that can be quite arcane. Hopefully this article should clear things up with a brief list of basic uses.

One of the nice things with find is that you can chain multiple things together.

Find a specific type

Basic usage:

find . -type [f - file|d - directory|l - links]

To find only normal files:

find . -type f

To find both files and directories:

find . -type f -o -type d

Find by filename

Basic usage:

find . -name <term>

You may want to use -iname for case insensitivity.

To find a directory named 'backup' or 'Backup':

find . -iname backup -type d

Find by time

Basic usage:

find . -[a - accessed|c - created|m - modified][time|min] 

where time is in days when used with time, or minutes when used with min.

To find files modified within 3 minutes ago:

find . -mmin -3

To find files created within 1 day ago:

find . -cmin -1

Do things on match

Basic usage:

find . -exec

find . -iname "*.java" -exec sh -c 'iconv -f cp1252 -t utf-8 {} > {}.utf8' \;