Window common basic commands

0. start

 0-1) Get command parameter guide

netstat /?

0-2) About two slashes:

        Use backslashes in windows file paths: \

        Use in linux file path: /

1. Power on and off commands

shutdown /s                # 关机

shutdown /r                # 重启

shutdown /l                # 注销

shutdown /h /f             # 休眠

shutdown /s /t 600         # 600s —— 十分钟之后关机

2. Switch directory (path)

2-1) Two ways to switch disks:

C:\> cd /d e:
C:\> E:

2-2) Switch directly to the specified directory:

C:\> cd /d e:/myself

e:\myself>

2-3) Return to the upper directory:

e:\myself> cd ..

e:\>

3-4) Enter the specified directory under the current directory:

e:\> cd ./myself

e:\myself>

3. Operations related to files or directories

3-1) Query all non-hidden directories and files in the directory (dir)

query current directory

e:\myself\test_nodejs> dir

Query the specified directory

e:\> dir C:

Query all non-hidden txt files in the current directory:

dir *.txt

3-2) View hidden files in the directory ( /a, /a:h )

Query all hidden directories and files under the C drive

e:\> dir /a:h C:

Query all files under the C drive, including hidden files:

e:\> dir /a C:

3-3) View all directories and files under the directory, sorted by date ( /o:D, /o:-D )

Query all files in the current directory and sort them in ascending order by date

e:\> dir /a /o:D

Query all non-hidden directories under the C disk directory, and sort them in descending order by date

e:\> dir /o:-D C:

3-4) Create a directory ( md, mkdir )

e:\myself> mk dirName

or:

e:\myself> mkdir testDir

Create multi-level folders:

e:\myself> mkdir dir_1\dir_2\dir_3

3-5) Delete directory tree (rd, rmdir)

Delete empty directories with no subfiles or subdirectories:
rd mydir

or

rmdir mydir
Delete non-empty directories with subdirectories or subfiles:
rmdir /s mydir 

or

rd /s /q mydir        # 直接删除,不用询问

3-6) Move directory or file (move)

# 将当前目录下的 test.txt 移动到 C:\testFile\
move test.txt C:\testFile
# 将 C:\test.txt 移动到D:\myself 目录下,并重命名为 File.txt
move C:\test.txt D:\myself\file.txt

3-7) Copy directory or file (copy)

copy E:\test.txt D:\        # 将E盘下的test.txt文件复制到D盘

copy test.txt D:\testFile.txt    # 将当前目录下的test.txt文件复制到D盘下,并重命名

# 将当前目录下的两个指定文件的内容拼接起来形成一个新的文件,然后将该文件复制到D盘中,并重命名为all.txt
copy test.txt + test_2.txt D:\all.txt

3-8) Copy directory (xcopy)

xcopy /s: copy non-empty directories

xcopy: complex directory without any files

# 复制 e:\myself\dir_1 的 dir_2 目录到当前目录下,并重命名为mydir2
xcopy /s e:\myself\dir_1\dir_2 mydir2\

3-9) Delete files (del, erase)

del test.txt

erase test.txt
del *.txt        # 删除所有 txt 类型的文件

3-10) Display the contents of the file (type)

type C:\test.txt

3-11) Rename the file (move)

e:\myself> move test.txt newFile.txt

3-12) Create a file and write content (copy con, echo content>)

 use copy con
# 创建一个名为test.sql 的文件并立即写入内容,写完内容后 Ctrl+Z 确认并保存
e:\> copy con test.sql

use echo

        echo is used to echo information, and can also write content to a file

echo Hello World > Hello.txt

        The symbol > is a redirection symbol, and its function is to write the result of running before the redirection symbol to the specified file

3-13) Open Notepad to edit file content

notepad.exe test.sql

3-14) Open the resource manager and navigate to the specified directory

explorer.exe E:\

4. Retrieve file content (find)

First create a file and write the content:

Search content:

# /N 为在前方标识出行号; /V 为显示不包含指定内容的行
# /C 为显示符合条件的行总数; /I 忽略大小写
find /N "is" mytxt.txt

Retrieve Chinese text files encoded using utf-8:

        The default encoding format in cmd is GBK. Temporarily modify the encoding format of cmd to prevent it from being parsed into garbled characters after reading the file:

Reference: https://www.jianshu.com/p/29a2ca839cfc

E:\myself> chcp 65001        # 临时改变编码格式为 utf-8

5. Network related commands

5-1) ipconfig View tcp/ip related configuration information

> ipconfig

> ipconfig /all        # 显示更详细的信息

> ipconfig /release     # 释放TCP/IP参数

> ipconfig /renew       # 重新获取TCP/IP参数

> ipconfig /flushdns    # 刷新dns缓存

5-2) Ping test whether the network connection is smooth

Determine whether the current host can exchange datagrams with the target host

# 重复两次,尝试与百度建立连接
E:\myself> ping www.baidu.com -n 2

5-3) tracert routing trace

Track the routing process that the current IP needs to go through to reach the target address to be accessed

5-4) netstat View the current tcp/ip network connection status

# 展示所有 tcp 相关的连接,显示监听端口、状态、进程ID等信息
netstat -anotp tcp



# a 表示显示所有的连接和端口
# n 表示以数字的形式展示地址和端口
# t 表示显示连接状态信息
# o 表示显示对应的进程ID
# p 表示选择指定的协议    上面选择的是tcp协议,还可以选择udp等协议

# 如果没有指定 p ,则会显示全部(tcp、udp等)
netstat -ant

6. Pipe character (|) and output redirection (>)

6-1) Pipe character:

        It is often used to separate two instructions. The previous instruction has output content, and the output content is used as the operation object of the next instruction.

# 先执行 ipconfig /all ,然后将结果作为 find 的对象,在其中检索出包含 address 的行(忽略大小写)
E:\myself> ipconfig /all | find /i "address"

E:\>netstat -ant | find /i "UDP"

6-2) Output redirection:

        Commonly used to output content to a file

# 先查询 ip 配置,然后将返回的内容写入到当前目录中的 my-ipconfig.txt 文件中(如果没有,则会先创建再写入)
E:\myself> ipconfig > my-ipconfig.txt

If the output file already exists and has content, the original content will be overwritten:

Guess you like

Origin blog.csdn.net/hao_13/article/details/132629415