由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Linux版 - A question about two linux commands
相关主题
求助, 为什么用find -exec 就没权限cp文件how to use sed command to replace ' into * ?
怎么看网络电视啊?ask one command in ubuntu
Grep 能作这个吗?The command line is powerful, but the UI can be more efficient!
问一个 Shell 的问题命令行迟迟不出来,请问高手是何原因?
教如何提取运行结果,用grep,awk等shell commandgrep 的很奇怪的现象
耗时很长的一个command不用安装的trash bin?
problem with "\"如何搜索installed package 如果不知道全名的话
发包子 echo 求助how to count a pattern in vi?
相关话题的讨论汇总
话题: cpp话题: command话题: grep话题: files话题: find
进入Linux版参与讨论
1 (共1页)
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

1 (共1页)
进入Linux版参与讨论
相关主题
how to count a pattern in vi?教如何提取运行结果,用grep,awk等shell command
请教一个script的问题耗时很长的一个command
bash "." commandproblem with "\"
any bash command option similar as perl -c to check the syn发包子 echo 求助
求助, 为什么用find -exec 就没权限cp文件how to use sed command to replace ' into * ?
怎么看网络电视啊?ask one command in ubuntu
Grep 能作这个吗?The command line is powerful, but the UI can be more efficient!
问一个 Shell 的问题命令行迟迟不出来,请问高手是何原因?
相关话题的讨论汇总
话题: cpp话题: command话题: grep话题: files话题: find