Notes on deleting directories and files owned by other users¶
Any user wanting to delete directories and files owned by a different user, must be a member of the Administrators group. The Windows commands takeown and icacls are needed to change the owner and permissions, respectively, of any files and directories.
The command to change the owner of a directory(as well as its contents) uses the following format.
takeown /f DIRECTORYPATH /R
- The command to change the owner of a file uses the following format.
takeown /f FILEPATH
- The command to grant a user the Modify permission on a directory(as well as its contents) uses the following format.
icacls DIRECTORYPATH /T /grant USERNAME:M
- The command to grant a user the Modify permission on a file uses the following format.
icacls FILEPATH /grant USERNAME:M
Procedure¶
Run a Cygwin terminal with Administrator privileges - Right-click on your Cygwin terminal shortcut and click on Run as Administrator,then run any of the following - after modifying folder or filename paths to suit your environment. After successfully completing the appropriate commands below, the user will have sufficient permission to delete the file(s) or directorie(s) that the user was granted Modify permissions to.
Run the following to take ownership of D:\bison\calf.txt only
takeown /f "D:\bison\calf.txt"
- Run the following to take ownership of folder D:\bison and its contents.
takeown /f "D:\bison" /R
- Run the following to grant Modify permission on file D:\bison\calf.txt to user janedoe.
icacls "D:\bison\calf.txt" /grant janedoe:M
- Run the following to grant Modify permission on folder D:\bison and its contents to user janedoe.
icacls "D:\bison" /T /grant janedoe:M
Updated by Redmine Admin about 9 years ago · 1 revisions