[20200224]windows命令学习笔记.txt
--//呆在家里没事,学习一些windows命令,做一个记录:
1.where 相当于linux下which命令:
d:\>where timeout
C:\Windows\System32\timeout.exe
--//cmd的内建命令是不能发现的。
d:\>where cd
信息: 用提供的模式无法找到文件。
d:\>where pause
信息: 用提供的模式无法找到文件。
2.timeout命令,相当于pause但是功能更加强大。
d:\>timeout /?
TIMEOUT [/T] timeout [/NOBREAK]
描述:
这个工具接受超时参数,等候一段指定的时间(秒)或等按任意键。它还接受
一个参数,忽视按键。
参数列表:
/T timeout 指定等候的秒数。有效范围从 -1 到 99999 秒。
/NOBREAK 忽略按键并等待指定的时间。
/? 显示此帮助消息。
注意: 超时值 -1 表示无限期地等待按键。
示例:
TIMEOUT /?
TIMEOUT /T 10
TIMEOUT /T 300 /NOBREAK
TIMEOUT /T -1
d:\>timeout /T 5
等待 0 秒,按一个键继续 ...
--//可以等5秒或者按一个键继续...
3.计算文件的md5,相当于linux下md5sum.
d:\>where md5sum
D:\tools\linux\usr\local\wbin\md5sum.exe
--//这个是我安装unxutils包,主要验证windows下是否计算正确。
d:\>md5sum usb.bat
badaa5c3f99352641f76ccf59c255248 *usb.bat
--//windows下使用certutil,顺便说一下certutil命令功能很多,我仅仅拿来计算md5.
d:\>certutil -hashfile -?
用法:
CertUtil [选项] -hashfile InFile [HashAlgorithm]
通过文件生成并显示加密哈希
选项:
-gmt -- 将时间显示为 GMT
-seconds -- 用秒和毫秒显示时间
-v -- 详细操作
-privatekey -- 显示密码和私钥数据
CertUtil -? -- 显示动词列表(命名列表)
CertUtil -hashfile -? -- 显示 "hashfile" 动词的帮助文本
CertUtil -v -? -- 显示所有动词的所有帮助文本
d:\>certUtil -hashfile usb.bat MD5
MD5 哈希(文件 usb.bat):
ba da a5 c3 f9 93 52 64 1f 76 cc f5 9c 25 52 48
CertUtil: -hashfile 命令成功完成。
--//对比完全能对上,只不过显示格式与前面不通。
d:\>CertUtil -hashfile usb.bat MD5 | findstr /v "hash MD5"
ba da a5 c3 f9 93 52 64 1f 76 cc f5 9c 25 52 48
d:\>CertUtil -hashfile usb.bat MD5 | findstr /v "hash MD5" | tr -d " "
badaa5c3f99352641f76ccf59c255248
--//windows的findstr语法很奇怪, findstr /v "hash MD5" ,相当于排除含有hash或者MD5的行。
--//再看看看powershell的语法,ms的东西真变态。本来想学习一点点,放弃。
d:\>powershell
Windows PowerShell
版权所有 (C) 2009 Microsoft Corporation。保留所有权利。
PS D:\> $(CertUtil -hashfile usb.bat MD5)
MD5 哈希(文件 usb.bat):
ba da a5 c3 f9 93 52 64 1f 76 cc f5 9c 25 52 48
CertUtil: -hashfile 命令成功完成。
PS D:\> $(CertUtil -hashfile usb.bat MD5)[1]
ba da a5 c3 f9 93 52 64 1f 76 cc f5 9c 25 52 48
--//语法有点点想bash shell,不知道ms是否抄袭^_^。要删除空格执行如下:
PS D:\> $(CertUtil -hashfile usb.bat MD5)[1] -replace " ",""
badaa5c3f99352641f76ccf59c255248
PS D:\> $(CertUtil -hashfile usb.bat MD5)[1]-replace " ",""
badaa5c3f99352641f76ccf59c255248
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/267265/viewspace-2676913/ ,如需转载,请注明出处,否则将追究法律责任。