The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 15, 2019, 07:56:49 AM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: unix command shell question: how to find some text in a directory  (Read 3590 times)
jammaster82
Lifer
*****
Offline Offline

Posts: 666


Thats craigs list for ya


View Profile
« on: August 29, 2009, 07:23:36 PM »

ok, im trying to reverse engineer some code, i have
ssh access to the site dir and i would like to do a search
of a directory and _any_ subdirectory beneath it...

for instance in windows search you can search through
a directory it will go deep into all levels and you can
put a condition on the search ... for example files named
*.php that CONTAIN the word $didyoupassmath
for example.

How would you write the command to search a dir and subdirs for
*.php that contain the text $didyoupassmath ?

Logged

The watched pot, never boils... But if you walk away from it , the soup burns.  What gives?
nop_90
Global Moderator
Lifer
*****
Offline Offline

Posts: 2203


View Profile
« Reply #1 on: August 29, 2009, 08:42:34 PM »

grep -r "sometext u looking for" *

little more complex then that find the man page
i am not expert
Logged
vsloathe
vim ftw!
Global Moderator
Lifer
*****
Offline Offline

Posts: 1669



View Profile
« Reply #2 on: August 31, 2009, 06:07:20 AM »

You can use find and it would be quicker, but this is easier to understand:

Code:
grep -r '$didyoupassmath' *.php

or

Code:
cat *.php | grep 'didyoupassmath'
Logged

hai
jammaster82
Lifer
*****
Offline Offline

Posts: 666


Thats craigs list for ya


View Profile
« Reply #3 on: September 09, 2009, 08:24:41 PM »

wow.  thanks man!

Logged

The watched pot, never boils... But if you walk away from it , the soup burns.  What gives?
Phaėton
Lifer
*****
Offline Offline

Posts: 555


⎝⏠⏝⏠⎠


View Profile
« Reply #4 on: May 04, 2010, 11:30:46 AM »

Im trying to search recursively with:

grep -d recurse '$didyoupassmath' *.php

          ~and~
 
grep -r '$didyoupassmath' *.php


and i have a test file in the directory im running it from
and a subfolder with that in a file in the subfolder.

this command is only returning things for the directory im running
it from... doesnt the -r or -d recurse tell it to hunt through sub
dirs? what am i missing.. i read the man page for grep b4 i posted lol
i thought the -r would do it...?
Logged

When I was your age we used to walk to the TV to change the channel....  _̴ı̴̴̡̡̡ ̡͌l̡̡̡ ̡͌l̡*̡̡ ̴̡ı̴̴̡ ̡̡͡|̲̲̲͡͡͡ ̲▫̲͡ ̲̲̲͡͡π̲̲͡͡ ̲̲͡▫̲̲͡͡ ̲|̡̡̡ ̡ ̴̡ı̴̡̡
Phaėton
Lifer
*****
Offline Offline

Posts: 555


⎝⏠⏝⏠⎠


View Profile
« Reply #5 on: May 04, 2010, 11:39:43 AM »

tried it on two different servers and it behaved differently

is grep all fucked up? 

this ended up actually doing it:


grep -RH --include "*.php" $didyoupassmath *

Logged

When I was your age we used to walk to the TV to change the channel....  _̴ı̴̴̡̡̡ ̡͌l̡̡̡ ̡͌l̡*̡̡ ̴̡ı̴̴̡ ̡̡͡|̲̲̲͡͡͡ ̲▫̲͡ ̲̲̲͡͡π̲̲͡͡ ̲̲͡▫̲̲͡͡ ̲|̡̡̡ ̡ ̴̡ı̴̡̡
vsloathe
vim ftw!
Global Moderator
Lifer
*****
Offline Offline

Posts: 1669



View Profile
« Reply #6 on: May 04, 2010, 11:41:34 AM »

Im trying to search recursively with:

grep -d recurse '$didyoupassmath' *.php

          ~and~
 
grep -r '$didyoupassmath' *.php


and i have a test file in the directory im running it from
and a subfolder with that in a file in the subfolder.

this command is only returning things for the directory im running
it from... doesnt the -r or -d recurse tell it to hunt through sub
dirs? what am i missing.. i read the man page for grep b4 i posted lol
i thought the -r would do it...?

It has to do with specifying a file type...I think if you did it with just * instead of *.php it might behave. Otherwise try ./*.php
Logged

hai
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #7 on: May 04, 2010, 12:22:06 PM »

Great question and hot tip VS ... *.php always messes with my grepping as well, so I wind up doing a straight wild card. I'm gonna try both your solutions and see if i can do better at grokking grep's greatness.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
Phaėton
Lifer
*****
Offline Offline

Posts: 555


⎝⏠⏝⏠⎠


View Profile
« Reply #8 on: May 04, 2010, 02:48:50 PM »

Vs, you make my brain hurt.  Cheesy

Thanks!  good point... funny i tried the * and i was
doing a ' > results.txt' at the end and it kept
spitting the results into the file and then searching
the file , including the results recursively from results.txt
in the results and then i hit  ctrl-c  hahaha
Logged

When I was your age we used to walk to the TV to change the channel....  _̴ı̴̴̡̡̡ ̡͌l̡̡̡ ̡͌l̡*̡̡ ̴̡ı̴̴̡ ̡̡͡|̲̲̲͡͡͡ ̲▫̲͡ ̲̲̲͡͡π̲̲͡͡ ̲̲͡▫̲̲͡͡ ̲|̡̡̡ ̡ ̴̡ı̴̡̡
vsloathe
vim ftw!
Global Moderator
Lifer
*****
Offline Offline

Posts: 1669



View Profile
« Reply #9 on: May 05, 2010, 05:45:28 AM »

Vs, you make my brain hurt.  Cheesy

Thanks!  good point... funny i tried the * and i was
doing a ' > results.txt' at the end and it kept
spitting the results into the file and then searching
the file , including the results recursively from results.txt
in the results and then i hit  ctrl-c  hahaha

lol yeah might want to pipe the results somewhere else. >> appends instead of overwriting, btw.
Logged

hai
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!