I normally use this style of command to run grep
over a number of files:
find / -xdev -type f -print0 | xargs -0 grep -H "800x600"
What this actually does is make a list of every file on the system, and then for each file, execute grep
with the given arguments and the name of each file.
The -xdev
argument tells find that it must ignore other filesystems - this is good for avoiding special filesystems such as /proc
. However it will also ignore normal filesystems too - so if, for example, your /home folder is on a different partition, it won't be searched - you would need to say find / /home -xdev ...
.
-type f
means search for files only, so directories, devices and other special files are ignored (it will still recurse into directories and execute grep
on the files within - it just won't execute grep
on the directory itself, which wouldn't work anyway). And the -H
option to grep
tells it to always print the filename in its output.
find
accepts all sorts of options to filter the list of files. For example, -name '*.txt'
processes only files ending in .txt. -size -2M
means files that are smaller than 2 megabytes. -mtime -5
means files modified in the last five days. Join these together with -a for and and -o for or, and use '('
parentheses ')'
to group expressions (in quotes to prevent the shell from interpreting them). So for example:
find / -xdev '(' -type f -a -name '*.txt' -a -size -2M -a -mtime -5 ')' -print0 | xargs -0 grep -H "800x600"
Take a look at man find
to see the full list of possible filters.
Permission denied
errors? Did you run it as root or a normal user?grep -r 800x600 / 2>/dev/null
. You can also try running it as root.