Skip to main content

pyf: programmers find

Project description

It’s pronounced “pif”.

pyf [options] [search-pattern [filename-pattern [start-directory]]]

Recursively search for files whose contents matches search-pattern.

  • Optionally restrict the search to files whose name matches filename-pattern.
  • Optionally chdir to start-directory before starting the search.
  • Patterns are Python regular expressions.

Written because I got tired of writing:

find . -name '*.py' -exec egrep -l regex {} \;

The above with pyf would be:

pyf regex '\.py$'


pyf regex 'py$'

or just

pyf regex py

If you don’t pass in a regex as the file name pattern, pyf assumes it is a file extension match and adds a $ on the end.

File name patterns and the search patterns inside of files are both Python regular expressions.


Find Files Containing A Regex

pyf regex

The above example will recursively find files and search for ‘regex’ in the file.

Restrict The Search To Certain File Extensions

pyf regex py

The above example will recursively find files whose name ends in ‘py’ and search for ‘regex’ in the file.

Finding Files Which Contain One Thing But Not Another

pyf post html | pyf -v -f - csrf_token

Above finds all files whose name ends in ‘html’ and contain ‘post’ but do not contain ‘csrf_token’.

Running A Command On A Matched File

pyf -r "sed -i '' -e 's/yajogo\.core\.debug/yajogo.core.logging/g'" 'yajogo\.core\.debug' py

Above finds files with extention ‘py’ that contain the string ‘yajogo.core.debug’ and runs a sed command on them.

Printing Regex Matches

pyf -s -m '\d+x\d+' html

Above will print all matches of the pattern ‘+x+’ in files whose names ends in ‘html’. The -s option suppresses printing of the filename for the match. The -m option causes the matched regex to be printed. So, with the above you might get an output like this:


We could pipe the output of this command to another program. For example:

pyf -s -m html '(\d+x\d+)' | sort | uniq

Would give us a sorted and unique list of matches:



pip install pyf-programmers-find


$ pyf -h
usage: pyf [options] [search-pattern [filename-pattern [start-directory]]]

pyf: programmers find

Recursively search for files whose contents matches search-pattern.
Optionally restrict the search to files whose name matches filename-pattern.
Patterns are Python regular expressions.

It's pronounced "pif".

positional arguments:
  search-pattern        Match this pattern in files.
  filename-pattern      Only search files whose name matches this pattern.
  start-directory       Change to this directory before findind and searching

optional arguments:
  -h, --help            show this help message and exit
  --version             show program's version number and exit
  --debug               Turn on debug logging.
  --debug-log FILE      Save debug logging to FILE.
  -c COUNT, --context COUNT
                        Show COUNT surrounding context lines of the matches.
                        Only makes sense when printing matched lines with the
                        -p option. Default 0.
                        Change to directory START_DIRECTORY before starting
                        the search. Can also be given as the third positional
                        Use SEARCH_PATTERN as the pattern to match in a file;
                        use when defining patterns beginning with -. Can also
                        be given as the first positional argument.
  -f FILE, --file FILE  File to search for a match. Instead of recursively
                        searching all files. Can be given multiple times. If
                        argument is - reads a list of files to match from
  -i, --ignore-case     Ignore case. Default False.
  -l, --line-number     Print the matching line number. Default False.
  -m, --matches         Print the matching regex group. Default False.
                        Recursively find files whose name matches
                        FILENAME_PATTERN. Only search in those files. Can also
                        be given as the second positional argument. Default:
  -p, --print-lines     Print the matching line. Default False.
  -r CMD, --run CMD     Run a program CMD for each matching file, passing the
                        path name of the matching file as an argument. Ignored
                        if the -p or -l options are given.
  -s, --no-filename     Do not print the file name when printing matched
                        lines. Only makes sense with the -p option. Default
  -v, --invert-match    Invert the sense of the match. Print non-matching
                        files and lines. Default False.
  -A, --suppress-file-access-errors
                        Do not print file/directory access errors.
  -B, --no-binary-check
                        Ignore (heuristic) binary file check, do not skip
                        probably binary files.
  -N, --no-pager        Do not pipe output to a pager when stdout it detected
                        as a tty.
  --force-pager         Always try to pipe output to a pager, do not check if
                        stdout is a tty. Ignored when running with the -r
  --skip-dirs-pattern SKIP_DIRS_PATTERN
                        Regex of directories to skip. Default
  --skip-files-pattern SKIP_FILES_PATTERN
                        Regex of files to skip. Default '(^\..+|\.pyc$)'.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pyf-programmers-find, version 0.9.0
Filename, size File type Python version Upload date Hashes
Filename, size pyf_programmers_find-0.9.0-py2.py3-none-any.whl (14.9 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size pyf-programmers-find-0.9.0.tar.gz (17.5 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page