Home » Questions » Computers [ Ask a new question ]

Grep on the whole server in Ubuntu

Grep on the whole server in Ubuntu

I need to use the grep facility on the whole server.

Asked by: Guest | Views: 36
Total answers/comments: 3
Guest [Entry]

sudo find / -type f -print0 |xargs -0 grep -l 'MyString'
Guest [Entry]

"cd /
grep -R 'your string' *"
Guest [Entry]

"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'"