Delete a directory.
Rmdir [/S] [/q] [drive:] path
Rd [/S] [/q] [drive:] path
In addition to the directory,/s also deletes all subdirectories and
File. Used to delete a directory tree.
/Q quiet mode. confirmation is not required when/s is used to delete the directory tree.
Found from cmvc Report-testserver> NUL
------------------------------------
Since
2> NUL can block the output of error messages. Why should we use it?
> NUL 2> what about NUL? Let's take a look at the next example.
Although the/Q parameter is used in the del command for silent deletion, the/S parameter is also used.
Parameter, so that the deleted file information is output to the handle as a standard, which must be 1> NUL
> NUL. In actual use, for example, to delete files in the sub-folders in a temporary folder, you can run the following command:
Del/f/S/Q % Temp % /*.*
The/S parameter must be used to delete files in the % Temp % subdirectory. The/s
Parameter to display the file name being deleted. This information is output by 1 handle as a standard, so use 1> NUL to block it. While
Some files in % Temp % may not be deleted because they are being called by some programs. This information is output incorrectly by two handles.
2> NUL. Therefore, to shield the output information, the command must be written as follows:
Del/f/S/Q % Temp %/*. *> NUL
2> NUL
To sum up,> NUL
It means to redirect the standard output request generated by this command to an empty device. Because of the silence of this device, it is equivalent to shielding (not hiding) the output information of this statement.
2> NUL
This is to output the standard error information during program execution errors to request redirection and block them. They are used together to shield all output information that may be generated by this statement.
(3) Secondary redirection
What is secondary redirection?> NUL
2> NUL
Is a typical secondary redirection. In general, secondary redirection will not cause problems, but there are exceptions, such:
Echo. 2> NUL 3> NUL
After this command is executed, no error messages are displayed.
Echo. 1> NUL 3> NUL
After this command is executed, all output prompts are invisible (but the error prompt is displayed )?
These two commands cannot be used at the same time.
When the following statement is executed, it will be displayed cyclically and cannot be stopped:
Echo. 0> NUL 3> NUL
In addition:
Echo. 2> NUL 3> test.txt
Then, the error information will be written to test.txt.
Likewise,
Echo. 1> NUL 3> test.txt
The standard output information is written to test.txt.
Why?
This is indeed an interesting and meaningful topic. This strange phenomenon seems to exist between undisclosed features and program algorithm vulnerabilities because it is not published in official documents.
After a simple test, the following conclusions are obtained:
This phenomenon is caused by secondary redirection of the handle and has nothing to do with the command body of the statement;
The secondary redirection targets can be different. The previous redirection affects this statement, and the subsequent redirection affects the CMD environment after the statement ends;
The handle for the next redirection must be undefined and never used before the previous redirection. This operation is immediately voided and cannot be reused for the handle redirection in the default cmd environment;
My speculation about this phenomenon is as follows:
When a statement in cmd modifies the handle (redirection or replication), the designer restores the modified handle after the statement is executed, it will inevitably be copied (or standby) before modification.
As for the backup destination, CMD selects the "undefined handle (3-9)" that has never been used before. This seems to be an understandable choice. However, when the program judges and obtains unused handles, it is clear that
Some vulnerabilities exist. They first deal with the first modification operation. After obtaining the handle to be modified, they immediately look for unused backup handles. After finding the backup handle and backing it up, to process subsequent modifications.
This backup handle can still be modified. After the statement ends, CMD will use the modified backup handle to restore the first modified handle, and finally the default cmd handle will be modified. In this case, CMD only
If you know that the backup handle has been used, the "unused handle" after the handle is modified in the Next statement will be used for backup.
The following statement should be similar, but more accurate description of the time to obtain the backup handle.
Pause 1> & 3
3> NUL
Therefore, the CMD help document's statement about 3-9 being an undefined handle should not be accurate enough, because it will indeed be moved by the system for other purposes, rather than "defined separately by the application, they are unique to each tool. From this perspective, they are more like "Reserved handles ".
In addition, the process of handling in cmd is obviously more complicated, especially the process of copying a handle, even if Microsoft documents are not detailed. For example, the following statement can copy stdout
Stderr, and stderr is redirected to the NUL device. As a result, the pause stdout is redirected to the NUL device, that is, no output. This is understandable.
Pause 2> NUL
1> & 2
In the following statement, only copying and redirection operations are reversed and no longer valid. This should also be related to the CMD features mentioned above.
Pause 1> & 2
2> NUL
Finally, it should be mentioned that in cmd, the handle has read/write attributes, stdin is read-only, stdout is write-only, stderr is readable and writable, and no other definition is defined. The read/write attributes of the handle are also copied.