admin 管理员组文章数量: 1184232
C盘空间总是莫名其妙变少?清理临时文件、回收站效果有限?其实,真正占用C盘空间的“大头”往往藏在系统休眠、还原点、WinSxS、Windows.old等深层区域。本文带来一套“极客级一键脚本+官方工具组合拳”,让你无需手动甄别,轻松暴涨C盘空间!
一、脚本清理范围(全自动,覆盖深度垃圾)
- 关闭休眠(删除hiberfil.sys)
- 清理系统还原点/影子副本
- 清理WinSxS(组件存储)
- 清理Windows.old(升级残留)
- 清理虚拟内存(可选,需手动设置)
- 清理临时文件、回收站、日志
- 清理Windows更新缓存
- 清理常见软件缓存(如微信、QQ、Edge、Chrome等,需自定义路径)
二、一键极致瘦身PowerShell脚本(专业版)
1. **打开PowerShell**:
- 在电脑桌面点击键盘 `Win` 键或点击电脑任务栏下方开始按钮。
- 搜索框输入powershell,点击以管理员身份运行。
2.运行PowerShell命令脚本
输入以下PowerShell命令,并且点击键盘回车键
# 专业版一键极致瘦身C盘脚本 - 支持循环菜单、智能检测、安全备份
# 保存为 .ps1 文件,右键以管理员身份运行
# 检查管理员权限
if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
Write-Host "错误:需要管理员权限运行此程序" -ForegroundColor Red
Write-Host "请右键点击此文件,选择'以管理员身份运行'" -ForegroundColor Yellow
Read-Host "按回车键退出"
exit
}
# 设置控制台编码和颜色
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$Host.UI.RawUI.WindowTitle = "C盘极致瘦身工具 v2.0"
# 创建清理日志
$logFile = "C:\cleanup_log_$(Get-Date -Format 'yyyyMMdd_HHmmss').txt"
Start-Transcript -Path $logFile -Append
# 主菜单函数
function Show-Menu {
Clear-Host
Write-Host "=========================================" -ForegroundColor Cyan
Write-Host " C盘极致瘦身工具 v2.0" -ForegroundColor Yellow
Write-Host "=========================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "请选择操作:" -ForegroundColor White
Write-Host "1. 基础清理(临时文件、回收站、日志)" -ForegroundColor Green
Write-Host "2. 深度清理(+休眠、还原点、WinSxS、Windows.old)" -ForegroundColor Green
Write-Host "3. 极致清理(+软件缓存、大文件扫描、虚拟内存优化)" -ForegroundColor Green
Write-Host "4. 自定义清理(手动选择项目)" -ForegroundColor Green
Write-Host "5. 恢复系统功能(重新开启休眠和系统还原)" -ForegroundColor Yellow
Write-Host "6. 查看C盘空间" -ForegroundColor Blue
Write-Host "0. 退出程序" -ForegroundColor Red
Write-Host ""
}
# 基础清理函数
function Basic-Cleanup {
Write-Host "执行基础清理..." -ForegroundColor Cyan
Remove-Item -Path "$env:TEMP\*" -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item -Path "C:\Windows\Temp\*" -Recurse -Force -ErrorAction SilentlyContinue
Clear-RecycleBin -Force -ErrorAction SilentlyContinue
Remove-Item -Path "C:\Windows\SoftwareDistribution\Download\*" -Recurse -Force -ErrorAction SilentlyContinue
Get-ChildItem -Path "C:\" -Include *.log -Recurse -Force -File -ErrorAction SilentlyContinue | Remove-Item -Force -ErrorAction SilentlyContinue
Write-Host "基础清理完成!" -ForegroundColor Green
}
# 深度清理函数
function Deep-Cleanup {
Write-Host "执行深度清理..." -ForegroundColor Cyan
Basic-Cleanup
# 关闭休眠
powercfg -h off
Write-Host "已关闭休眠,释放hiberfil.sys" -ForegroundColor Green
# 清理系统还原点
vssadmin delete shadows /for=C: /all /quiet
Write-Host "已清理系统还原点" -ForegroundColor Green
# 清理WinSxS
Dism.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase
Write-Host "已清理WinSxS组件存储" -ForegroundColor Green
# 清理Windows.old
if (Test-Path "C:\Windows.old") {
Remove-Item -Path "C:\Windows.old" -Recurse -Force -ErrorAction SilentlyContinue
Write-Host "已清理Windows.old" -ForegroundColor Green
}
Write-Host "深度清理完成!" -ForegroundColor Green
}
# 极致清理函数
function Ultimate-Cleanup {
Write-Host "执行极致清理..." -ForegroundColor Cyan
Deep-Cleanup
# 智能检测并清理软件缓存
Write-Host "清理软件缓存..." -ForegroundColor Yellow
# 微信缓存
if (Test-Path "$env:USERPROFILE\Documents\WeChat Files") {
Remove-Item -Path "$env:USERPROFILE\Documents\WeChat Files\*\FileStorage\*" -Recurse -Force -ErrorAction SilentlyContinue
Write-Host "已清理微信缓存" -ForegroundColor Green
}
# QQ缓存
if (Test-Path "$env:USERPROFILE\Documents\Tencent Files") {
Remove-Item -Path "$env:USERPROFILE\Documents\Tencent Files\*\FileRecv\*" -Recurse -Force -ErrorAction SilentlyContinue
Write-Host "已清理QQ缓存" -ForegroundColor Green
}
# Chrome缓存
if (Test-Path "$env:LOCALAPPDATA\Google\Chrome\User Data\Default\Cache") {
Remove-Item -Path "$env:LOCALAPPDATA\Google\Chrome\User Data\Default\Cache\*" -Recurse -Force -ErrorAction SilentlyContinue
Write-Host "已清理Chrome缓存" -ForegroundColor Green
}
# Edge缓存
if (Test-Path "$env:LOCALAPPDATA\Microsoft\Edge\User Data\Default\Cache") {
Remove-Item -Path "$env:LOCALAPPDATA\Microsoft\Edge\User Data\Default\Cache\*" -Recurse -Force -ErrorAction SilentlyContinue
Write-Host "已清理Edge缓存" -ForegroundColor Green
}
# Steam游戏缓存
if (Test-Path "$env:PROGRAMFILES(X86)\Steam\steamapps\downloading") {
Remove-Item -Path "$env:PROGRAMFILES(X86)\Steam\steamapps\downloading\*" -Recurse -Force -ErrorAction SilentlyContinue
Write-Host "已清理Steam下载缓存" -ForegroundColor Green
}
# Adobe软件缓存
$adobePaths = @(
"$env:LOCALAPPDATA\Adobe\CEP\extensions",
"$env:APPDATA\Adobe\CEP\extensions",
"$env:LOCALAPPDATA\Adobe\Common\Media Cache Files",
"$env:LOCALAPPDATA\Adobe\Common\Media Cache"
)
foreach ($path in $adobePaths) {
if (Test-Path $path) {
Remove-Item -Path "$path\*" -Recurse -Force -ErrorAction SilentlyContinue
Write-Host "已清理Adobe缓存: $path" -ForegroundColor Green
}
}
# 开发工具缓存
$devTools = @(
"$env:APPDATA\Code\Cache",
"$env:APPDATA\JetBrains\*\system\caches",
"$env:LOCALAPPDATA\Microsoft\VisualStudio\*\ComponentModelCache",
"$env:APPDATA\Microsoft\VisualStudio\*\ComponentModelCache"
)
foreach ($tool in $devTools) {
if (Test-Path $tool) {
Remove-Item -Path "$tool\*" -Recurse -Force -ErrorAction SilentlyContinue
Write-Host "已清理开发工具缓存: $tool" -ForegroundColor Green
}
}
# 虚拟机文件检测(提示用户)
$vmPaths = @(
"$env:USERPROFILE\Documents\Virtual Machines",
"$env:USERPROFILE\VirtualBox VMs",
"$env:USERPROFILE\VMware"
)
$vmFound = $false
foreach ($vmPath in $vmPaths) {
if (Test-Path $vmPath) {
$vmSize = (Get-ChildItem -Path $vmPath -Recurse -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum).Sum
if ($vmSize -gt 1GB) {
Write-Host "发现虚拟机文件: $vmPath (大小: $([math]::Round($vmSize/1GB,2)) GB)" -ForegroundColor Yellow
$vmFound = $true
}
}
}
if ($vmFound) {
Write-Host "建议:虚拟机文件占用空间较大,可考虑转移到其他分区" -ForegroundColor Cyan
}
# 清理系统事件日志
wevtutil el | ForEach-Object {wevtutil cl "$_" 2>$null}
Write-Host "已清理系统事件日志" -ForegroundColor Green
# 虚拟内存检测与提示
$pagefile = Get-WmiObject -Class Win32_PageFileUsage -ErrorAction SilentlyContinue
if ($pagefile) {
Write-Host "当前虚拟内存: $([math]::Round($pagefile.AllocatedBaseSize/1GB,2)) GB" -ForegroundColor Yellow
Write-Host "建议:可在系统属性-高级-性能-虚拟内存中调整虚拟内存大小" -ForegroundColor Cyan
}
Write-Host "极致清理完成!" -ForegroundColor Green
}
# 自定义清理函数
function Custom-Cleanup {
Write-Host "`n自定义清理选项:" -ForegroundColor Cyan
Write-Host "a. 扫描大文件(>100MB)" -ForegroundColor White
Write-Host "b. 清理OneDrive本地缓存" -ForegroundColor White
Write-Host "c. 清理其他软件缓存" -ForegroundColor White
$custom = Read-Host "请输入选择 (a/b/c,多个用逗号分隔,直接回车跳过)"
if ($custom -like "*a*") {
Write-Host "`n扫描大文件..." -ForegroundColor Yellow
# 优化:只扫描常见大文件目录,提升性能
$scanPaths = @(
"$env:USERPROFILE\Downloads",
"$env:USERPROFILE\Desktop",
"$env:USERPROFILE\Documents",
"$env:USERPROFILE\Pictures",
"$env:USERPROFILE\Videos",
"$env:USERPROFILE\Music"
)
$largeFiles = @()
foreach ($path in $scanPaths) {
if (Test-Path $path) {
$files = Get-ChildItem -Path $path -Recurse -File -ErrorAction SilentlyContinue | Where-Object {$_.Length -gt 100MB} | Select-Object FullName, @{Name="Size(GB)";Expression={[math]::Round($_.Length/1GB,2)}} | Sort-Object "Size(GB)" -Descending | Select-Object -First 5
$largeFiles += $files
}
}
if ($largeFiles) {
Write-Host "发现大文件:" -ForegroundColor Yellow
$largeFiles | Sort-Object "Size(GB)" -Descending | Select-Object -First 10 | Format-Table -AutoSize
Write-Host "建议:手动检查并转移这些大文件到其他分区" -ForegroundColor Cyan
} else {
Write-Host "未发现大文件" -ForegroundColor Green
}
}
if ($custom -like "*b*") {
if (Test-Path "$env:USERPROFILE\OneDrive") {
Remove-Item -Path "$env:USERPROFILE\OneDrive\*" -Recurse -Force -ErrorAction SilentlyContinue
Write-Host "已清理OneDrive本地缓存" -ForegroundColor Green
}
}
if ($custom -like "*c*") {
# 清理其他常见软件缓存
$otherCaches = @(
"$env:LOCALAPPDATA\Temp",
"$env:APPDATA\Temp",
"$env:USERPROFILE\AppData\Local\Microsoft\Windows\INetCache",
"$env:USERPROFILE\AppData\Local\Microsoft\Windows\WebCache",
"$env:LOCALAPPDATA\Microsoft\Windows\Explorer\ThumbCacheToDelete",
"$env:APPDATA\Microsoft\Windows\Recent"
)
foreach ($cache in $otherCaches) {
if (Test-Path $cache) {
Remove-Item -Path "$cache\*" -Recurse -Force -ErrorAction SilentlyContinue
Write-Host "已清理: $cache" -ForegroundColor Green
}
}
}
Write-Host "自定义清理完成!" -ForegroundColor Green
}
# 恢复系统功能函数
function Restore-System {
Write-Host "恢复系统功能..." -ForegroundColor Cyan
# 重新开启休眠
powercfg -h on
Write-Host "已重新开启休眠" -ForegroundColor Green
# 重新开启系统还原
Enable-ComputerRestore -Drive "C:\"
Write-Host "已重新开启系统还原" -ForegroundColor Green
Write-Host "恢复完成!" -ForegroundColor Green
}
# 显示C盘空间函数
function Show-DiskSpace {
$drive = Get-PSDrive C
Write-Host "C盘空间信息:" -ForegroundColor Cyan
Write-Host "总容量: $([math]::Round($drive.Used/1GB + $drive.Free/1GB,2)) GB" -ForegroundColor White
Write-Host "已使用: $([math]::Round($drive.Used/1GB,2)) GB" -ForegroundColor Yellow
Write-Host "可用空间: $([math]::Round($drive.Free/1GB,2)) GB" -ForegroundColor Green
Write-Host "使用率: $([math]::Round($drive.Used/($drive.Used + $drive.Free)*100,1))%" -ForegroundColor White
}
# 智能建议函数
function Show-SmartAdvice {
$drive = Get-PSDrive C
$freeSpace = [math]::Round($drive.Free/1GB,2)
Write-Host "`n=== 智能建议 ===" -ForegroundColor Magenta
if ($freeSpace -lt 10) {
Write-Host "⚠️ C盘空间不足,建议:" -ForegroundColor Yellow
Write-Host " • 运行深度清理或极致清理" -ForegroundColor White
Write-Host " • 检查下载、文档、桌面等文件夹中的大文件" -ForegroundColor White
Write-Host " • 考虑卸载不常用的大型软件或游戏" -ForegroundColor White
} elseif ($freeSpace -lt 20) {
Write-Host "✅ C盘空间一般,建议:" -ForegroundColor Green
Write-Host " • 定期运行基础清理保持C盘干净" -ForegroundColor White
Write-Host " • 开启存储感知自动清理" -ForegroundColor White
} else {
Write-Host "🎉 C盘空间充足!" -ForegroundColor Green
Write-Host " • 建议定期运行清理脚本保持系统流畅" -ForegroundColor White
}
}
# 主程序循环
do {
Show-Menu
$choice = Read-Host "请输入选择 (0-6)"
switch ($choice) {
"1" {
Basic-Cleanup
Show-SmartAdvice
Read-Host "按回车键继续..."
}
"2" {
Deep-Cleanup
Show-SmartAdvice
Read-Host "按回车键继续..."
}
"3" {
Ultimate-Cleanup
Show-SmartAdvice
Read-Host "按回车键继续..."
}
"4" {
Custom-Cleanup
Show-SmartAdvice
Read-Host "按回车键继续..."
}
"5" {
Restore-System
Read-Host "按回车键继续..."
}
"6" {
Show-DiskSpace
Read-Host "按回车键继续..."
}
"0" {
Write-Host "感谢使用!清理日志已保存到: $logFile" -ForegroundColor Green
Stop-Transcript
Read-Host "按回车键退出"
exit
}
default {
Write-Host "无效选择,请重新输入!" -ForegroundColor Red
Start-Sleep -Seconds 2
}
}
} while ($true)
复制命令并且回车之后效果如图所示,可进入C盘极致瘦身工具 :
3.操作和简单使用
(1)查看C盘空间
输入数字6并且回车,即可查看当前C盘的占用率和使用情况,方便您在后续清理之后查询:
(2)清理功能
清理功能包括基础清理、深度清理和极致清理,清理的程度和时间如名称含义相同,越是细致的时间越长,但效果越好(这里已经测试过所有的清理方式,并且保障系统和电脑的安全,所以不做细致的演示)。
(3)恢复系统功能(重新开启休眠和系统还原)
数字5功能为重新开启休眠和系统还原功能。在进行极致清理时会关闭系统休眠和系统还原存储,关闭的原因是因为它们常常会产生大量存储,对于系统空间占用较大,但是也能够起到一定的系统保护的作用,可根据个人需要在进行极致清理进行再次打开(不推荐打开)。
(4)自定义清理
输入数字4可进入自定义清理,这个功能清理速度较快,具有一定针对性,适合在卸载电脑C盘软件,或进行C盘操作之后进行快速清理,建议拥有一定windows操作理解的人员更为方便,自定义扫描选项如下:
清理其他软件缓存功能示意:
致谢
非常感谢你阅读到这里!如果这篇文章对你有帮助,欢迎点赞、收藏并分享给需要的朋友。你的支持是我持续更新 Win11 实用技巧的最大动力。如果你有更好的做法或遇到问题,留言告诉我,我会尽快回复并完善内容。也欢迎关注我的主页,获取后续的脚本与懒人包更新。
版权声明:本文标题:C盘空间不够?10条官方命令+一键脚本,实测释放至少30%空间 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/b/1764912029a3329444.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论