(A Japanese translation is available here.)
In Bash, rm -rf
deletes a file or a directory. In PowerShell, I would like to do the same thing in a short command as well. Therefore, I created a PowerShell function to do the job.
Introduction
Let's say that I want to delete target
. In PowerShell, the following command does the job.
Remove-Item -Recurse -Force target
This is a long command even with tab completion. The following command is shortened version using officially provided aliases.
rm -r -fo target
This is still long when compared to rm -rf
in Bash.
Therefore, I decided to create a PowerShell function, rmrf
, for this job.
How to create the command
PowerShell profile needs to be created.
echo $profile
displays the file path of the profile. If the file does not exist, create it first.
In PowerShell profile, add the following function.
function rmrf { | |
<# | |
.DESCRIPTION | |
Deletes the specified file or directory. | |
.PARAMETER target | |
Target file or directory to be deleted. | |
.NOTES | |
This is an equivalent command of "rm -rf" in Unix-like systems. | |
#> | |
Param( | |
[Parameter(Mandatory=$true)] | |
[string]$Target | |
) | |
Remove-Item -Recurse -Force $Target | |
} |
After editing the profile, restart PowerShell to reload the profile.
Result
Issuing the following command will delete target
. It's short!
rmrf target
Top comments (0)