remove-nul

star 0

在 Windows 環境下刪除無法正常移除的保留裝置名稱檔案(如 nul、con、aux、prn、com1~com9、lpt1~lpt9)。 當使用者遇到以下情境時必須載入此技能:git status 顯示有 nul 檔案、想刪除 nul 但 del/PowerShell/git rm 都失敗、 看到 "Permission denied" 錯誤無法刪除某個奇怪的檔案、詢問「remove nul file」、「怎麼刪除 nul 檔」、 「nul 檔案刪不掉」、「Windows 保留裝置名稱怎麼清除」等相關問題。

Ting-s515 By Ting-s515 schedule Updated 3/4/2026

name: remove-nul description: > 在 Windows 環境下刪除無法正常移除的保留裝置名稱檔案(如 nul、con、aux、prn、com1com9、lpt1lpt9)。 當使用者遇到以下情境時必須載入此技能:git status 顯示有 nul 檔案、想刪除 nul 但 del/PowerShell/git rm 都失敗、 看到 "Permission denied" 錯誤無法刪除某個奇怪的檔案、詢問「remove nul file」、「怎麼刪除 nul 檔」、 「nul 檔案刪不掉」、「Windows 保留裝置名稱怎麼清除」等相關問題。

刪除 nul 檔案

背景說明

在 Windows 環境中,nul 是系統保留的裝置名稱(類似 conauxprn 等),無法透過一般方式(如 delPowerShell Remove-Itemgit rm)刪除。需要透過 Git Bash 的 POSIX 檔案操作來繞過此限制。

執行流程

  1. 確認檔案存在:執行 git status --short -- nul 確認 nul 檔案存在於工作目錄中
  2. 刪除檔案:在 Git Bash 環境下執行 rm -f nul
  3. 驗證結果:再次執行 git status --short -- nul 確認檔案已被移除

指令

# 步驟 1:確認檔案存在
git status --short -- nul

# 步驟 2:刪除 nul 檔案(Git Bash 環境下執行)
rm -f nul

# 步驟 3:驗證刪除結果
git status --short -- nul

為什麼其他方式無效

指令 結果 原因
git rm nul 失敗 檔案為 untracked,不在 git 追蹤中
git clean -f -- nul Permission denied Windows 保護保留裝置名稱
cmd /c "del \\?\C:\...\nul" 無效 Windows cmd 無法正確處理
PowerShell Remove-Item 失敗 無法辨識 \\?\ 路徑前綴
rm -f nul(Git Bash) 成功 Git Bash 使用 POSIX 檔案操作,不受 Windows 保留名稱限制

補充說明

  • 此技能適用於所有 Windows 保留裝置名稱檔案(nulconauxprncom1com9lpt1lpt9
  • 必須在 Git Bash 環境下執行,不適用於 cmd 或 PowerShell
Install via CLI
npx skills add https://github.com/Ting-s515/skills --skill remove-nul
Repository Details
star Stars 0
call_split Forks 0
navigation Branch main
article Path SKILL.md
More from Creator