How To Delete Files & Folders – From The Windows Command Line (CMD, DOS)
Easily delete files, folders & directories from the command prompt (cmd), with just a few simple commands in your current as well as different directories.
Welcome!
This guide is all about input or output redirection, combining commands and pipes.
Lets get started!
Usually the only way to send input to the command line is with your keyboard.
However, we can also send input or output using a redirector.
A redirector is a special symbol that is used to, as the name suggests redirect the input or output from one command to another.
Let’s take a look at a few ways we can use redirectors.
Like we said before we can use redirectors to send input or output form one command to another. Lets try it.
For example we can redirect or transfer the output of the echo command and write it into a file by using a redirector.
Let’s type <strong”>echo, followed by the text we want our file to have, along with the greater than symbol, and the name we want our file to have along with its extension.
echo Hello World > File.txt
And our file has been created.
Using the greater than redirector will only create a new file.
To add text to an existing file we need to type the greater than symbol twice.
echo Goodbye World >> File.txt
Once again using the type command we can see that our text was added successfully.
Type File.txt
Pretty simple right?
In the windows command line, you can enter multiple commands with one line of code.
We used a redirector in the previously to redirect the output of the echo command into a file.
This time we are going to use a redirector to redirect from one command to another.
Let’s go through all the redirectors you can use to combine two commands.
Command1 && Command2
Command1 & Command2
Command1 || Command2
Command1 | Command2
You can also combine multiple redirectors. For example:
Command1 && Command2 || Command3
If the first command runs successfully command2 will be run if not command3 will be run instead.
You can use any of the above redirectors or a combination of them to complete any task you wish. For example, to create a file, move it to a new folder and view its contents you need to type:
echo Success > File.txt && mkdir "My Folder" && move File.txt "My Folder" && type "My Folder\File.txt"
Try using a combination of commands on your own using the redirectors you just learned, to make sure you understand them properly.
You now know what redirectors are and how you can use them from the command prompt.
If you liked this short guide take a look at a few of our other posts related to the windows command line, or if you really liked it consider enrolling in our video course where you will learn the ins and outs of the Windows command Line.
This course has everything you need to start learning about the windows command line along with batch scripting.
Easily delete files, folders & directories from the command prompt (cmd), with just a few simple commands in your current as well as different directories.
This guide is all about various cmd commands you can use to manage and troubleshoot networks directly from the windows command line.
The most useful commands, tips, tricks and hacks you can use to increace your efficiency and productivity with the command prompt (cmd).
Learn the Windows command line And Become an Expert!