How to search text throughout entire file system?

Level1Coder

Assuming that the grep tool should be used, I'd like to search for the text string "800x600" throughout the entire file system.

I tried:

grep -r 800x600 /

but it doesn't work.

What I believe my command should do is grep recursively through all files/folders under root for the text "800x600" and list the search results.

What am I doing wrong?

Richard Downer

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to search for broken links on the entire local file system of a server?

From Dev

Search throughout an chm file

From Dev

I completely messed up my entire file system permissions. I recovered, but how can I make sure my system is correct throughout?

From Dev

How to access a configuration object throughout the entire application?

From Dev

How to search entire hard drive for a file?

From Dev

Full text database search and attachments on file system

From Dev

To search entire file in a directory

From Java

How to search and replace text in a file?

From Dev

python search for string in file return entire line + next line into new text file

From Dev

How to implement search in file system in haskell?

From Dev

How to search for text files containing a text string on a linux system

From Dev

Search lines in text file for pattern between two positions and print entire row

From Dev

how to search for newline in text file using emacs

From Dev

How to properly pass text file to search the data there?

From Dev

How to search for a string in a text file using Qt

From Dev

How to search for a name from a text file

From Dev

How to search for text in file and display lines

From Dev

How to search for text in a file ignoring newlines?

From Dev

How to properly pass text file to search the data there?

From Dev

How to search a string and replace a string in text file?

From Dev

how to paginate search results from text file

From Dev

How to search a text file for a specific integer

From Dev

How to search each occurrence in a text file Linux?

From Dev

c# Add text to a file dynamically throughout program

From Dev

c# Add text to a file dynamically throughout program

From Dev

Firestore : How search in the entire database?

From Dev

How to search for a keyword in entire website

From Dev

How to read a text file for a specific word in lines and write the entire lines to another text file?

From Dev

Search all attributes in the entire DOM for text

Related Related

  1. 1

    How to search for broken links on the entire local file system of a server?

  2. 2

    Search throughout an chm file

  3. 3

    I completely messed up my entire file system permissions. I recovered, but how can I make sure my system is correct throughout?

  4. 4

    How to access a configuration object throughout the entire application?

  5. 5

    How to search entire hard drive for a file?

  6. 6

    Full text database search and attachments on file system

  7. 7

    To search entire file in a directory

  8. 8

    How to search and replace text in a file?

  9. 9

    python search for string in file return entire line + next line into new text file

  10. 10

    How to implement search in file system in haskell?

  11. 11

    How to search for text files containing a text string on a linux system

  12. 12

    Search lines in text file for pattern between two positions and print entire row

  13. 13

    how to search for newline in text file using emacs

  14. 14

    How to properly pass text file to search the data there?

  15. 15

    How to search for a string in a text file using Qt

  16. 16

    How to search for a name from a text file

  17. 17

    How to search for text in file and display lines

  18. 18

    How to search for text in a file ignoring newlines?

  19. 19

    How to properly pass text file to search the data there?

  20. 20

    How to search a string and replace a string in text file?

  21. 21

    how to paginate search results from text file

  22. 22

    How to search a text file for a specific integer

  23. 23

    How to search each occurrence in a text file Linux?

  24. 24

    c# Add text to a file dynamically throughout program

  25. 25

    c# Add text to a file dynamically throughout program

  26. 26

    Firestore : How search in the entire database?

  27. 27

    How to search for a keyword in entire website

  28. 28

    How to read a text file for a specific word in lines and write the entire lines to another text file?

  29. 29

    Search all attributes in the entire DOM for text

HotTag

Archive