Because I often use Linux commands, I often make mistakes when entering commands in Windows cmd, and the prompt is not an internal or external command, nor is it a runnable program.
So is there a way to complete the cmd command so that the commands in Linux can also be used in Windows?
Let me explain how to use Linux commands in the Windows CMD command line.
Introduction to Cygwin
Cygwin is a UNIX-like simulation environment running on the Windows platform. It is useful for learning the UNIX/Linux operating environment, or porting applications from UNIX to Windows, or doing some special development work, especially using the GNU tool set on Windows. It is very useful for embedded system development.
Download Cygwin
We visit Github and search for CygwinPortable to enter the project page
https://github.com/MachinaCore/CygwinPortable/
Click on Release
the link , we downloadCygwinPortable_1.4.0.0.7z
Install Cygwin
Unzip the downloaded 7z compressed package, rename it and Cygwin
put it the root directory of the C drive
Enter the Cygwin directory and start CygwinPortable.exe
the program
. After starting the installer, we chooseDownload Cygwin X64
The Cygwin installer will download and install all related programs online, and the program will automatically close after the installation is complete.
At this point, you can see the Cygwin program icon in the lower right corner of the taskbar.
Search Cygwin
can find the Cygwin terminal program, we startCygwin64 Terminal
Now we can enter common Linux commands in this terminal. The default path after the terminal is started is
C:\Cygwin\App\Runtime\Cygwin\home\用户目录
Configure environment variables
After installation, it still cannot be used in the cmd command line. If we want to make it available in the cmd command, we must configure the system environment variables.
Win+ RWe enter in the run window sysdm.cpl
to start the system properties panel.
Click on 高级
the tab , we find the function of opening environment variables
Find this column 系统变量
in the bottom , select it and click the button.Path
编辑
Click 新建
the button to add the Cygwin bin directory. If you have configured it step by step according to my steps before, just fill in the following path, and confirm to exit after adding.
C:\Cygwin\App\Runtime\Cygwin\bin
- Add environment variables with the command
Open CMD with administrator privileges and enter the following command to add a system environment variable
setx path "%PATH%;C:\Cygwin\App\Runtime\Cygwin\bin" /M
use linux commands
We start the CMD terminal, and then use ls
the command to use it normally. Cygwin integrates more than 270 Linux commands.
Try using grep
the search function