HOME> 意大利世界杯夺冠> Windows命令行查找并kill进程及常用批处理命令汇总
{$vo.文章标题}
{$vo.文章标题}

Windows命令行查找并kill进程及常用批处理命令汇总

admin
1159

Windows命令行查找并kill进程及常用命令汇总

打开命令窗口

开始—->运行—->cmd,或者是 window+R 组合键,调出命令窗口。

一、cmd命令行杀死Windows进程方法

1、根据进程名称批量kill

1)、执行tasklist|more检索进程

2)、执行 tasklist|findstr "进程名(模糊匹配)" 确认进程具体名词

3)、执行 TASKKILL /F /IM 进程名称 /T 杀死进程

4)、执行tasklist|findstr "QQ“ 确认

2、根据端口号杀死进程

1)、执行 netstat -ano|findstr "端口号" 确认进程ID

2)、根据进程id执行 tasklist|findstr "Pid"确认进程名称

3)、执行 TASKKILL /F /IM 进程名称 /T 杀死进程

C:\Users\Administrator>TASKKILL /F /IM redis-se

rver.exe /T

二、常用命令

常用命令汇总

1、盘符

切换分区

F:\>

F:\>d:

D:\>e:

E:\>f:

F:\>i:

I:\test\dir1>

2、目录相关

1)、dir 显示目录中的文件和子目录列表。

命令示例

2)、cd显示当前目录名或改变当前目录。

命令示例

I:\test\dir>cd..

I:\test>cd dir1

I:\test\dir1>cd ..

I:\test>cd I:\test\dir

I:\test\dir>cd I:\python

I:\python>

3)、Chdir 显示当前目录名或改变当前目录。

命令示例

I:\python>chdir

I:\python

I:\python>chdir I:\test\dir

I:\test\dir>chdir ..

I:\test>

4)、MD 创建目录。

命令示例:

5)、rd删除一个目录。

命令示例:

3、文件相关

1)、Echo显示消息,或者启用或关闭命令回显。或者创建文件

echo 字符串 > [路径\] 文件名.扩展名

注释:>>和>都可以将命令的输出内容输入到某文件中,若文件不存在,则同时创建该文件

>>为追加

>为覆盖

命令示例:

I:\test\dir2>echo hello fieldyang>test

I:\test\dir2>echo hello fieldyang>>test

I:\test\dir2>echo hello fieldyang>>test

I:\test\dir2>type test

hello fieldyang

hello fieldyang

hello fieldyang

I:\test\dir2>echo hello world>>test

I:\test\dir2>echo hello world>test

I:\test\dir2>type test

hello world

I:\test\dir2>

2)、Replace 替换文件。

示例示例:

3)、type显示文本文件的内容。

TYPE [drive:][path]filename

命令示例:

I:\test\dir2>type test

hello world

hello fieldyang

hello fieldyang

hello fieldyang

hello fieldyang

4)、more逐屏显示输出。

命令示例:

I:\test\dir2>more I:\python\mysql_createdb.py

#usr/bin/python

#-*- coding:utf-8 -*-

#author:Fieldyang

import io

import os

import MySQLdb

import time

os.environ['NLS_LANG'] = "AMERICAN_AMERICA.ZHS16GBK"

I:\test\dir2>type I:\python\mysql_createdb.py|more

#usr/bin/python

#-*- coding:utf-8 -*-

#author:Fieldyang

import io

import os

import MySQLdb

import time

os.environ['NLS_LANG'] = "AMERICAN_AMERICA.ZHS16GBK"

5)、Del删除一个或多个文件。

命令示例:

6)、Attrib 显示或更改文件属性。

命令示例:

I:\test\dir2>type test0

helo world

I:\test\dir2>attrib test0

A I:\test\dir2\test0

I:\test\dir2>attrib +r test0

I:\test\dir2>echo helo field >>test0

拒绝访问。

I:\test\dir2>attrib -r test0

I:\test\dir2>echo helo field >>test0

I:\test\dir2>type test0

helo world

helo field

I:\test\dir2>

7)、Copy 将一份或多份文件复制到另一个位置。

命令示例:

8)、move 移动文件并重命名文件和目录

命令示例:

9)、ren 重命名文件

4、字符检索相关

1)、find 在文件中搜索字符串。

命令示例:

I:\test\dir2>find "NLS_LANG" I:\python\mysql_createdb.py

---------- I:\PYTHON\MYSQL_CREATEDB.PY

os.environ['NLS_LANG'] = "AMERICAN_AMERICA.ZHS16GBK"

I:\test\dir2>find "NLS_LANG" I:\python\*.py

---------- I:\PYTHON\1.PY

os.environ['NLS_LANG'] = "AMERICAN_AMERICA.ZHS16GBK"

---------- I:\PYTHON\2.PY

os.environ['NLS_LANG'] = "AMERICAN_AMERICA.ZHS16GBK"

---------- I:\PYTHON\CMD.PY

---------- I:\PYTHON\MONITOR.PY

---------- I:\PYTHON\MYSQL-REDIS.PY

os.environ['NLS_LANG'] = "AMERICAN_AMERICA.ZHS16GBK"

---------- I:\PYTHON\MYSQL_CREATEDB.PY

os.environ['NLS_LANG'] = "AMERICAN_AMERICA.ZHS16GBK"

---------- I:\PYTHON\REDIS-HASH.PY

---------- I:\PYTHON\REDIS-LIST.PY

---------- I:\PYTHON\REDIS-SET.PY

---------- I:\PYTHON\REDIS-STRING.PY

---------- I:\PYTHON\REDISTY.PY

---------- I:\PYTHON\TEST.PY

I:\test\dir2>

2)、findstr 在文件中寻找字符串。

命令示例

I:\test\dir2>findstr NLS_LANG I:\python\*.py

I:\python\1.py:os.environ['NLS_LANG'] = "AMERICAN_AMERICA.ZHS16GBK"

I:\python\2.py:os.environ['NLS_LANG'] = "AMERICAN_AMERICA.ZHS16GBK"

I:\python\mysql-redis.py:os.environ['NLS_LANG'] = "AMERICAN_AMERICA.ZHS16GBK"

I:\python\mysql_createdb.py:os.environ['NLS_LANG'] = "AMERICAN_AMERICA.ZHS16GBK"

I:\test\dir2>type I:\python\mysql_createdb.py |findstr NLS_LANG

os.environ['NLS_LANG'] = "AMERICAN_AMERICA.ZHS16GBK"

I:\test\dir2>

5、时间设置

1)、Date显示或设置日期。

DATE [/T | date]

显示当前日期设置和输入新日期的提示,请键入

不带参数的 DATE。要保留现有日期,请按 Enter。

如果命令扩展被启用,DATE 命令会支持 /T 开关;

该开关指示命令只输出当前日期,但不提示输入新日期。

2)、time显示或设置系统时间。

TIME [/T | time]

显示当前时间设置和输入新时间的提示,请键入

不带参数的 TIME。要保留现有时间,请按 Enter。

如果命令扩展被启用,TIME 命令会支持 /T 命令行开关;该命令行开关告诉

命令只输出当前时间,但不提示输入新时间。

6、进程相关

1)、Tasklist显示在本地或远程机器上当前运行的进程列表。

命令示例:

I:\test\dir2>tasklist|more

映像名称 PID 会话名 会话# 内存使用

========================= ======== ================ =========== ============

System Idle Process 0 Services 0 8 K

System 4 Services 0 24 K

Registry 108 Services 0 34,768 K

smss.exe 424 Services 0 232 K

csrss.exe 648 Services 0 2,236 K

^C^C

I:\test\dir2>tasklist|findstr System

System Idle Process 0 Services 0 8 K

System 4 Services 0 24 K

SystemSettings.exe 8448 Console 18 1,148 K

I:\test\dir2>

2)、Taskkill 杀死进程

命令示例

3)、Netstat显示协议统计信息和当前 TCP/IP 网络连接。

输入命令:

netstat -ano

该命令列出所有端口的使用情况。

在列表中我们观察被占用的端口,比如是 1224,首先找到它。

示例:

7、其他

1)、Set 显示、设置或删除 cmd.exe 环境变量。

命令示例:

I:\test\dir2>set a=hello

I:\test\dir2>set b=world

I:\test\dir2>set /A c=50

50

I:\test\dir2>set /A d=150

150

I:\test\dir2>set f=%a%and%b% +(%c%+%d%)

I:\test\dir2>echo %f%

helloandworld +(50+150)

I:\test\dir2>set e=%c%+%d

I:\test\dir2>echo %e%

50+150

I:\test\dir2>set /A g=%c%+%d%

200

I:\test\dir2>echo %G%

200

I:\test\dir2>

2)、Path 为可执行文件显示或设置一个搜索路径。

3)、Choice从选择列表选择一个项目并返回所选项目的索引。

命令示例

I:\test\dir1>CHOICE /C YNC /M "确认请按 Y,否请按 N,或者取消请按 C。"

确认请按 Y,否请按 N,或者取消请按 C。 [Y,N,C]?Y

I:\test\dir1> CHOICE /C ab /M "选项 1 请选择 a,选项 2 请选择 b。"

选项 1 请选择 a,选项 2 请选择 b。 [A,B]?A

I:\test\dir1>

4)、Goto将 cmd.exe 定向到批处理程序中带标签的行。

示例参考后面脚本

5)、Call 从批处理程序调用另一个批处理程序。

命令示例

I:\test\dir1>type test3.bat

echo You call another bat script test3.bat

echo Thanks for your call!

echo Goodbye!

I:\test\dir1>call test3.bat

I:\test\dir1>echo You call another bat script test3.bat

You call another bat script test3.bat

I:\test\dir1>echo Thanks for your call!

Thanks for your call!

I:\test\dir1>echo Goodbye!

Goodbye!

I:\test\dir1>

8、符号相关

1)、@ 关闭命令回显

命令示例:

I:\test\dir1>for %a in (1,2,3,4,5) do echo %a

I:\test\dir1>echo 1

I:\test\dir1>echo 2

2

I:\test\dir1>echo 3

3

I:\test\dir1>echo 4

4

I:\test\dir1>echo 5

5

I:\test\dir1>for %a in (1,2,3,4,5) do @echo %a

1

2

3

4

5

I:\test\dir1>@echo off

set /A a=5

5

set /A b=10

10

set c=%a%+%b%

set /A d =%a%+%b%

15

echo %c%

5+10

echo %d

%d

echo on

I:\test\dir1>

2)、| 管道符:同Linux,前一个命令的输出作为后一个命令的输入

Command1|command2

示例

3)、& 顺序执行多条命令,而不管命令是否执行成功

Command1&command2

示例 :先写“hello world”到test1,然后创建test0文件

可以看到 写入失败,但是创建文件成功

4)、&& 顺序执行多条命令,当碰到执行出错的命令后将不再执行后面的命令

Command1&&command2

示例 :先写“hello world”到test1,执行成功则创建test0文件

可以看到 写入失败,创建文件失败

5)、|| 顺序执行多条命令,当碰到执行正确的命令后将不再执行后面的命令

Command1||command2

示例 :先写“hello world”到test1,执行不成功则创建test0文件

可以看到写入失败,但是创建文件test0成功

示例 :修改test1文件可以写入,先写“hello world”到test1,执行成功则不创建test0文件

可以看到写入成功,不再创建test0文件

三、简单脚本

1、for循环

示例1:循环创建 test0-test4

for %i in (0,1,2,3,4) do echo >test%i

示例2:循环写入到test0

2、if else 判断

示例1:存在test0输出hello test0 否则输出 not exist test0

示例2:存在test5 打印hello test5 否则创建test5文件

示例3:如果变量i==C则创建dir_C目录,否则创建file_%i文件

示例4:如果定义变量则输出变量值,否则输出No define variable a1

3、if -else if-else 多层嵌套

示例1:如果定义变量则继续判断值是否匹配,没有定义则输出No define variable a1

4、choice根据用户输入执行不同操作

以下脚本演示Windows位置参数,choice选择、call调用、变量匹配

test2.bat

@echo off

:start

choice /c YNCPQ /m "确认请选Y,否请按N,取消按C,展示参数请安P,退出请按Q" /T 10 /D C

if errorlevel 5 goto quit

if errorlevel 4 goto para

if errorlevel 3 goto cancel

if errorlevel 2 goto no

if errorlevel 1 goto yes

:yes

echo You choice yes!

call I:\test\dir1\test3.bat

goto end

:no

echo You choice no!

goto end

:cancel

echo You choice cancel!

goto end

:para

if NOT "a%3"=="a" ( if "%3" == "cc" (echo hello %3) else (echo The bat script para is %1 %2 %3)) else if NOT "a%2"=="a" (echo The bat script para is %1 %2) else if not "a%1"=="a" (echo The bat script para is %1 ) else (echo No defined parameter)

goto end

:end

goto start

:quit

echo Goodbye!

pause

I:\test\dir1>type test3.bat

echo You call another bat script test3.bat

echo Thanks for your call!

echo Goodbye!