Windows common command training [1]

Open the "Run" dialog box ( Win+R), enter cmd, and open the console command window...

You can also cmd /ccommand and cmd /krun the command mode commands directly

Note: /cmeans to close the cmd window after executing the command; /kmeans to keep the cmd window after executing the command

Some tricks in the console command window

Copy content: Press and hold the left button to select the content to be copied to copy, or the shortcut key Ctrl+C to copy.

Paste content: Right-click to quickly paste. You can also paste with the shortcut key Ctrl+V.

Hold down Shift in the blank space of the folder, then right-click to pop up a shortcut menu, you can see "Open command line window here"

Use the up and down arrow keys to scroll through the used commands

tabCompletion function

The file and directory names cannot contain any of the following characters: \ /: *? "<> |

rem // Add a comment to the batch file, the subsequent commands will not be executed, but will be echoed

:: // :: can also play the role of rem annotation, and there will be no echo

Any character line starting with a colon: will be treated as a label in batch processing, and everything after it will be ignored.
Valid label: the colon is followed by a string beginning with an alphanumeric character, which can be recognized by the goto statement
Invalid label: a special symbol that is not alphanumeric immediately after the colon, a label that goto cannot recognize, can serve as a comment, :: is often used as a comment symbol

0, /?get help

例:cmd /?    // 查看cmd命令帮助说明

1. Interrupt command execution

Ctrl + C

2. File/Directory

cd chdir Display the current directory name or change the current directory.

例:cd   // 显示当前目录

例:cd ..   // 进入父目录

例:cd d:\   // 进入d盘根目录

例:cd d: // 显示上次d盘所在的目录

例:cd /d d:\src // 进入d:\src目录

例:cd prj\src\view  // 进入当前目录下的prj\src\view文件夹

dirDisplay a list of files and subdirectories in the directory.

例:dir   // 显示当前目录中的子文件夹与文件

例:dir /b  // 只显示当前目录中的子文件夹与文件的文件名

例:dir /p  // 分页显示当前目录中的子文件夹与文件

例:dir /ad  // 显示当前目录中的子文件夹

例:dir /a-d  // 显示当前目录中的文件

例:dir c:\test   // 显示c:\test目录中的内容

例:dir keys.txt  // 显示当前目录中keys.txt的信息

例:dir /S   // 递归显示当前目录中的内容

例:dir key*  // 显示当前目录下以key开头的文件和文件夹的信息

例:dir /AH /OS  // 只显示当前目录中隐藏的文件和目录,并按照文件大小从小到大排序

tree Graphically displays the folder structure of the drive or path

例:tree d:\myfiles  // 显示d:\myfiles目录结构

 /F   显示每个文件夹中文件的名称。
 /A   使用 ASCII 字符,而不使用扩展字符。

ren rename File or directory rename

例:ren rec.txt rec.ini  // 将当前目录下的rec.txt文件重命名为rec.ini

例:ren c:\test test_01  // 将c盘下的test文件夹重命名为test_01

请注意,你不能为目标文件指定新的驱动器或路径。

md mkdir Create a directory

例:md movie music  // 在当前目录中创建名为movie和music的文件夹

例:md d:\test\movie  // 创建d:\test\movie目录

rd rmdir Delete directory

例:rd movie // 删除当前目录下的movie空文件夹

例:rd /s /q d:\test  
// 使用安静模式删除d:\test(除目录本身外,还将删除指定目录下的所有子目录和文件)安静模式,带 /S 删除目录树时不要求确认

copy Copying files means copying one or more files to another location.

例:copy key.txt c:\doc  
// 将当前目录下的key.txt拷贝到c:\doc下(若doc中也存在一个key.txt文件,会询问是否覆盖)

例:copy jobs c:\doc  
// 将当前目录下jobs文件夹中文件(不递归子目录)拷贝到c:\doc下(若doc中也存在相应的文件,会询问是否覆盖)

例:copy key.txt c:\doc\key_bak.txt  
// 将当前目录下的key.txt拷贝到c:\doc下,并重命名为key_bak.txt(若doc中也存在一个key_bak.txt文件,会询问是否覆盖)

例:copy /Y key.txt c:\doc  
// 将当前目录下的key.txt拷贝到c:\doc下(不询问,直接覆盖写)

例:copy key.txt +  // 复制文件到自己,实际上是修改了文件日期

例:copy /Y key1.txt + key2.txt key.txt  
// 将当前目录下的key1.txt与key2.txt的内容合并写入key.txt中(不询问,直接覆盖写)

例:copy /B art_2.7z.* art_2.7z    
// 将当前目录下的art_2.7z.开头的所有文件(按照名称升序排序)依次合并生成art_2.7z

例:copy /B art_2.7z.001+art_2.7z.002 art_2.7z    
// 将当前目录下的art_2.7z.001、art_2.7z.002文件合并生成art_2.7z

xcopy More powerful copy commands

例:xcopy c:\bat\hai d:\hello\ /y /h /e /f /c   
 // 将c:\bat\hai中的所有内容拷贝到d:\hello中  
 注意:需要在hello后加上\  表示hello为一个目录,否则xcopy会询问hello是F,还是D

例:xcopy c:\bat\hai d:\hello\ /d:12-29-2010 
 // 将c:\bat\hai中的2010年12月29日后更改的文件拷贝到d:\hello中

robocpy Reliable file copy for Windows

Recommended to open a command line window, enter their own robocopy /?view specific replication options

move Move files and rename files and directories.

例:move *.png test  
// 将当前目录下的png图片移动到当前目录下test文件夹中 (若test中也存在同名的png图片,会询问是否覆盖)

例:move /Y *.png test  
// 将当前目录下的png图片移动到当前目录下test文件夹中 (不询问,直接覆盖写)

例:move 1.png d:\test\2.png  
// 将当前目录下的1.png移动到d盘test文件夹中,并重命名为2.png (若test中也存在同名的png图片,会询问是否覆盖)

例:move test d:\new  
// 若d盘中存在new文件夹,将当前目录下的test文件夹移动到d盘new文件夹中;
// 若不存在,将当前目录下的test文件夹移动到d盘,并重命名为new

del eraseDelete one or more files. Note: neither the directory nor its subdirectories will be deleted

Specify a list of one or more files or directories. Wildcards can be used to delete multiple files. If you specify a directory, all files in that directory will be deleted.

例:del test  
// 删除当前目录下的test文件夹中的所有非只读文件(子目录下的文件不删除;删除前会进行确认;等价于del test\*

例:del /f test  
// 删除当前目录下的test文件夹中的所有文件(含只读文件;子目录下的文件不删除;删除前会进行确认;等价于del /f test\*

例:del /f /s /q test d:\test2\*.doc  
// 删除当前目录下的test文件夹中所有文件及d:\test2中所有doc文件(含只读文件;递归子目录下的文件;删除前不确认)

 /A            根据属性选择要删除的文件
 属性          R  只读文件            S  系统文件
                H  隐藏文件            A  准备存档的文件
                I  无内容索引文件      L  重新分析点
                O  脱机文件            -  表示“否”的前缀

/ar、/ah、/as、/aa 分别表示删除只读、隐藏、系统、存档文件
/a-r、/a-h、/a-s、/a-a 分别表示删除除只读、隐藏、系统、存档以外的文件

例:del /ar *.* // 删除当前目录下所有只读文件

例:del /a-s *.* // 删除当前目录下除系统文件以外的所有文件

replace Replace file [Even if this file is in use, it can still be replaced successfully]

例:replace d:\love.mp3 d:\mp3   
// 使用d盘下的love.mp3强制替换d盘mp3目录中的love.mp3文件

mklink Create a symbolic link (introduced in win7); the created symbolic link file will have an arrow similar to a shortcut

Insert picture description here

The mklink command under win7 can establish different forms of file or directory links by specifying parameters, which are divided into three types: hard link, symbolic link and directory junction.

(1) Symbolic link (symbolic link)

Establishing a soft link is equivalent to creating a file (or directory). This file (or directory) is used to point to other files (or directories), which is similar to win shortcuts.

Deleting this link will have no effect on the original file (or directory); and when you delete the original file (or directory), opening the link again will prompt "The location is not available".

(2) Directory connection (junction)

The function is basically similar to symbolic links. The difference is that the directory link will automatically reference the absolute path of the original directory when it is established, while the symbolic link allows the reference of the relative path.

(3) Hard link

Establishing a hard link is equivalent to creating an alias for the file, for example, creating a hard link named 2.txt for 1.txt;

If you use Notepad to modify 1.txt, 2.txt will be modified at the same time. If you delete 1.txt, 2.txt still exists, and the content is the same as 1.txt.

Please pay attention to the establishment of links:
a. The establishment of file or directory links is limited to the NTFS file system; the establishment of symbolic links (directory links) can be cross-partitioned (for example, a link to a file or directory on disk c can be established on disk d), and hard links can only be established Files in the same partition point to
b. Hard links can only be used for files, not directories; directory links can only be used for directories; symbolic links are both possible;
c. Hard links are not allowed to create links to empty files. ) The link is OK.

+++++++++++++++++++++++++++++++++

mklink [[/d] | [/h] | [/j]] Link Target

/d   创建目录符号链接。黙认为文件符号链接。
/h   创建硬链接,而不是符号链接。
/j   创建目录联接。
Link  指定新的符号链接名称。
Target 指定新链接引用的路径(相对或绝对)

+++++++++++++++++++++++++++++++++
例:mklink /j "D:\Users" "C:\Users"   // 创建D盘Users目录联接到C盘,并命名为Users

attrib View or modify the attributes of a file or directory [A: Archive R: Read-only S: System H: Hidden]

例:attrib 1.txt   // 查看当前目录下1.txt的属性

例:attrib -R 1.txt  // 去掉1.txt的只读属性

例:attrib +H movie  // 隐藏movie文件夹

assoc Set the'file type' associated with the'file extension'

例:assoc // 显示所有'文件扩展名'关联

例:assoc .txt // 显示.txt代表的'文件类型',结果显示.txt=txtfile

例:assoc .doc // 显示.doc代表的'文件类型',结果显示.doc=Word.Document.8

例:assoc .exe // 显示.exe代表的'文件类型',结果显示.exe=exefile

例:assoc .txt=txtfile  // 恢复.txt的正确关联

ftype Set the'execution program and parameters' associated with the'file type'

例:ftype // 显示所有'文件类型'关联

例:ftype exefile // 显示exefile类型关联的命令行,结果显示 exefile="%1" %*

例:ftype txtfile=C:\Windows\notepad.exe %1 // 设置txtfile类型关联的命令行为:C:\Windows\notepad.exe %1

When double-clicking a .txt file, Windows does not directly judge the
.txt to open it with notepad.exe, but first judges that the .txt belongs to the txtfile'file type'; then calls the command line associated with txtfile: txtfile=%SystemRoot%\system32\ NOTEPAD.EXE %1

forfiles Recursive directory execution commands

例:forfiles /p . /m .svn /s /c "cmd /c svn up -r12005" 
// 在当前目录下查找含有.svn的文件或目录(递归子目录),并对该目录执行指定版本号svn更新

例:forfiles /p c:\myfiles /m .svn /s /c "cmd /c svn up -r12005" 
// 在c:\myfiles目录下查找含有.svn的文件或目录(递归子目录),并对该目录执行指定版本号svn更新

3. File View

type Display the contents of the text file

例:type c:\11.txt   // 显示c盘中11.txt的文本内容

例:type conf.ini  // 显示当前目录下conf.ini的文本内容

例:type c:\11.txt | more  // 分页显示c盘中11.txt的文本内容

more Display text file content screen by screen

例:more /E text.txt = //  逐屏的显示当前目录下text.txt 的文本内容, 显示行数
--------------------------------------------------------
    /E      启用扩展功能
            如果已启用扩展功能,则在 -- More -- 提示处 接受下列命令:
    P n 显示下 n 行
    S n 跳过下 n 行
    F 显示下个文件
    Q 退出
    = 显示行号
    ? 显示帮助行
    <space> 显示下一页
    <ret> 显示下一行

4. netCommand

net start  // 查看已经启动的服务

net start "Task Scheduler"   // 开启任务计划服务

net stop "Task Scheduler" /y  // 不询问,直接关闭任务计划服务

net start dnscache  // 开启dns缓存服务

net stop dnscache /y  // 不询问,直接关闭dns缓存服务

net start TermService  // 开启Remote Desktop Services服务

net stop TermService /y  // 不询问,直接关闭Remote Desktop Services服务

net share   // 查看当前用户下的共享目录

net share workFile /delete  // 取消名为workFile的共享状态

net share xxx=c:\360Downloads   // 将c:\360Downloads设为共享,并取名为xxx

net share ipc$ // 开启ipc$共享

net share ipc$ /del // 删除ipc$共享

net share c$ /del // 删除c盘共享

net use \\192.168.1.166\ipc$ " " /user:" " // 建立192.168.1.166的ipc空链接

net use \\192.168.1.166\ipc$ "123456" /user:"administrator"   
// 直接登陆后建立192.168.1.166的ipc非空链接(用户名为administrator 密码为123456)

net use h: \\192.168.1.166\c$ "123456" /user:"administrator"   
// 直接登陆后映射192.168.1.166的c盘到本地为h盘(用户名为administrator 密码为123456)

net use h: \\192.168.1.166\c$   // 登陆后映射192.168.1.166的c盘到本地为h盘

net use \\192.168.1.166\ipc$ /del  // 删除ipc链接

net use h: /del // 删除本地的h盘的映射

net view   // 查看本地局域网内开启了哪些共享

net view \\192.168.1.166  // 查看192.168.1.166的机器上在局域网内开启了哪些共享

net time \\127.0.0.1   // 查看本地机器的日期及时间

net time \\localhost   // 查看本地机器的日期及时间

net time \\192.168.1.166   // 查看192.168.1.166机器的日期及时间

net time \\192.168.1.166 /set  
// 设置本地计算机时间与192.168.1.166主机的时间同步,加上参数/yes可取消确认信息

net user  // 查看当前机器上的用户

net user Administrator   // 查看当前机器上的Administrator用户的信息

net user Guest /active:yes  // 启用Guest用户

net user dev 123456 /add   // 新建一个名为dev,密码为123456的用户

net localgroup administrators dev /add  // 把名为dev的用户添加到管理员用户组中,使其具有管理员权限

net user dev /del  // 删除名为dev的用户

5. Process operation

tasklist Display current running process information (you can view PID)

taskkill End the specified process

6. Network operation

ping Used to detect whether the network is unblocked and the network delay (working on the ICMP protocol)

例:ping baidu.com   //  测试与baidu服务器的连接情况

例:ping chen-pc0   // 测试机器名为chen-pc0的连接情况

例:ping 220.181.111.86   // 测试与ip为220.181.111.86的连接情况

例:ping -l 65500 -n 10 qq.com   // 向qq.com发送10次65500字节的ping

例:ping -n 6 127.0.0.1 // 对当前主机执行6次ping操作(花费时间为5s)

例:ping -t baidu.com   
// 不断地测试baidu服务器的连接情况   【Ctrl+Pause Break:查看ping的统计信息;Ctrl+C:终止当前任务】

a. First check the local arp cache information to see if there is a record of the counterparty's mac address and IP address mapping entry
b. If not, initiate an arp request broadcast packet and wait for the counterparty to inform the specific mac address
c. After receiving the arp response packet , Obtain the specific mac address corresponding to an IP, and then start communication after having the physical address, and make a local cache for the ip-mac address
. d. Send out the icmp echo request packet and receive the icmp echo reply packet

Note: If you are on the same network segment but cannot ping the target host, it may be that the target host has disabled ping. You can turn on "Inbound Rules"-"File and Printer Sharing (Echo Request-ICMPv4-In)" in the advanced settings of the firewall.

ipconfig View detailed information such as local ip address

nslookup DNS

nslookup www.cnblogs.com  // 获取www.cnblogs.com的域名解析

nslookup -d www.cnblogs.com  // 打印出www.cnblogs.com的域名解析所有记录

netstat Display protocol statistics and current TCP/IP network connection.

netstat -a   // 查看开启了哪些端口

netstat -ao // 查看开启了哪些端口,并显示进程pid

netstat -n  // 查看端口的网络连接情况

netstat -v   // 查看正在进行的工作

netstat -p tcp  // 查看tcp协议的使用情况

tracert 182.140.167.44 // View the routing path of the machine to 182.140.167.44

route Operate the network routing table.

route print  // 显示出IP路由

telnet Used to detect the port number of the specified IP, this is just a basic function of telnet;

The power of the telnet command is to log in to the computer on the network remotely and manage the computer remotely by command line.

Windows telnet server (default port: 23) environment configuration process is as follows:
a. Install telnet server
b. Start Telnet service
c. Turn off windows firewall Note: If you don’t want to turn off the firewall, you need to access the Telnet server in the Windows firewall-advanced settings Rules for configuration

ftpTransfer files to and from a computer running an FTP server service (often called a daemon). You can use Ftp interactively.

ftp 46.19.34.198 21  
// 连接46.19.34.198 ftp服务器(21为端口号),然后会要求输入用户名与密码;连接成功后,具体如何使用可以键入?来查看帮助说明

arp Display and modify the "IP to physical" address conversion table used by the Address Resolution Protocol (ARP).

例:arp -a  // 显示arp缓存表

7. Other

cls Clear screen

ver Display the version number of the current windows system

winver The pop-up box displays the current windows system information

whoami Display the name of the current user

hostname Display the current machine name

vol Display the volume label of the current partition

label Display the volume label of the current partition and prompt for a new volume label

例:label c:system  // 设置c盘的卷标为system

time Display or set the current time

例:time /t  // 显示当前时间

例:time   // 设置新的当前时间(格式:hh:mm:ss),直接回车则表示放弃设置

date Display or set the current date

例:date /t  // 显示当前日期

例:date   // 设置新的当前日期(格式:YYYY/MM/DD),直接回车则表示放弃设置

title Doing command line testing // Modify the title bar text of the current cmd window to be doing command line testing

prompt orz: // Modify the command prompt to orz:

print1.txt // Use the set printer to print the 1.txt text file

call ff.bat // Call to execute the ff.bat script (the original script will be executed after the ff.bat script is executed)

start Run a program or command

例:start chome.exe  // 启动chome浏览器

exit Exit the current cmd window instance

Set the properties of the cmd window (background color, font size, color, etc.)
: click on the blank at the top of the cmd window —> right click —> properties to set

Insert picture description here
Insert picture description here
systeminfo Display information about the operating system configuration of local or remote machines (including service pack levels).

logoff Log out the current user

shutdown Shut down, restart, log off, hibernate the computer

例:shutdown /s  // 关闭计算机

例:shutdown /s /t 3600  // 一小时后,关闭本地计算机

例:shutdown /a  // 终止系统关闭

例:shutdown /r  // 关闭并重启本地计算机

例:shutdown /m 192.168.1.166 /r  // 关闭并重启ip为192.168.1.166的计算机

Obtaining remote shutdown permissions:
1) Modify the "local security policy" of the remote PC to open permissions for specified users.
In the default security policy of WindowsXP, only users in the Administrators group have the right to shut down the computer remotely. If you want to give xxxx User's permission to shut down remotely.
It can be achieved by using WindowsXP's "Group Policy" or "Local Security Policy" in "Administrative Tools".
1. Run gpedit.msc from the command line to open the "Group Policy Editor";
2. Navigate to "Computer Configuration/Windows Settings/Security Settings/Local Policies/User Rights Assignment";
3. Modify "Force Shutdown from Remote System", Just add xxxx user.

2) Obtain remote IPC management authority.
If "Access denied." appears after the first step of the configuration, you need to run the following command before running the shutdown command
net use \[ip address or computer name]\ipc$ password /user:xxxx
Where password is the login password of account xxxx.

例:shutdown /g  // 关闭并重启计算机,重启后重新启动所有注册的应用程序

例:shutdown /l  // 注销本地计算机

例:shutdown /h /f // 休眠本地计算机(强制正在运行的应用程序关闭,不前台警告用户)

例:shutdown /s  // 关闭计算机

cmdkey Credential (Create, display and delete saved user names and passwords.)

powercfg Allows users to control the power settings on the local system.

For detailed information about commands and options, please run "POWERCFG /? "

例:powercfg -list   // 列出当前用户环境中的所有电源方案的GUID以及当前使用的是哪一个电源方案

schtasks Allows the administrator to create, delete, query, change, run and abort scheduled tasks on local or remote systems.

Guess you like

Origin blog.csdn.net/qq_44721831/article/details/108657757
Recommended