PDA

View Full Version : [ubuntu] searching for a string_



spillage2
November 22nd, 2012, 07:48 PM
Hi,

I have had a look around but couldnt find any info. Can you use the terminal to search all files on my o/s for a string. I have setup ssmtp but am sure there is a .conf file lurking about with the wrong settings in and I need to find it.

I'm sure it would only be in /etc but not sure how to search all files in /etc for "a_word".

Thanks,

Spill.

spillage2
November 22nd, 2012, 08:09 PM
should it just be
grep -R name_of_string /directory ????

spill.

Pletched
November 22nd, 2012, 08:22 PM
ls -aShows all files and folders in the current directory.


ls -a | grep STRINGPasses the output of ls to grep to search the current directory listing for STRING.

steeldriver
November 22nd, 2012, 08:28 PM
should it just be
grep -R name_of_string /directory ????

Should work fine - you might want to :


do it with 'sudo' if you think the string may be in a file that is read-protected
add '-I' to ignore binary files
add -i to make the match case insensitive


$ sudo grep -RIi name_of_string /etcIf you don't want to / can't use 'sudo' you can send all the error messages to null to keep the output readable


$ grep -RIi name_of_string /etc 2>/dev/null

spillage2
November 22nd, 2012, 08:28 PM
cheers but will this only look for file names and not a string within a document?

spill.

steeldriver
November 22nd, 2012, 08:36 PM
no, it will grep within each file recursively and highlight all the matches e.g.


$ grep -IRi WORKGROUP /etc 2>/dev/null
/etc/samba/smb.conf:# Change this to the workgroup/NT-domain name your Samba server will part of
/etc/samba/smb.conf: workgroup = WORKGROUP
/etc/bash_completion.d/samba: -W|--workgroup)
/etc/bash_completion.d/samba: --log-basename --workgroup' -- "$cur" ) )
/etc/bash_completion.d/samba: --username -p --password -w --workgroup -n --nonprompt -d \

spillage2
November 22nd, 2012, 08:58 PM
thanks steeldriver you must of posted just as i uploaded my last post..

just tried and worked a treat...well it did but i'm still none the wiser..php(mail) I aint.

Spill.

Resistent
November 22nd, 2012, 09:17 PM
Very helpful. Thank you a lot!!
I have many txt files and I often don't know where to search.