How to Use Grep to Find Files

The "grep" command is a small terminal application included in almost all Linux, BSD and UNIX distributions. It makes use of these operating systems' ability to chain commands together and pipe the output of one into another. Grep is a generic utility which searches the previous command, file or directory list's output for a regular expression and prints all matching results. Grep can be used to find files recursively through all directories on your system.

Instructions

    • 1

      Log in to your system with an account that has sufficient privileges to view all files and folders your file(s) may be located in.

    • 2

      Open a new terminal window. This process is different for each system, but typically it can be found in the "Applications" or "Utilities" menu of your window manager.

    • 3

      Change your working directory to the directory you want to begin the search in. For example, type "cd /" to look at all connected system devices, or type "cd ~/Desktop" to look only at your desktop.

    • 4

      Begin entering your command by typing "grep -lr" into the terminal. This tells grep it will list only file names and will recursively search all subdirectories it encounters.

    • 5

      Complete the command by specifying the pattern, which is also known as a regular expression. For example, to search words only starting with "report" type, including quotes: grep -lr "report.*"

    • 6

      Try different patterns. To search for multiple files named "bill" or "frank" or "joe," type, including quotes:

      grep -r "bill\|frank\|joe"

Tips & Warnings

  • Review the complete grep regular expression syntax if you require more complex assignment at the grymoire.com regular expressions website.

Related Searches:

References

Resources

Comments

You May Also Like

Related Ads

Featured