[oracle@DB-Server admin]$ grep "v\$temp_space_header" *.sql
catspacd.sql:drop public synonym v$temp_space_header;
catspacd.sql:drop public synonym gv$temp_space_header;
catspace.sql:create or replace view v_$temp_space_header as select * from v$temp_space_header;
catspace.sql:create or replace public synonym v$temp_space_header for v_$temp_space_header;
catspace.sql:create or replace view gv_$temp_space_header as select * from gv$temp_space_header;
catspace.sql:create or replace public synonym gv$temp_space_header
catspace.sql: FROM gv$temp_space_header
[oracle@DB-Server admin]$
clip_image002
3:如果需要显示搜索文本在文件中的行数,可以使用参数-n
[oracle@DB-Server admin]$ grep -n "v\$temp_space_header" *.sql
catspacd.sql:68:drop public synonym v$temp_space_header;
catspacd.sql:71:drop public synonym gv$temp_space_header;
catspace.sql:1952:create or replace view v_$temp_space_header as select * from v$temp_space_header;
catspace.sql:1953:create or replace public synonym v$temp_space_header for v_$temp_space_header;
catspace.sql:1956:create or replace view gv_$temp_space_header as select * from gv$temp_space_header;
catspace.sql:1957:create or replace public synonym gv$temp_space_header
catspace.sql:2357: FROM gv$temp_space_header
[oracle@DB-Server admin]$
4: 如果搜索时需要忽略大小写问题,可以使用参数-i
[oracle@DB-Server admin]$ grep "V\$TEMP_SPACE_HEADER" *.sql
[oracle@DB-Server admin]$ grep -i "V\$TEMP_SPACE_HEADER" *.sql
catspacd.sql:drop public synonym v$temp_space_header;
catspacd.sql:drop public synonym gv$temp_space_header;
catspace.sql:create or replace view v_$temp_space_header as select * from v$temp_space_header;
catspace.sql:create or replace public synonym v$temp_space_header for v_$temp_space_header;
catspace.sql:create or replace view gv_$temp_space_header as select * from gv$temp_space_header;
catspace.sql:create or replace public synonym gv$temp_space_header
catspace.sql: FROM gv$temp_space_header
[oracle@DB-Server admin]$
另外,例如检查安装的MySQL组件
[oracle@DB-Server admin]$
[oracle@DB-Server admin]$ grep "v\$temp_space_header" *.sql
catspacd.sql:drop public synonym v$temp_space_header;
catspacd.sql:drop public synonym gv$temp_space_header;
catspace.sql:create or replace view v_$temp_space_header as select * from v$temp_space_header;
catspace.sql:create or replace public synonym v$temp_space_header for v_$temp_space_header;
catspace.sql:create or replace view gv_$temp_space_header as select * from gv$temp_space_header;
catspace.sql:create or replace public synonym gv$temp_space_header
catspace.sql: FROM gv$temp_space_header
[oracle@DB-Server admin]$ grep -c "v\$temp_space_header" catspacd.sql
2
[oracle@DB-Server admin]$ grep -c "v\$temp_space_header" catspace.sql
5
[oracle@DB-Server admin]$
clip_image003
[oracle@DB-Server admin]$ grep -w "ORA" utlspadv.sql
-- ORA-XXXXX: Monitoring already started. If for example you want
-- ORA-20111:
-- ORA-20112:
-- ORA-20113: 'no active monitoring job found'
-- ORA-20113: 'no active monitoring job found'
-- ORA-20111:
-- ORA-20112:
-- ORA-20100:
-- ORA-20113: 'no active monitoring job found'
-- ORA-20113: 'no active monitoring job found'
[oracle@DB-Server admin]$ grep "ORA" utlspadv.sql
-- ORA-XXXXX: Monitoring already started. If for example you want
-- ORA-20111:
-- ORA-20112:
-- ORA-20113: 'no active monitoring job found'
-- ORA-20113: 'no active monitoring job found'
-- 0 |<PS> =>DBS2.REGRESS.RDBMS.DEV.US.ORACLE.COM 0 0 2 99.3% 0% 0.7% ""
-- |<PR> DBS1.REGRESS.RDBMS.DEV.US.ORACLE.COM=> 100% 0% 0% "" |<PR> ...
-- =>DBS2.REGRESS.RDBMS.DEV.US.ORACLE.COM 92 7 99.3% 0% 0.7% "" |<PR> ...
-- |<C> CAPTURE_USER1=>DBS2.REGRESS.RDBMS.DEV.US.ORACLE.COM 2 0 0 0.E+00
-- |<C> CAPTURE_USER1=>DBS2.REGRESS.RDBMS.DEV.US.ORACLE.COM
-- ORA-20111:
-- ORA-20112:
-- ORA-20100:
-- ORA-20113: 'no active monitoring job found'
-- ORA-20113: 'no active monitoring job found'
[oracle@DB-Server admin]$
10: grep命令结合find命令搜索
[oracle@DB-Server admin]$ find . -name '*.sql' -exec grep -i 'v\$temp_space_header' {} \; -print
create or replace view v_$temp_space_header as select * from v$temp_space_header;
create or replace public synonym v$temp_space_header for v_$temp_space_header;
create or replace view gv_$temp_space_header as select * from gv$temp_space_header;
create or replace public synonym gv$temp_space_header
FROM gv$temp_space_header
./catspace.sql
drop public synonym v$temp_space_header;
drop public synonym gv$temp_space_header;
./catspacd.sql
[oracle@DB-Server admin]$