Recursive Grep by file type
ripgrep is a recursive searching utility for searching through files for contents, much like grep does. In this example, I use ripgrep or rg to recursively search for any file in my django application that contains the work import and return the file and what is imported.
The -t flag is used to specify python files.
rg "import" -t py
manage.py 3:import os 4:import sys 10: from django.core.management import execute_from_command_line 13: "Couldn't import Django. Are you sure it's installed and " notes/wsgi.py 10:import os 12:from django.core.wsgi import get_wsgi_application notes/asgi.py 10:import os 12:from django.core.asgi import get_asgi_application testing_views/views.py 1:from django.shortcuts import render 2:from django.views.generic import TemplateView, DetailView, ListView 3:from .models import * 5:from django.db.models import Q
Note that the output returns both the file, line number of the import and the import full text