wind10 檔名區分大小寫
Windows 10 四月更新,資料夾名稱也能區分大小寫了
釋出於 2018-06-14 00:02 更新於 2018-09-01 00:03
Linux 一向都是區分檔案和資料夾大小寫的。Mac OS 預設不區分檔案和資料夾大小寫,不過可以配置成支援。而 Windows 向來是不區分檔案和資料夾大小寫的,但是從 NTFS 開始卻又支援區分資料夾大小寫。
本文將介紹 Windows 10 四月更新帶來的新特性 —— 讓資料夾名稱也能區分大小寫。
問題
本來檔案系統是否區分大小寫只是單純風格上的差異,並沒有孰優孰劣,但這可讓那些跨平臺的檔案系統難以抉擇了。典型的例子就是 Git。
我曾經就遭遇過 Git 操作上的大小寫敏感性問題,寫了一篇部落格:
由於 Windows 檔案系統對大小寫不敏感,所以上面的問題才變得尤其難辦,竟然需要通過至少兩次提交,並且丟掉單線的 Git 歷史記錄的方式才能真正完成任務。而單純讓 Git 在倉庫中區分大小寫竟然會產生兩份檔案(卻無法在 Windows 系統中觀察到)。
開啟方法
Windows 10 四月更新終於帶來了資料夾區分大小寫的支援!
使用管理員許可權在當前資料夾啟動 PowerShell:
fsutil.exe file SetCaseSensitiveInfo C:\Users\walterlv\GitDemo enable
是的,就是上面這一段非常簡單而容易理解的命令即可開啟單個資料夾的名稱區分大小寫功能。只是單個資料夾!如果需要開啟其他資料夾,需要多次執行這樣的命令。
而如果需要關閉對此資料夾的大小寫支援,只需要將 enable
改為 disable
。
fsutil.exe file SetCaseSensitiveInfo C:\Users\walterlv\GitDemo disable
看!以上就是在 Windows 10 系統級開啟了大小寫敏感的我的一個 Git 倉庫,這下可以讓跨平臺的 Git 工作起來在各個系統都一樣了。
注意事項
以上命令的正確執行需要以下條件,缺一不可:
- Windows 10 四月更新(1803)
- 安裝有 Linux 子系統,即 Windows Subsystem for Linux
- 所在分割槽為 NTFS 格式
- 以管理員許可權執行 PowerShell
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
fsutil.exe file setCaseSensitiveInfo D:\Study\Code enable
fsutil.exe file setCaseSensitiveInfo D:\Study\Code disable
如果沒有安裝 Linux 子系統,那麼執行時會出現以下錯誤:
錯誤:不支援該請求。
▲ 中文版 PowerShell
The request is not supported.
▲ 英文版 PowerShell
這個問題在 MicrosoftDocs 的 GitHub 倉庫中被提到了:fsutil setCaseSensitiveInfo · Issue #977 · MicrosoftDocs/windowsserverdocs。
安裝 Linux 子系統的方法可以參考微軟官方文件:Install Windows Subystem for Linux (WSL) on on Windows 10。如果英文閱讀有壓力,可以參考毒逆天的部落格:Win10 安裝 Linux子系統 Ubuntu18.04 / Kali Linux 的體驗。
簡單點,就是管理員許可權 PowerShell 敲個命令:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
或者命令都懶得敲,就是去商店下載(在商店搜尋 Linux):
附
fsutil file
支援的命令:
⚡ [email protected]> fsutil.exe file ---- FILE Commands Supported ---- createNew Creates a new file of a specified size findBySID Find a file by security identifier layout Query all the information available about the file optimizeMetadata Optimize metadata for a file queryAllocRanges Query the allocated ranges for a file queryCaseSensitiveInfo Query the case sensitive information for a directory queryExtents Query the extents for a file queryExtentsAndRefCounts Query the extents and their corresponding refcounts for a file queryFileID Queries the file ID of the specified file queryFileNameById Displays a random link name for the file ID queryOptimizeMetadata Query the optimize metadata state for a file queryValidData Queries the valid data length for a file setCaseSensitiveInfo Set the case sensitive information for a directory setShortName Set the short name for a file setValidData Set the valid data length for a file setZeroData Set the zero data for a file setEOF Sets the end of file for an existing file setStrictlySequential Sets ReFS SMR file as strictly sequential
fsutil 支援的命令:
⚡ [email protected]> fsutil.exe ---- Commands Supported ---- 8dot3name 8dot3name management behavior Control file system behavior dax Dax volume management dirty Manage volume dirty bit file File specific commands fsInfo File system information hardlink Hardlink management objectID Object ID management quota Quota management repair Self healing management reparsePoint Reparse point management resource Transactional Resource Manager management sparse Sparse file control tiering Storage tiering property management transaction Transaction management usn USN management volume Volume management wim Transparent wim hosting management