Tips & Tricks


This can be easily achieved using grep command.

Here are a couple of examples :

$ grep -l “printf” *.c
bfrovrflw.c
bufrovrflw.c
Cfile.c
cmd.c
env.c
file.c
helloworld.c
macro.c
main.c
my_fopen.c
my_printf.c
new_printf.c
prog.c
stacksmash.c
test_strace.c

$ grep -l “buff” *.c
bfrovrflw.c

If it is desired to view the lines where the string is used in the file, then ‘find’ command can be used with ‘xargs’ and ‘grep’ command in the following way :

$ find ./ -name “*.c” | xargs grep “buff”
./bfrovrflw.c: char buff[15];
./bfrovrflw.c: gets(buff);
./bfrovrflw.c: if(strcmp(buff, “MyLinuxBook”))

So we see that even the lines containing the string “buff” were displayed in the output.

Go Back to Menu