Delete directory from command line

Delete directory from command line

Do you ever find yourself in the terminal and wanting to remove a bunch of files and folders or have a script that your writing and want it to prune the older copies? How do we do this? Turns out there is a command call rmdir that will do this in the shell.

***** BIG NOTE!! THIS COMMAND WILL BYPASS THE RECYCLE BIN AND PERMINENTLY DELETE

So you can see I am in the base folder call Backups, and inside that folder I created a folder called dude. I then ran the dir command to show that it was there, and then the magic command:

rmdir

So you can see that I did a rmdir dude which removed the directory called dude, and then I did a dir command to show that it was gone.

So what happens if the fodler is not empty? Well it will give an error and ask you want to do Example.

Ok super cool, great for human interactions but your writing a script or you know that it is ok to remove this folder so how do I bypass this I know what I am doing?? Cool, well lets do a powershell command for that now.

Remove-Item foldertodelete -Recurse -Force -Confirm:$false

So as you can see I had the same test directory as before, I showed the contents of the folder, then I ran that command, and poof it was all gone, no warning, no confirming, no nothing, its just gone.

This script / command is pretty much the same thing as the Linux version of rm -Rf /dir as this will kill itself very easily destorying a system if used wrong.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *