This is the copy of alvincr.com

Win uses linux commands to replace dos commands to execute user instructions

This article was published 375 days ago. The content in the article may be out of date. If you have any questions, please leave a message in the alvincr.com

view my personal blog original article for more:

https://alvincr.com/2021/01/win%e9%87%87%e7%94%a8linux%e5%91%bd%e4%bb%a4%e6%9b%bf%e6%8d%a2dos%e5%91%bd%e4%bb%a4%e4%bb%a5%e6%89%a7%e8%a1%8c%e7%94%a8%e6%88%b7%e6%8c%87%e4%bb%a4/

1 Preparation

1.1 Enable developer mode

Select Settings-Update and Security, enable developer mode, and allow installation of applications from any source. Reference: https://docs.microsoft.com/en-us/windows/apps/get-started/enable-your-device-for-development?OCID=WinClient_Ver1703_Settings_DevMode

img

1.2 Enable subsystem

Select Control Panel-Programs-Programs and Features-Enable or disable windows functions-check the windows subsystem for linux

img

img

After the installation is successful, restart the computer and proceed to the next step.

2 Download the Windows subsystem for Linux

Official website: https://aka.ms/wslstore

Get the address through cmd command -bash

img

There are 5 options in 2021.1.3:

img

If you are a novice who has never been in contact with linux (it is estimated that novices will not read this), please refer to the version reference website : https://www.oschina.net/translate/best-linux-distributions

Personally prefer centos commands, but ubuntu uses less. So choose openSUSE. 2021.1.3 Supplement: Some commands of SUSE have relatively low support under win, and the experience is very general, so use kali linux instead.

The following is a basic introduction to the change options (content comes from the network):

Ubuntu is a Linux operating system based on Debian distribution and Unity as the default desktop environment. He is one of the most popular releases in the world, and every time it is released, it improves. The latest release is the optimization of desktop, mobile and desktop mobile hybrid version.

The OpenSUSE distribution is a general distribution of Linux. It is built by the OpenSUSE project. The goal is to become a good distribution for novices while also satisfying the needs of experienced Linux users. OpenSUSE comes with YAST, which is an administrator program that can control installation, package management, and other things.

Kali Linux, formerly known as BackTrack, is a penetration testing distribution that is widely used in online security communities. This Debian-based Linux distribution can easily perform digital forensics tasks.

Debian is an older Linux distribution that came along with the GNOME desktop environment. However, this desktop environment can also be used for FreeBSD, and support for other kernels is also in progress, such as Hurd . Debian is proud of its pre-installed packages of more than 37,500, and with simple features that make it easy to get more packages.

https://docs.microsoft.com/en-us/windows/wsl/install-win10

Supplement: WSL is the abbreviation of Windows Subsystem for Linux, which allows developers to run the GNU/Linux environment as it is-including most command line tools, utilities and applications-without incurring virtual machine overhead.

Just start after downloading

img

Wait for the installation, set the administrator name and password

img

3 use

3.1 Method One

In the file manager, hold down the shift+right mouse button and choose to open the linux shell here to replace the win command with the linux command.

img

When using the paste option, you cannot use ctrl+v, nor can you use shell shortcuts, but click the right mouse button to paste the command after copying. If you don’t use ctrl+v here, it’s not that you can’t copy, but that there will be a “mouth” phenomenon.

img

3.2 Method Two

Use the cmd command to enter bash to access the Linux side

4 attached

1 Windows and Linux line break rules

^M Input method in Linux/Unix: CTRL+v, then press CTRL+SHIFT+m

1.1 Interesting historical knowledge:

Before the computer appeared, there was something called a teletype machine (Teletype Model 33), which could type 10 characters per second. But it has a problem, that is, it takes 0.2 seconds to type a line and wrap it, which is exactly two characters. If a new character is passed in within 0.2 seconds, then this character will be lost.

Therefore, the developers thought of a way to solve this problem, which is to add two characters at the end of each line. One is called “Carriage Return”, which tells the typewriter to position the print head on the left margin; the other is called “Linefeed”, which tells the typewriter to move the paper down one line.

Later, the computer was invented, and these two concepts were applied to the computer. At that time, memory was very expensive, and some scientists thought that adding two characters at the end of each line was too wasteful, just add one. As a result, there was a disagreement.

In Unix systems, each line ends with ““, that is, “\n”; in Windows systems, each line ends with ““, that is, “\r\n”; in Mac systems, The end of each line is ““. A direct consequence is that if a file under Unix/Mac is opened in Windows, all text will become one line; and if a file in Windows is opened under Unix/Mac, there may be an extra ^M at the end of each line. symbol.

(The above content is reproduced from Ruan Yifeng’s blog )

In summary, it is because of historical reasons that win and linux have diverged in some details (win and linux are designed with reference to UNIX, and linux is even more so), resulting in slightly different instructions in win and linux. The win command cannot be run directly on Linux, but it can be run after a simple transformation.

1.2 Why does the text file created under windows display normally in linux

Because the newline character is automatically detected when using the vim command of linux, but sometimes the file created or edited under win will appear ^M under linux. This is caused by the newline character of the text checked by vim, as long as there is no win format Line break, then the text data will be displayed as it is.

(1) Replace with sed command

sed -e’s/^M//g’ before.txt> after.txt

Refer to the sed command below, you can see that the above parameters are edited directly in the command line mode for sed actions

Sed is an online editor that processes content one line at a time. During processing, the currently processed line is stored in a temporary buffer called “pattern space”, and then the content in the buffer is processed with the sed command. After the processing is completed, the content of the buffer is sent to the screen. Then process the next line, and repeat this way until the end of the file. The content of the file does not change unless you use redirection to store the output. Sed is mainly used to automatically edit one or more files; simplify repeated operations on files; write conversion programs, etc.

1
2
3
4
5
6
7
8
[ root@www ~]# sed [-nefr] [action]
Options and parameters:
-n: Use silent mode. In general sed usage, all data from STDIN will generally be listed on the terminal. But if the -n parameter is added, only the line (or action) that has been specially processed by sed will be listed.
-e: directly edit sed actions in command line mode;
-f: directly write the sed action in a file, -f filename can run the sed action in filename;
-r: The sed action supports the grammar of extended formal notation. (The default is basic regular notation syntax)
-i: Modify the content of the read file directly instead of outputting it to the terminal.
https://www.cnblogs.com/ggjucheng/archive/2013/01/13/2856901.html

2 The difference between X Window and Microsoft Windows

  • The UNIX/Linux system and X Window are not necessarily tied to each other, that is to say, UNIX/Linux can be installed with or without X Window; and Microsoft’s Windows graphics environment is closely tied to the kernel.
  • The UNIX/Linux system does not rely on a graphical environment, and 100% of the functions can still be completed through the command line, and a lot of system resources will be saved because the graphical environment is not used.

http://c.biancheng.net/view/707.html

Create and use sub-themes to prevent loss of added functionality

  1. 1.
    1. 1.0.0.0.1. view my personal blog original article for more:
  • 2. 1 Preparation
    1. 2.1. 1.1 Enable developer mode
    2. 2.2. 1.2 Enable subsystem
  • 3. 2 Download the Windows subsystem for Linux
  • 4. 3 use
    1. 4.1. 3.1 Method One
    2. 4.2. 3.2 Method Two
  • 5. 4 attached
    1. 5.1. 1 Windows and Linux line break rules
      1. 5.1.1. 1.1 Interesting historical knowledge:
      2. 5.1.2. 1.2 Why does the text file created under windows display normally in linux
      3. 5.1.3. 1.3 Related code
    2. 5.2. 2 The difference between X Window and Microsoft Windows