Sunday, 18 October 2015

grep - Linux Command

Most of the general linux commands are available online but here i will be covering bit advance feature of some linux commands

grep

We use grep command to search contents in a file or directory.What will be command for searching only in specific extension files in a directory.Lets find out below
  • Recursively Search a pattern in all files of a directory use
        grep -R "Pattern to Search" /DirectoryPath
  • To Search a pattern only in files with specific extensions in a directory use
        grep -R --include=*.xml "Pattern to Search" /DirectoryPath
  • To Search a pattern in files with multiple extensions in a directory use
        grep -R --include=*.{xml,sh,html} "Pattern to Search" /DirectoryPath

  • Case insensitive Search of a pattern
        grep -iR  "Pattern to Search" /DirectoryPath

No comments:

Post a Comment