Searching!!

There are many ways to search for content. Below are some of the effective ways to search for the content or file.

Using Grep

 grep -ri -C 2 -E 'password|user' <Folder or files name>
 
#  grep -Ei "credential|user|password|username|secure" *.ps1

# Example in which line number of matching value is displayed.
cat shell.php | grep -ni "changed this"
# Example:
# grep -ri -C 2 -E 'password|user' joomla/

Explanation of Options:

  • -r: Recursive search through directories.

  • -i: Case-insensitive search.

  • -C 2: Show 2 lines of context before and after matches.

  • -E: Enables extended regular expressions.

  • -n: Displays the line numbers of the matching lines.

According to your need, you can add or remove value inside the single quote separated by "|" sign.

Using Select-String & where-object

Select-String

"Task To Run.exe.": This regular expression matches lines containing "Task To Run" followed by any characters (.*), and then "exe".

We can use "-Context 0,1" to make the search easy.

"-Context 0,1:" Shows 0 lines before and 1 line after each match.

Where-Object

Common Operators

  1. -match: Matches a value using a regular expression (case-insensitive by default).

    • Example: $_.Name -match "pattern"

  2. -notmatch: Excludes values that match a regular expression.

    • Example: $_.Name -notmatch "pattern"

  3. -like: Matches a value using wildcards (* for multiple characters, ? for a single character).

    • Example: $_.Name -like "*value*"

  4. -notlike: Excludes values that match a wildcard pattern.

    • Example: $_.Name -notlike "*value*"

  5. -eq: Checks if a value is equal (case-insensitive for strings).

    • Example: $_.Status -eq "Active"

  6. -ne: Checks if a value is not equal.

    • Example: $_.Status -ne "Inactive"

Example from the command above:

  • $_ -notmatch "system32" checks if the current line/object does not contain system32.

  • $_ -notmatch "Next Run Time:\s+N/A" checks if the current line/object does not match Next Run Time: N/A.

Find Command

Showing all content in a folder.

Searching for file

In Windows:

-Force Use this option to include the hidden files or directories.

If you want to get data from the file then you can use the below command:

CMD search Functionality:

In linux:

Flag Finding

In Windows:

In Linux:

One liner:

Last updated