3
1
I need to use the grep facility on the whole server.
I tried the following:
grep -r 'MyString' /
grep -r 'MyString' /*
However, none of these seem to work. Any suggestions?
3
1
I need to use the grep facility on the whole server.
I tried the following:
grep -r 'MyString' /
grep -r 'MyString' /*
However, none of these seem to work. Any suggestions?
1
sudo find / -type f -print0 |xargs -0 grep -l 'MyString'
5
sudo find / -type f -exec grep "Strring" {} \;
Are you SURE you want to do this though? This will traverse all filesystems (local or not) and may very well max out the CPU on your server.
1Throw sudo
in there so you can read all files and you'll have a winner! – Carl Smotricz – 2010-01-05T15:46:52.070
0
Install ack, which is packaged as ack-grep
in the Ubuntu repositories. It is like a supercharged combination of find and grep that does exactly what you want without messing around with combinations of commands.
$ sudo ack-grep -a 'MyString' /
The -a
option is used to override the default filtering behaviour of ack which limits the search to filetypes which it knows about. It will still exclude certain files and directories though, such as backup files that end in "~" or source control directories like ".svn". You can override this behaviour to search absolutely everything by using the -u
option.
To limit the search to particular file types:
$ sudo ack-grep -aG '.*txt' MyString
noting that the argument to -G
is a regex, not a glob.
Or for file types which ack knows about already, such as C++ files:
$ ack-grep --cpp 'SomeFunctionName'
0
cd /
find . | xargs grep MyString
If you're looking for particular file types:
find . -name *.java | xargs grep Integer
0
I second nont's approach.
But if your not root you'll get a whole bunch of permission denied messages, redirect those to /dev/null. Then you'll get what you want back.
find . / 2>/dev/null | xargs grep MyString 2>/dev/null
0
cd /
grep -R 'your string' *
What are you looking for? File or folder names? Contents of (text) files? – None – 2010-01-05T15:46:37.407
Define "don't work". They should certainly work. – None – 2010-01-05T15:48:27.177