‘grep’ 不被识别为内部或外部命令
‘grep’ is not recognized as an internal or external command
grep
Windows下使用命令时出现“’grep’不是内部或外部命令、可运行程序或批处理文件”的错误。
要解决此错误,请使用findstr
命令搜索文件中的文本模式或使用 Git Bash。
findstr
命令是 Unix命令
的 Windows 等价物。grep
下面是一个在名为
my_file.txt
.
findstr "app" my_file.txt
findstr
您可以在
文档的这一部分查看其他使用示例。
grep
安装来在 Git Bash 中运行该命令。git
如果你已经git
安装了,你可以搜索Git Bash
并使用
grep
命令,否则,你必须git
先安装。
grep
在 Git Bash 中运行命令
要下载git
并能够使用 Git Bash:
- 打开git 下载页面并下载适用于 Windows 的安装程序。
- 启动安装程序。
- 系统将提示您选择目标位置。您可以保留默认选项并单击
Next
。
- You will be prompted to select components on the next screen. Leave the
default options and clickNext
.
-
Click
Next
on the screen that prompts you to “Select Start Menu Folder”. -
On the next screen, you can choose the default editor for
Git
, e.g.
Notepad
,Notepad++
or any other editor you prefer.
- On the “Adjust the name of the initial branch in new repositories screen”,
clickNext
.
- On the “Adjust your PATH environment” screen, make sure you have the default
option of “Git from the command line and also from 3rd-party software”
option selected and click “Next”.
- For all the remaining screens, leave the default option selected and click
Next
. - Lastly, click on the
Install
button to installgit
.
Once you have git
installed, click on the Search field, type “Git Bash”
and start the application.
Now you can use the grep
command directly in Git Bash.
# 👇️ search for "apple" in the file `my_file.txt` grep "apple" my_file.txt # 👇️ search for "apple" recursively in all directories grep -r "apple" *
If you need to open Git Bash in a specific folder:
- Open the folder in a new window.
- Right-click in Explorer.
- Click “Git Bash Here”.
Now you can use the grep
command to search for patterns of text in files.
# 👇️ search for "apple" in the file `my_file.txt` grep "apple" my_file.txt # 👇️ search for "apple" recursively in all directories grep -r "apple" *
# Additional Resources
You can learn more about the related topics by checking out the following
tutorials:
- Windows Equivalent of the ‘ls’, ‘which’ and ‘ln’ commands
- The Windows equivalent of the Unix ‘tee’ command
- The Windows equivalent of the Unix ‘pwd’ command
- ‘curl’ is not recognized as an internal or external command
- ‘make’ is not recognized as an internal or external command
- ‘concurrently’ is not recognized as an internal or external command
- ‘cross-env’ is not recognized as an internal or external command
- ‘expo’ is not recognized as an internal or external command
- ‘ng’ is not recognized as an internal or external command
- ‘nodemon’ is not recognized as an internal or external command
- ‘eval’ is not recognized as an internal or external command