Powershell: Removing a hidden file in Unix results in RemoveFileSystemItemUnAuthorizedAccess

Created on 8 Dec 2019  路  5Comments  路  Source: PowerShell/PowerShell

Steps to reproduce

New-Item .x
Remove-Item .x

Expected behavior

The file should either be removed without having to specify -Force. Removing it with /bin/rm .x works without needing to specify -f

Actual behavior

Remove-Item : You do not have sufficient access rights to perform this operation.                                                                                                                                                                                                          At line:1 char:1                                                                                                                                                                                                                                                                           + Remove-Item .x                                                                                                                                                                                                                                                                           + ~~~~~~~~~~~~~~                                                                                                                                                                                                                                                                           + CategoryInfo          : PermissionDenied: (/tmp/.x:FileInfo) [Remove-Item], IOException
+ FullyQualifiedErrorId : RemoveFileSystemItemUnAuthorizedAccess,Microsoft.PowerShell.Commands.RemoveItemCommand

Environment data

Name                           Value
----                           -----
PSVersion                      6.2.3
PSEdition                      Core
GitCommitId                    6.2.3
OS                             Darwin 19.0.0 Darwin Kernel Version 19.0.0: Thu Oct 17 16:17:15 PDT 2019; root:xnu-6153.41.3~29/RELEASE_X86_64
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0鈥
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
Area-Cmdlets-Core Issue-Discussion OS-Linux OS-macOS Up-for-Grabs

Most helpful comment

It seems that the behavior is consistent within PowerShell so probably shouldn't change that. Seems like the error could be better saying because it is hidden and not a permission problem.

All 5 comments

For clarity, your OS is macOS Catalina.

Correct. However, I just tested the same version of Powershell in Arch Linux. The results are the same but with a slightly different error id:

Remove-Item : You do not have sufficient access rights to perform this operation.
At line:1 char:1
+ Remove-Item .x
+ ~~~~~~~~~~~~~~
+ CategoryInfo          : PermissionDenied: (/home/roey/src/aur/topgrade/.x:FileInfo) [Remove-Item], IOException
+ FullyQualifiedErrorId : RemoveFileSystemItemUnAuthorizedAccess,Microsoft.PowerShell.Commands.RemoveItemCommand

I think this behaviour is inherited from the FileSystem provider and possibly from .NET Core's System.IO.File APIs. On Windows, this behaviour is the same (and always has been) -- you need to specify -Force to remove hidden files.

Not sure if we'd want to change this behaviour specifically for Unix or not, though. @SteveL-MSFT thoughts? 馃槉

It seems that the behavior is consistent within PowerShell so probably shouldn't change that. Seems like the error could be better saying because it is hidden and not a permission problem.

The design with hidden files was that -force should be required for all operations e.g. ls -force to list them, etc. Technically, using -force expands the set of operation you can do so the "insufficient access rights" message makes "sense" if you fully understand the design. But practically, a message saying "use -force to delete hidden files" would be more useful. Alternately we could simply remove the restriction so no message is required.

Was this page helpful?
0 / 5 - 0 ratings