实用cmd命令

⌚Time: 2025-07-22 20:04:00

👨‍💻Author: Jack Ge

连续采集cpu使用率,间隔5s,记录在cpu_usage.csv文件里

typeperf "\Processor(_Total)\% Processor Time" -si 5 -o D:\cpu_usage.csv -f CSV

递归查找目录下文件

dir *名字* /s

显示文件目录树

tree dirpath

创建 10MB 文件

fsutil file createnew test.data 10485760

单位换算: 1KB = 1024 字节 1MB = 1048576 字节 1GB = 1073741824 字节


使用bat脚本,递归计算文件夹内的所有文件的sha256值,储存在同目录下,同名文件.sha256后缀文件。

@echo off

if "%~1"=="" (
    echo error
    pause
    exit /b 1
)

set "targetDir=%~1"

cd /d "%targetDir%"

for /R %%i in (*) do (
    if not "%%i"=="%~nx0" (
        echo Processing: %%~nxi
        
        REM switch to dir
        pushd "%%~dpi"
        
        REM only use file name to hash
        certutil -hashfile "%%~nxi" SHA256 > "%%~nxi.sha256"
        
        REM return original dir
        popd
    )
)

pause

使用的时候将目录拖到bat脚本上处理