Apr 28, 2008

Find Man

List all files that belong to the user Simon:

find . -user Simon

List all the directory and sub-directory names:

find . -type d

List all files in those sub-directories (but not the directory names)

find . -type f

List all the file links:

find . -type l

List all files (and subdirectories) in your home directory:

find $HOME

Find files that are over a gigabyte in size:

find ~/Movies -size +1024M

Find files have been modified within the last day:

find ~/Movies -mtime -1

Find files have been modified within the last 30 minutes:

find ~/Movies -mmin -30

Find .doc files that also start with 'questionnaire' (AND)

find . -name '*.doc' -name questionnaire*

List all files beginning with 'memo' and owned by Simon (AND)

find . -name 'memo*' -user Simon

Find .doc files that do NOT start with 'Accounts' (NOT)

find . -name '*.doc' ! -name Accounts*

Search for files which have read and write permission for their owner,
and group, but which the rest of the world can read but not write to.

find . -perm 664

Files which meet these criteria but have other permissions bits set
(for example if someone can execute the file) will not be matched.

Search for files which have read and write permission for their owner,
and group, but which the rest of the world can read but not write to,
without regard to the presence of any extra permission bits
(for example the executable bit).

find . -perm -664

This will match a file which has mode 0777, for example.

Search for files which are writeable by somebody (their owner, or their group, or anybody else).

find . -perm +222
or
find . -perm +g+w,o+w
or
find . -perm +g=w,o=w

All three of these commands do the same thing, but the first one uses
the octal representation of the file mode, and the others use the symbolic form.
The files don't have to be writeable by both the owner and group to be matched; either will do.

Search for files which are writeable by both their owner and their group:

find . -perm -022
or
find . -perm -g+w,o+w

"Instead of getting married again, I'm going to find a woman I don't like and just give her a house." - Lewis Grizzard

Related Linux Bash commands:

fnmatch - Filename match
findutils documentation - 'Finding Files' doc with more detail on security considerations
grep - Search file(s) for lines that match a given pattern
locate - Find files - simple but fast
gawk - Find and Replace text within file(s)
xargs - Execute utility, passing constructed argument list(s)

Equivalent Windows XP command:
DIR /b /s - Display a list of files and (sub)folders

No comments: