Return to Bash and PowerShell command correspondence table
I just learned how to do PowerShell.
Bash
$ grep [option] <The character string you want to search> [file name]
# [option]: 任意(以下は、私がよく使うoption)
-i:Search in case insensitive
-I:Exclude binary files from search
-n:Display the line number of the part that was caught in the search
-r:Also search for files in subdirectories
-v: <The character string you want to search>Show what does not match
-w:Show only exact matches
--exclude="*.extension": 指定したextensionは検索対象外にする
--include="*.extension": 指定したextensionのみ検索対象にする
# <The character string you want to search>:Mandatory
If space is included in the middle, ""String string"Enclose in double quotes.
# [file name]:Optional (but close to mandatory)
Search only in the specified file.
fundamentally"*(Asterisk): All files can be searched.
I want to narrow down the search target (for example, hoge).Specify a specific file name only when (txt file only).
Example 1) Search for all files in the current directory with hoge
$ grep hoge *
Example 2) Search for the hoge.txt
file in the current directory with hoge
$ grep hoge hoge.txt
Example 3) Search for exact matches with main
for all files including subdirectories
$ grep -rw main *
Example 4) Search for all files including subdirectories that do not contain main
$ grep -rv main *
Example 5) Search by color
for all files other than json and xml files including subdirectories
$ grep -r --exclude="*.json" --exclude="*.xml" color *
PowerShell
> Select-String -Path <file name> -Pattern '<The character string you want to search>' [option]
# <file name>about
Search only in the specified file.
fundamentally"*(Asterisk): All files can be searched.
I want to narrow down the search target (for example, hoge).Specify a specific file name only when (txt file only).
# <The character string you want to search>about
Specify what you want to search here.
Be sure to "single quote (single quote)[Shift] + [7]) ”.
# [option]
-Encoding:Character code (Shift_JIS and UTF-8 etc.)
-NotMatch: <The character string you want to search>Show what does not match
-Exclude <String>:In the file name<String>Exclude those containing
-Include <String>:In the file name<String>Only those that include
> Get-ChildItem -Path <Folder path you want to search> -Filter <file name> -Recurse | Select-String -Pattern '<The character string you want to search>'
# -About Recurse
Attach this when you want to include subfolders in the search target.
# <Folder path you want to search>
Specify where to start the search.
Search from the current folder: .(Dot)
Search from home folder: ~(Tilde) or$HOME
Search from root folder: /(Slash)
# <file name>about
Same as "Search only in current folder" above.
# <The character string you want to search>about
Same as "Search only in current folder" above.
Example 1) Search for all files in the current directory with hoge
> Select-String -Path * -Pattern 'hoge'
Example 2) Search for the hoge.txt
file in the current directory with hoge
> Select-String -Path hoge.txt -Pattern 'hoge'
Example 3) Search for files containing main
, including all files including subdirectories.
> Get-ChildItem -Path ./* -Filter * -Recurse | Select-String -Pattern 'main'
Example 4) Search for all files including subdirectories that do not contain main
> Get-ChildItem -Path ./* -Filter * -Recurse | Select-String -Pattern 'main' -NotMatch
Example 5) Search by color
for all files other than all json files including subdirectories (multiple files are unknown)
> Get-ChildItem -Path ./* -Filter * -Recurse | Select-String -Pattern 'color' -Exclude *.json
Recommended Posts