‘cat’ 不被识别为内部或外部命令
‘cat’ is not recognized as an internal or external command
cat
当我们在 Windows 上,在 CMD shell 中使用该命令时,出现错误“’cat’ 未被识别为内部或外部命令、可运行的程序或批处理文件” 。
要解决该错误,请使用type
命令显示文件的内容。
该type
命令是 Unix/Linuxcat
命令的 Windows 等价物。
# 👇️ display the contents of a file named my_file.txt type my_file.txt # 👇️ display the contents of a lengthy file named my_file.txt, one screen at a time type my_file.txt | more
my_file.txt
占位符替换为您要阅读的文件的名称。type命令
用于显示文本文件的内容。
您可以将命令的输出通过管道传递给more
命令,以一次显示一个屏幕的冗长文件的内容。
# 👇️ display the contents of a lengthy file named my_file.txt, one screen at a time type my_file.txt | more
请注意,您可以在 PowerShell 中使用该cat
命令。
要打开 PowerShell:
- 单击搜索栏并键入“PowerShell”。
- 单击“Windows PowerShell”应用程序。
直接在 PowerShell 中运行 cat 命令来读取文件的内容。
cat my_file.txt
如果您需要在特定文件夹中打开 PowerShell:
- 在窗口中打开文件夹。
- 在资源管理器中按下
Shift
并右键单击。
- 单击“在此处打开 PowerShell 窗口”。
- 运行
cat
命令。
cat my_file.txt
cat
安装来在 Git Bash 中运行该命令。git
If you already have git
installed, you can search for Git Bash
and use the
cat
command, otherwise, you have to install git
first.
# Running the cat
command in Git Bash
To download git
and be able to use Git Bash:
- Open the git downloads page and download the
installer for Windows. - Start the installer.
- You will be prompted to select a destination location. You can leave the
default option and clickNext
.
- 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.
现在您可以cat
直接在 Git Bash 中使用该命令。
cat my_file.txt
如果需要在特定文件夹中打开 Git Bash:
- 在新窗口中打开文件夹。
- 在资源管理器中右键单击。
- 单击“此处的 Git Bash”。
现在您可以使用该cat
命令来显示文本文件的内容。
cat my_file.txt