Table of Contents

Find

General Information

The GNU find utility and some useful parsing methods.

Checklist


General Syntax

The general syntax of find is:

find [options] [path] [expression]

The [options] allow for how to treat symbolic links, debugging, and optimization.
The defaults are almost always used. (see 'man find' if curious)

[path] is the directory in which you are starting the search.

[expression]s are made up of options that manipulate the operation of find.


Find Examples

Some of the useful find commands that have been “tested in production”.


Find folders with the most files

If you run into a situation in which you have high inode usage as seen by 'df -i', the following syntax will show folders with the most files:

nice find / -mount -printf '%h\n' | sort | uniq -c | sort -n -k 1

Explanation:

This will give output with the first column displaying file count and the second column displaying the folder it is in.

Example Output (last 5 lines):

   1814 /usr/bin
   1983 /usr/share/doc
   2075 /usr/share/man/man3
   2122 /usr/share/linuxmint/mintinstall/installed
   2123 /usr/share/linuxmint/mintinstall/icons

Find, starting in /, all files (type f) owned by rjones

find / -user rjones -type f

Remove all files owned by rjones

find / -user rjones -type f -exec rm '{}' \;

Find all files modified in the last 3 days

find / -mtime -3 -type f