返回首页   进站必读

1.19 find、grep


1.19.1 find

在目录中搜索文件,使用find命令

$find . -name 'chess.\*'
./chess.c

1.19.2 grep

在指定文件中搜索特定内容,并将含有这些内容的行输出到标准输出。若不指定文件名,则从标准输入读取。

$grep 'printf' ./ -R
./chess.c:30:        printf("\n  ");
./chess.c:32: printf(" %d", i + 1);
./chess.c:33: printf("\n");
./chess.c:35: printf(" -");
./chess.c:36: printf("\n");
./chess.c:39: printf("%d ", i + 1);
./chess.c:42: printf(" %d", chessboard[i][j]);
./chess.c:44: printf("\n");
./chess.c:115: printf("current: p1: %d, p2: %d.\n", p1, p2);
./chess.c:126: printf("Welcome!\n");
./chess.c:127: printf("Input link this, 3 3\n");
./chess.c:131: printf("Player %d: ", who);
./chess.c:140: printf("Board full!\n");
./chess.c:143: printf("Current step: %d\n", step);
./chess.c:146: printf("out of range or place
occupied!\n"
上面显示出了在chess.c里边所有包含printf关键字的行数及该行所有的内容。