Using the grep utility to search through source code can take a long time when you are searching for certain text. But this can be made easier if you use grep.
The command below:
grep -rn --include "*.*" "winlogon" . |
Will search recursively through a source code tree and find what you are looking for.
This is part of the output when searching a very large source code tree.
┌──[jason@192.168.1.2]─[~/Downloads/NOTREPACKED/nt5src/XPSP1] └──╼ ╼ $ grep -rn --include "*.*" "winlogon" . ./tools/x86/perl/site/lib/win32/tieregistry.pm:2151: $tip18= $winlogon->{"/18"}; ./tools/postbuildscripts/swapinoriginalfiles.cmd:55:set SwapList=%SwapList% winlogon.exe licdll.dll licwmi.dll ./tools/postbuildscripts/swapinoriginalfiles.cmd:58:set SwapSymbolExeList=winlogon.pdb ./tools/postbuildscripts/scp_wpafiles.cmd:96:REM For non-version specific WPA binaries (e.g. licwmi, licdll, winlogon); ./tools/postbuildscripts/scp_wpafiles.cmd:409:set SKUIndependentExes=winlogon ./tools/spfiles.txt:1460: winlogon.exe ./tools/sp/data/catalog/fr/ia64fre/nt5.hash:1957:d:\relbins.ia64fre\fr\winlogon.exe - 12A403F3A3CF99D53BA47148C440858AC299EACB ./tools/sp/data/catalog/fr/x86fre/nt5.hash:1518:d:\relbins.x86fre\fr\winlogon.exe - 7F3198D4D33A59FD23C47675390E2F102D3401DF ./tools/sp/data/catalog/ara/x86fre/nt5.hash:1513:f:\nt2.relbins.x86fre\ara\winlogon.exe - 42180C0C9DD44B0F8C9225E9B2B65CF7A031B709 ./tools/sp/data/catalog/ru/x86fre/nt5.hash:1514:d:\relbins.x86fre\ru\winlogon.exe - C1AB4B514A1001E9218EC3842F4E8EE5E4B8FE90 ./tools/sp/data/catalog/kor/x86fre/nt5.hash:1533:f:\nt2.relbins.x86fre\KOR\winlogon.exe - 2CA04A67CD8A5BB0BAC7EC89DBB1FEBC45D24000 ./tools/sp/data/catalog/nl/x86fre/nt5.hash:1517:d:\relbins.x86fre\nl\winlogon.exe - B94D13DCF108215AA0C6710BECE726A21CB969A3 ./tools/sp/data/catalog/sv/x86fre/nt5.hash:1515:d:\relbins.x86fre\sv\winlogon.exe - ABE61280B0229D5103E954018FCB9AFCF997E081 ./tools/sp/data/catalog/chs/x86fre/nt5.hash:1536:f:\nt2.relbins.x86fre\chs\winlogon.exe - E36C60DB0AB59B0D83828B5214F55F057D61513B ./tools/sp/data/catalog/heb/x86fre/nt5.hash:1514:f:\nt2.relbins.x86fre\heb\winlogon.exe - 08715640E1B1D06AFD7848F27B0E45CE3771C1BC ./tools/sp/data/catalog/pt/x86fre/nt5.hash:1513:d:\relbins.x86fre\pt\winlogon.exe - 12A291F3EC34DD44D40FCC782F9583B33B014249 ./tools/sp/data/catalog/it/x86fre/nt5.hash:1516:d:\relbins.x86fre\It\winlogon.exe - 73E09E30D94BD0AAC558B2FBC5D86568A4D131C3 ./tools/sp/data/catalog/chh/x86fre/nt5.hash:1548:f:\nt2.relbins.x86fre\chh\winlogon.exe - 76EDB2BDD0433033BD670783313F3F24F6453D6D ./tools/sp/data/catalog/hu/x86fre/nt5.hash:1515:d:\relbins.x86fre\hu\winlogon.exe - 28E210B5C1CD3E3C9EDE52A479B1842D2C2F17B3 |
This shows how easy it is to find what you are looking for.
Or to search in certain files. Just use the *.doc wildcard for example.
┌──[jason@192.168.1.2]─[~/Downloads/NOTREPACKED/nt5src/XPSP1] └──╼ ╼ $ grep -rn --include "*.doc" "winlogon" . Binary file ./ds/security/services/scerpc/specs/scts_design.doc matches Binary file ./ds/security/csps/wfsccsp/winpwrdsc.doc matches Binary file ./ds/security/gina/gpdas/rsopschema.doc matches Binary file ./admin/netui/shell/doc/ntnp.doc matches Binary file ./sdktools/systrack/systrack.doc matches Binary file ./sdktools/memsnap/memsnap.doc matches Binary file ./windows/appcompat/doc/debugtricks.doc matches Binary file ./base/ntsetup/textmode/kernel/upgrade.doc matches Binary file ./base/fs/rdr2/csc/csc.doc matches |
This allows you to find the text you seek very quickly.
This is another way, using the find command and filtering the output with grep.
┌──[jason@192.168.1.2]─[~/Downloads/NOTREPACKED/nt5src/XPSP1] └──╼ ╼ $ find . -type f -print0 | xargs -0 grep -n "desktop resolution" ./shell/osshell/control/scrnsave/d3dsaver/d3dsaver.cpp:1300: // Try to find mode matching desktop resolution and 32-bpp. Binary file ./multimedia/directx/dxg/ddk/help/d3d8funcspec81.doc matches ./admin/activec/conui/ocxview.cpp:855: * get the desktop resolution ./drivers/video/ms/3dlabs/perm2/disp/ddsurf.c:297:// of the desktop resolution/requested depth. ./windows/advcore/gdiplus/engine/entry/initialize.cpp:603: // Get the multimon meta-desktop resolution. SM_CX/CYVIRTUALSCREEN |
This returns matching files and tells me what line the text is on. This is very useful for a programmer.
Or it can even be colourful, this is easier to read. The –color=always parameter to grep will force a colourful output and highlight matching lines.
┌──[jason@192.168.1.2]─[~/Downloads/NOTREPACKED/nt5src/XPSP1] └──╼ ╼ $ find . -type f -print0 | xargs -0 grep --color=always -n "administrator" Binary file ./tools/x86/sd.exe matches Binary file ./tools/x86/sdclient.exe matches ./tools/x86/perl/bin/perlbug.bat:193: # Possible administrator addresses, in order of confidence ./tools/x86/perl/bin/perlbug.bat:309: # Prompt for administrator address, unless an override was given ./tools/x86/perl/bin/perlbug.bat:313:perl administrator. If the address is wrong, please ./tools/x86/perl/bin/perlbug.bat:317: print "Local perl administrator [$cc]: "; ./tools/x86/perl/bin/perlbug.bat:739: -C Don't send copy to administrator. ./tools/x86/perl/bin/perlbug.bat:956:Don't send copy to administrator. ./tools/x86/perl/bin/perlbug.bat:961:local perl administrator (recorded when perl was built). ./tools/x86/perl/bin/pod2man.bat:87:miscellaneous information, and 8 for administrator commands. This works ./tools/x86/perl/lib/pod/perl5004delta.pod:861:change is intended to allow administrators to keep the Perl 5.004 ./tools/x86/perl/lib/pod/perlfaq1.pod:20:These strengths make it especially popular with system administrators ./tools/x86/perl/lib/pod/perllocale.pod:47:your system administrator, must make sure that this is the case. The ./tools/x86/perl/lib/pod/perllocale.pod:52:supplier. Still others allow you or the system administrator to define ./tools/x86/perl/lib/pod/perllocale.pod:321:the help of your friendly system administrator. ./tools/x86/perl/lib/pod/perllocale.pod:356:Contact a system administrator (preferably your own) and report the exact ./tools/x86/perl/lib/pod/perlrun.pod:196:can't be done, system administrators are strongly encouraged to put ./tools/x86/perl/lib/pod/perldiag.pod:3013:administrator have set up the so-called variable system but Perl could ./tools/x86/perl/lib/pod/perldelta.pod:947:administrator have set up the so-called variable system but Perl could ./tools/x86/perl/lib/pod/perlxstut.pod:723:or ask your system administrator to run the make for you. ./tools/x86/perl/lib/config.pm:4495:Electronic mail address of the perl5 administrator. ./tools/x86/perl/site/lib/win32/netadmin.pm:300:account name for the administrator account if it is renamed or localized. ./tools/x86/perl/site/lib/win32/test.pl:6:# DSN (Data Source Name) by the ODBC administrator, then give this a try! Binary file ./tools/x86/managed/urt/v1.0.3705/system.windows.forms.dll matches Binary file ./tools/x86/managed/urt/v1.0.3705/system.web.dll matches ./tools/x86/managed/urt/v1.0.3705/system.messaging.xml:3014: cursor, application, or the system administrator has already removed the message Binary file ./tools/x86/managed/urt/v1.0.3705/mscorcfg.dll matches Binary file ./tools/x86/mkerrtbl.exe matches Binary file ./tools/ia64/sdclient.exe matches Binary file ./tools/ia64/mkerrtbl.exe matches |
This works very well. This is how easy it is to search through a lot of files and find what you are looking for in a huge source code tree. This will save your sanity.
Another example.
┌──(john㉿DESKTOP-PF01IEE)-[/mnt/c/Users/Intel i5/Desktop/downloads/GPU/integ/gpu_drv/stage_rel] └─$ find . -type f -print0 | xargs -0 grep --color=always -n "thermalViolation" ./apps/dcgm/dcgmi/Policy.cpp:420: std::cout << "Temperature: " << callbackResponse->val.thermal.thermalViolation << std::endl; ./apps/dcgm/dcgmi/ProcessStats.cpp:469: cmdView.addDisplayParameter(DATA_INFO_TAG, HelperFormatPercentTime(totalTime ,jobInfo->thermalViolationTime)); ./apps/dcgm/dcgmi/ProcessStats.cpp:792: cmdView.addDisplayParameter(DATA_INFO_TAG, HelperFormatPercentTime(totalTime ,pidInfo->thermalViolationTime)); ./apps/dcgm/dcgmlib/dcgm_structs.h:1508: unsigned int thermalViolation; //!< Temperature reached that violated policy ./apps/dcgm/dcgmlib/dcgm_structs.h:1901: long long thermalViolationTime; //!< Number of microseconds we were at reduced clocks due to thermal violation ./apps/dcgm/dcgmlib/dcgm_structs.h:1977: long long thermalViolationTime; //!< Number of microseconds we were at reduced clocks due to thermal violation ./apps/dcgm/dcgmlib/src/NvcmHostEngineHandler.cpp:3899: pidInfo->summary.thermalViolationTime = DCGM_INT64_NOT_SUPPORTED; ./apps/dcgm/dcgmlib/src/NvcmHostEngineHandler.cpp:4083: singleInfo->thermalViolationTime = i64Val; ./apps/dcgm/dcgmlib/src/NvcmHostEngineHandler.cpp:4086: if(!DCGM_INT64_IS_BLANK(pidInfo->summary.thermalViolationTime)) ./apps/dcgm/dcgmlib/src/NvcmHostEngineHandler.cpp:4087: pidInfo->summary.thermalViolationTime += i64Val; ./apps/dcgm/dcgmlib/src/NvcmHostEngineHandler.cpp:4089: pidInfo->summary.thermalViolationTime = i64Val; ./apps/dcgm/dcgmlib/src/NvcmHostEngineHandler.cpp:4362: pJobInfo->summary.thermalViolationTime = DCGM_INT64_NOT_SUPPORTED; ./apps/dcgm/dcgmlib/src/NvcmHostEngineHandler.cpp:4648: singleInfo->thermalViolationTime = i64Val; ./apps/dcgm/dcgmlib/src/NvcmHostEngineHandler.cpp:4651: if(!DCGM_INT64_IS_BLANK(pJobInfo->summary.thermalViolationTime)) ./apps/dcgm/dcgmlib/src/NvcmHostEngineHandler.cpp:4652: pJobInfo->summary.thermalViolationTime += i64Val; ./apps/dcgm/dcgmlib/src/NvcmHostEngineHandler.cpp:4654: pJobInfo->summary.thermalViolationTime = i64Val; grep: ./apps/dcgm/doc/DCGM_API_Reference_Guide.pdf: binary file matches ./apps/dcgm/modules/policy/DcgmPolicyManager.cpp:407: thermalResponse.thermalViolation = gpuTemp; ./apps/dcgm/testing/python/dcgm_structs.py:973: ("thermalViolation", c_uint) # Temperature reached that violated policy ./apps/dcgm/testing/python/dcgm_structs.py:1217: ('thermalViolationTime', c_int64), ./apps/dcgm/testing/python/dcgm_structs.py:1274: ('thermalViolationTime', c_int64), ./apps/dcgm/testing/python/tests/test_field_values.py:700: assert jobInfo.summary.thermalViolationTime >= jobInfo.gpus[0].thermalViolationTime, "thermal violation time in the job stat summary %d is less than the one stored in a gpu Info %d" %\ ./apps/dcgm/testing/python/tests/test_field_values.py:701: |
Another example. This is to find a word surrounded by spaces.
┌──(john㉿DESKTOP-PF01IEE)-[/mnt/c/Users/Intel i5/Desktop/downloads/GPU/integ/gpu_drv/stage_rel] └─$ find . -type f -print0 | xargs -0 grep --color=always -n " 3080 " ./apps/nvml/testing2/apps/lspci/Linux-aarch64/share/pci.ids:2249: 1462 3080 R9 290X Gaming ./apps/nvml/testing2/apps/lspci/Linux-ppc64le/share/pci.ids:2249: 1462 3080 R9 290X Gaming ./apps/nvml/testing2/apps/lspci/Linux-x86/share/pci.ids:2249: 1462 3080 R9 290X Gaming ./apps/nvml/testing2/apps/lspci/Linux-x86_64/share/pci.ids:2249: 1462 3080 R9 290X Gaming ./apps/nvml/testing3/apps/lspci/Linux-ppc64le/share/pci.ids:2249: 1462 3080 R9 290X Gaming ./apps/nvml/testing3/apps/lspci/Linux-x86/share/pci.ids:2249: 1462 3080 R9 290X Gaming ./apps/nvml/testing3/apps/lspci/Linux-x86_64/share/pci.ids:2249: 1462 3080 R9 290X Gaming ./apps/nvn/nvntest/shaderc/third_party/glslang/glslang/MachineIndependent/glslang_tab.cpp:9027:#line 3080 "glslang.y" /* yacc.c:1646 */ ./apps/nvn2/nvn1x/nvntest/shaderc/third_party/glslang/glslang/MachineIndependent/glslang_tab.cpp:9027:#line 3080 "glslang.y" /* yacc.c:1646 */ |