e******d 发帖数: 310 | 1 If I want to show all *.cpp files in the current dir tree, the following
command can be used
================
find ./ -name "*\.cpp"
================
If I want to show all *.h and *.cpp files in the current dir tree in one command, what should be used? I tried the following command, it does not work,
=====================
find ./ -name "*\.(h|cpp)"
====================
If I want to grep all *.h and *.cpp files for text "xxx" in the current dir tree in one command, what command should be used?
=====================
grep -r "xxx" "*\.(h|cpp)" #### bad command
grep -r "xxx" * ### in addition to *.h and *.cpp files, this command
also searches other files.
======================
Thank you a lot. |
e**t 发帖数: 358 | 2 find . -regex '.*\.\(h\|cpp\)'
find . -regex '.*\.\(h\|cpp\)' -exec grep xxx {} + |
v*****r 发帖数: 1119 | 3 1. Find
find ./ -name "*.cpp" -o -name "*.h"
2. Grep
grep -r "xxx" *.cpp *.h |
e******d 发帖数: 310 | 4
Thank you so much. The second command pipes find and grep together. Can we
just use grep command?
【在 e**t 的大作中提到】 : find . -regex '.*\.\(h\|cpp\)' : find . -regex '.*\.\(h\|cpp\)' -exec grep xxx {} +
|
e******d 发帖数: 310 | 5 Thank you a lot
what does option "-o" mean?
it seems this command does not work
【在 v*****r 的大作中提到】 : 1. Find : find ./ -name "*.cpp" -o -name "*.h" : 2. Grep : grep -r "xxx" *.cpp *.h
|
v*****r 发帖数: 1119 | 6 -o = OR
I was wrong on the grep, didn't notice it is -r option, you will have to
combine find and grep in your case.
【在 e******d 的大作中提到】 : Thank you a lot : : what does option "-o" mean? : it seems this command does not work
|