Posted: . At: 7:17 PM. This was 4 years ago. Post ID: 14265
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.


How to find matching files when using grep to search for files containing text.


The grep utility is very useful when searching for text in files. This can be used recursively to find matching files. This tip will return the full path to all files containing the text you are looking for.

4.4 Thu Apr 23 jason@Yog-Sothoth 1: $ grep -r -H "noclip"

This is an example of the output of this grep one-liner.

4.4 Thu Apr 23 jason@Yog-Sothoth 1: $ grep -r -H "noclip"
public/togl/glmgr.h:	if (CommandLine()->FindParm("-caps_noclipplanes"))
engine/cmd.h:// things like godmode, noclip, etc, are commands directed to the server,
engine/sv_main.cpp:extern ConVar *sv_noclipduringpause;
engine/sv_main.cpp:    sv_noclipduringpause = ( ConVar * )g_pCVar->FindVar( "sv_noclipduringpause" );
engine/sv_main.cpp:    bool bSendDuringPause = sv_noclipduringpause ? sv_noclipduringpause->GetBool() : false;
engine/sys_dll.cpp:ConVar *sv_noclipduringpause = NULL;
engine/sys_dll.cpp:	sv_noclipduringpause = NULL;
engine/sys_dll.cpp:	sv_noclipduringpause = NULL;
engine/mod_vis.cpp:		// When noclip is enabled, we can't use this optimization because we're outside of the world 
game/server/player_command.cpp:extern ConVar sv_noclipduringpause;
game/server/player_command.cpp:		// If no clipping and cheats enabled and noclipduring game enabled, then leave
game/server/player_command.cpp:			 sv_noclipduringpause.GetBool() )

This shows the complete path to each file from the current working directory. This is a very useful way to find files containing certain strings.

This is another method using the find command. This will find all files containing the word noclip.

4.4 Thu Apr 23 jason@Yog-Sothoth 1: $ find . -type f \( -name *.c -o -name *.txt -o -name *.h \) -exec grep "noclip" /dev/null {} \;
./public/togl/glmgr.h:	if (CommandLine()->FindParm("-caps_noclipplanes"))
./engine/cmd.h:// things like godmode, noclip, etc, are commands directed to the server,
./game/server/cstrike15/cs_player.h:	// Each state has a well-defined set of parameters that go with it (ie: observer is movetype_noclip, nonsolid,
./game/shared/movevars_shared.h:extern ConVar sv_noclipaccelerate;
./game/shared/movevars_shared.h:extern ConVar sv_noclipspeed;
./game/shared/movevars_shared.h:extern ConVar sv_specnoclip;
./game/shared/gamemovement.h:	// Handle movement in noclip mode.
./game/shared/shareddefs.h:	EFL_NOCLIP_ACTIVE =			(1<<2),	// Lets us know when the noclip command is active.

it is also how to specify multiple file extensions to look for.


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.