Maciej A. Czyzewski Blog Talks About

Finding files, right way using command-line utility...

Posted on

Have you ever saved, moved, or copied a file, script, document, then been unable to find it?

Maybe you saved it in a different directory, with an unusual name
or magic unicorns stole it, it’s definitely time to learn find utility

Command

The find utility recursively descends the directory tree for each path listed, evaluating an expression (composed of the “primaries” and “operands”) in terms of each file in the tree.

Old files ;-)

Search a folder hierarchy for filename(s) that meet a desired criteria: name, size, file, type…

usage: find [-H | -L | -P] [-EXdsx] [-f path] path ... [expression]
       find [-H | -L | -P] [-EXdsx] -f path [path ...] [expression]

Basics

To find all files on a computer named “mysecretfile.py”, just type:

It’s possible that you will see Permission denied, you should then call this command as root…

$ find / -name 'mysecretfile.py'

Command below will show all files in your home directory modified or created today, by default, find counts days from midnight, so an age of 0 means today, -1 means yestarday, -30 means month ago, etc.

$ find ~ -type f -mtime 0

You may have used the -iname option with find before, but it can do lots more. These options can be combined, so if that elusive download was an python file, you could narrow the search with:

$ find ~ -type f -mtime 0 -iname '*.py'

To find files and directories that are not owned by you, use:

$ find ~ ! -user ${USER}

More

For more information just type in your console man find, or visit this page.