Let us know which solution worked for you in the comments section down below.
Текущая версия страницы пока не проверялась
опытными участниками и может значительно отличаться от версии
, проверенной 22 сентября 2021 года; проверки требуют 2 правки
.
Working on Command Prompt in Windows requires you to clear the screen frequently. It could be you are doing a long task, and the crowded screen is distracting you. You might also want to clear the screen if you have entered sensitive information in the Command Prompt. That’s why you should know how to clear Command Prompt without letting it affect your work.
Depending on your situation, there are many ways to clear the Command Prompt. You can learn different ways to clear the CMD screen by reading this article till the end.
Some folders and files are impossible to delete using Windows Explorer. These include files with long paths, names or reserved names like CON, AUX, COM1, COM2, COM3, COM4, LPT1, LPT2,
Regardless of the reason, these can only be force deleted using command line only. This article explains using cmd to delete folder or file successfully.
Table of contents
- Before we begin
- How to remove files and folders using Command Prompt
- How to remove files and folders using Windows PowerShell
- Delete files and folders with complex and long paths using the command line
- Closing words
Use CLS Command to Clear Command Prompt Screen
One of the simplest and most common ways to clear the screen in CMD is to use the clear or “cls” command. This command can clear your Command Prompt screen without clearing the history. You can access the previous history through the upward arrow key even after using this command. Use these steps to clear Command Prompt by using the clear command:
Step 1:
Launch the Command Prompt to Perform Functions

Step 2:
Use the cls Command in CMD
When you are done with your work, run the “cls” command. It will clear the Command Prompt screen, and you can start your next task.

Pro Tip 1:
The clear command also works if you use Windows PowerShell instead of Command Prompt. You can run the “cls” or “clear” command to clear the screen in Windows PowerShell.
Cls is a internal command found inside windows command interpreter cmd,
that is used for clearing the console window.
It does so by removing the entry of all previously entered commands, and their corresponding outputs. The command was first introduced in the MSDOS Version 2
. Initially it was for command.com
(command processor for MSDOS
), which is the predecessor of cmd.exe (
AKA Command Prompt
).
It is one of the most used commands, and is offered by all Operating Systems in one way or another (ex. Linux
has a command named clear
which serves the same purpose). In this article, we would learn about this command and how to use it.
Description of the Command :
CLS : Clears the screen.
Note –
In order to obtain the above text execute the cls /?
command on cmd.
Using Command :
The command serves only one purpose, and that is to clear the output screen. For doing so execute the command without any parameters.
It is clear that from the above image, that all the previous output has been removed.
Please can any one help me out how to clear the command prompt in windows while using mysql in command prompt
how can i clear the screen
Please can any one help me out how to clear the command prompt in windows while using mysql in command prompt
how can i clear the screen
asked Oct 16, 2014 at 15:56
Currently, it’s not possible to do so in Windows. It’s possible to do it in Linux (CTRL+L). You can only exit MySql, type in CLS, and re-enter MySql.
See: How to clear mysql screen console in windows?
answered Oct 16, 2014 at 16:06
You can use ‘cls’ command to clear the screen in the window CMD.
answered Apr 10, 2020 at 10:40
Pranay kumar
4 gold badges
22 silver badges
51 bronze badges
Windows doesn’t provide direct commands to perform this. Linux has ctrl+l
to do the same. But in windows, you have to exit MySQL with \q
or ctrl+c
and then use CLS
to clear your screen and login again to mysql.
answered Oct 16, 2014 at 16:02
1 gold badge
10 silver badges
15 bronze badges
I solve it like this. it will work. try it please.
write a bat file
@mysql -uroot -p123456 -D%1 -e%2
named it mysqldb.bat.
then use the bat:
mysqldb.bat dbname "select * from tablename;"
cls
answered Apr 23, 2021 at 3:08
How can I clear the current line in the command prompt? (I’m using Windows 7.)
Too often, I enter a command, execute it, get many lines of output, then wish to enter another command. But before entering the second command, I press the up arrow key to review the first command, then I find I have to hold backspace for 30-or so characters. ( I can’t just press down again to get an empty line. Nor can I get it by pressing up again.)
asked Mar 5, 2012 at 18:43
The Escape ( Esc
) key will clear the input line.
In addition, pressing Ctrl+C
will move the cursor to a new, blank line. This may be helpful as the input you just reviewed remains visible while you type the new command.
answered Mar 5, 2012 at 18:45
Myrddin Emrys
3 gold badges
21 silver badges
29 bronze badges
Aside from the two that Myyrddin
covered – Esc
and Ctrl+C
– there are also two more shortcuts related to clearing the current input in CMD.
Ctrl+Home
will clear all characters in the input before the cursor
(equivalent to Ctrl+U
in Bash)
Ctrl+End
will clear all characters in the input after the cursor
(equivalent to Bash’s Ctrl+K
)
Both are fairly useful and, once internalised and gotten used to, could speed up editing in CMD by quite a bit.
answered Nov 22, 2016 at 23:39
Hashim Aziz
34 gold badges
98 silver badges
165 bronze badges
Use Keyboard Shortcuts to Clear Command Prompt Screen
Keyboard shortcuts in Windows are beneficial when working on any task. They allow you to speed up your work and increase your productivity. If you want to find keyboard shortcuts to clear the Command Prompt screen, you will be disappointed as there are none. Below are a few keyboard shortcuts keys that can help remove unnecessary inputs in CMD:
- Esc:
The Escape or Esc key can be used to delete the current line of text in Command Prompt. It completely removes the line and moves the cursor back to the prompt. - Backspace:
You can use the Backspace key to delete the one character to the left side of the cursor on CMD. Pressing and holding the Backspace key will result in the continuous deletion of text one character at a time. - Ctrl + Home:
When typing a command, it can delete everything on the left side of the cursor in CMD. - Ctrl + End:
This key is used to delete all the text to the right side of the cursor when using Command Prompt. - Ctrl + Backspace:
Using this combination will allow you to delete a single word on the left side of the cursor. By holding the “Ctrl + Backspace” key, you can delete the whole text line one word at a time. - Ctrl + C:
With the help of this CMD shortcut, you can move your cursor to the new blank line, but this will terminate your running process or command.
Is there any way of clearing the command prompt screen in windows using keyboard shortcuts?
asked Apr 20, 2013 at 5:44
NO, But you can use CLS
command to clear the whole screen, Esc
(Escape) key will clear the input line.
In addition, pressing Ctrl
+ C
will move the cursor to a new blank line.
2 gold badges
31 silver badges
37 bronze badges
answered Apr 20, 2013 at 5:52
1 gold badge
11 silver badges
5 bronze badges
If you really really want to do that with a keyboard shortcut
(myself included) you might turn to using autohotkey
and write a little script like this:
; -------------------------------------------------------------------------
; Cntr-L should clear screen
; -------------------------------------------------------------------------
#IfWinActive ahk_class ConsoleWindowClass
^L::
Send cls{Enter}
return
#IfWinActive
- first look if one is within console application
- if CTRL
+ L
is pressed - write
cls
to the console and then hit ENTER
answered Aug 13, 2015 at 12:17
So long i also research but found best way to achieve this by defining Doskey Macro
i defined macro like this
doskey 1=cd\ $T cls
this will do two things by simple writing 1 and hit enter
- Bring you on clean Command route
- Clear entire screen
Note: you can add multiple desire command under one macro by separating them with $T
answered Oct 11, 2017 at 9:15
5 bronze badges
I have searched a lot to find a way (keyboard shortcut) to clear the screen of the console window of cmd
on Windows 10. I tried Ctrl+L
and Ctrl+K
and ESC
, but nothing worked for me and I didn’t find any satisfied solution.
Thanks a lot for the AutoHotkey
script.
I modified the script to input Python
script to clear the screen when using scrapy shell
like that
Send from os import system{Enter}
Send cls = lambda: system)'cls'({Enter}
Send cls)({Enter}
It worked well but I noticed the value 0
at the top of the window.
The console window after execution of AutoHotkey
script with █
as blinking caret symbol.
0
>>> █
How can I remove that zero?
17 gold badges
80 silver badges
143 bronze badges
asked Oct 16, 2021 at 4:45
7 gold badges
36 silver badges
94 bronze badges
The simplest way of clear window in command prompt is typing: cls + enter
Ecs
is a key to exit input of command prompt, it does noting on clear window
Ctrl + L and Ctrl + K
are not correct short key in Linux command prompt. If you really want to make it a short cut key of cls, you can use AutoHotKey to write a short script
; -------------------------------------------------------------------------
; Cntr-L should clear screen
; -------------------------------------------------------------------------
#IfWinActive ahk_class ConsoleWindowClass
^L::
Send cls{Enter}
return
#IfWinActive
Official website of autohotkey: https://www.autohotkey.com/
Windows 10 + python 3.9 clear command prompt script:
import os
os.system(‘cls’)
answered Oct 16, 2021 at 4:55
Before we begin
Here are some important things for you to understand before we dig into removing files and folders using Command Prompt and Windows PowerShell. These tips will help you understand the terms and some basic rules of the commands that will be used further in the article.
The most important thing to remember here is the syntax of the path and file/folder name. When typing file name, notice whether there is a gap (space) in it. For example, if the folder name has no space in it, it can be written as-is. However, if there is a gap in it, it will need to be written within parenthesis (“”). Here is an example:

Another thing to remember is that you might see different outcomes while removing folders that are already empty, and folders that have some content in them. Having said that, you will need to use the dedicated options in the command to remove content from within a folder along with the main folder itself. This is called a recursive action.
One last thing that might come in handy is being able to view what content is available in the current working directory. This is especially helpful so that you type in the correct spelling of the target file or folder. To view the contents of the current working directory in Command Prompt and PowerShell, type in Dir
.

Now that we have the basic knowledge, let us show you how you can delete files and folders using the command line on a Windows
PC.
By default, there are 2 command-line interfaces built into Windows 10
– Command Prompt and Windows PowerShell. Both of these are going to be used to delete content from a computer.
Here are the steps I need, I am using a batch script
- Open a cmd with path set to the desktop
- Then set it’s echo off
- Then clear the screen
- Then wait for me to type commands
Code I tried so far
@echo off
cd "C:\Documents and Settings\Administrator\Desktop"
cls
cmd
@echo off
cls
The output I get is
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\Documents and Settings\Administrator\Desktop>
The output I want is simple
Imagine a blinking underscore
_
asked Mar 23, 2013 at 10:25
Try this line:
start /D "C:\Documents and Settings\Administrator\Desktop" cmd /k "prompt $"
/D <path>
will set your working directory
Prompt $
will set your prompt to “nothing”, only the blinking cursor will display
answered Mar 23, 2013 at 11:16
10 gold badges
58 silver badges
91 bronze badges
The output I want is simple
_
You can achive this with the prompt
command, e.g. prompt $S
or prompt $g
Here’s an example batch file that would open up a new cmd window with an empty prompt:
@echo Off
start cmd /k "prompt $g"
answered Mar 23, 2013 at 10:30
9 gold badges
80 silver badges
125 bronze badges
create a VBS file using notepad
add this lines
Set cmd = CreateObject("WScript.Shell")
cmd.run"cmd"
WScript.Sleep 200
cmd.Sendkeys"echo off{Enter}"
WScript.Sleep 200
cmd.Sendkeys"cls{Enter}"
WScript.Sleep 200
28 gold badges
99 silver badges
211 bronze badges
answered Sep 4, 2013 at 6:59
cmd /c echo off | clip
goto off
(Save as .bat)
No more problems !!!
30 gold badges
109 silver badges
146 bronze badges
answered Sep 30, 2014 at 18:51
I just used
cls
echo off
cls
cmd|echo off
cls
in a batch file. Works for me
answered Jul 14, 2015 at 12:10
Способ 1: Очистка текущей строки
Избавиться от введенного ранее текста в «Командной строке» Windows 10 можно с помощью всего одной кнопки на клавиатуре – «ESC»
. После нажатия клавиши все символы без исключения будут удалены по аналогии с многократным нажатием клавиши «Backspace»
.
Основной альтернативой кнопке «ESC»
в Windows 10 выступает сочетание клавиш «CTRL+C»
, которое присутствует в большинстве операционных систем с консолью. В этом случае все символы со строки будут моментально удалены, произведен автоматический переход на новую строку и остановлены любые ранее запущенные команды.
Key “Backspace”
can also be used to partially but quickly clear the console in combination with other buttons. So, for example, the combination “CTRL + Backspace”
allows you to delete consecutive characters without spaces, including numbers and any other characters.
Method 2: Hiding all entries
The only currently available way to clear all entries within the Windows 10 Command Prompt window is to use the command below. In this case, after entering characters whose case does not matter, and then pressing “ENTER”
, all data on the screen will be deleted and reset to a single start line.
In addition to this command, as you might guess, you can always manually close the console using the cross in the corner of the screen or the key combination “ALT + F4”
, which will automatically clean up. However, it is important to consider here that the commands being executed, as a rule, do not stop before completion or pressing “CTRL+C”
.
Method 3: Custom Launch File
Although this is not particularly critical at first glance, it is quite possible to start working with an initially completely clean console without additional information about the system version and developer. To do this, open the standard Notepad
or any other text editor and enter the following content in one line.
cmd /k cls
This document must be saved in any convenient place with the extension “.bat”
and in the future use it as a shortcut to launch the “Command Prompt”. Only in this case it will open with one single line, be it “С:\Windows\system32”
or a custom location, which is quite possible to control through additional commands in the file.
More articles on this topic:
Did the article help you?
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
/* Standard error macro for reporting API errors */
#define PERR(bSuccess, api){ if(!(bSuccess)) printf("%s:Error %d from %s \
on line %d\n", __FILE__, GetLastError(), api, __LINE__); }
HWND GetConsoleHwnd(void) {
#define MY_BUFSIZE 1024 // Buffer size for console window titles.
HWND hwndFound; // This is what is returned to the caller.
char pszNewWindowTitle[MY_BUFSIZE]; // Contains fabricated WindowTitle.
char pszOldWindowTitle[MY_BUFSIZE]; // Contains original WindowTitle.
// Fetch current window title.
GetConsoleTitle(pszOldWindowTitle, MY_BUFSIZE);
// Format a "unique" NewWindowTitle.
wsprintf(pszNewWindowTitle,"%d/%d", GetTickCount(), GetCurrentProcessId());
// Change current window title.
SetConsoleTitle(pszNewWindowTitle);
// Ensure window title has been updated.
Sleep;
// Look for NewWindowTitle.
hwndFound=FindWindow(NULL, pszNewWindowTitle);
// Restore original window title.
SetConsoleTitle(pszOldWindowTitle);
return(hwndFound);
}
void cls( HANDLE hConsole ) {
COORD coordScreen = { 0, 0 }; /* here's where we'll home the cursor */
BOOL bSuccess;
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi; /* to get buffer info */
DWORD dwConSize; /* number of character cells in the current buffer */
/* get the number of character cells in the current buffer */
bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi );
PERR( bSuccess, "GetConsoleScreenBufferInfo" );
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
/* fill the entire screen with blanks */
bSuccess = FillConsoleOutputCharacter( hConsole, (TCHAR) ' ',
dwConSize, coordScreen, &cCharsWritten );
PERR( bSuccess, "FillConsoleOutputCharacter" );
/* get the current text attribute */
bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi );
PERR( bSuccess, "ConsoleScreenBufferInfo" );
/* now set the buffer's attributes accordingly */
bSuccess = FillConsoleOutputAttribute( hConsole, csbi.wAttributes,
dwConSize, coordScreen, &cCharsWritten );
PERR( bSuccess, "FillConsoleOutputAttribute" );
/* put the cursor at (0, 0) */
bSuccess = SetConsoleCursorPosition( hConsole, coordScreen );
PERR( bSuccess, "SetConsoleCursorPosition" );
return;
}
int main (void) {
// why does this fail?
HWND cons = GetConsoleHwnd();
cls(cons);
return 0;
}
My question is this: How do I set up a console handle to pass to the `cls` function?
Edit
: Please note that I do not wish to simply call/invoke the cls
or clear
command(s) via a call to system
as advised in the majority of answers to this question
.
While clearing the screen is a terminal
function (via ANSI terminal control codes), the way that you get those codes sent can be different depending on the shell. The general idea is that:
-
ESC[2J
clears the screen, but leaves the scrollback -
ESC[3J
clears the screen, including all scrollback
According to man clear
on Linux, the 2J
code was originally (in 1999) an extension to XTerm, which was picked up by the Linux kernel in 2011 for the console driver. Sometime later, Windows Console Host picked it up, and it’s been in Windows Terminal probably since its inception.
Windows Terminal (for all shells)
Windows Terminal includes the clearBuffer
action
which can be bound to any hotkey. However, it impacts all shells regardless of what application may be running inside it
. For that reason, I recommend against using it unless you are sure you won’t accidentally press the hotkey when in something like vi
(or worse).
That said, it’s definitely the easiest way to get this functionality in CMD.
If you want to use it, the clearBuffer
action allows you to specify a clear
target of:
-
screen
-
scrollback
-
all
Using the screen
option will clear the current contents of the screen but leave the scrollback in place.
You’ll need to edit your Windows Terminal settings.json
directly since the UI doesn’t have a way to set the clear
target:
{
"command":
{
"action": "clearBuffer",
"clear": "screen"
},
"keys": ""
}
PowerShell
If you have muscle memory in typing clear
in PowerShell, you could simply change its definition:
Remove-Item Alias:clear
function clear {
Write-Output "$([char]27)[2J"
}
Place this in your PowerShell profile if you want it to be permanent.
CMD
It’s possible, but tricky to do this in CMD as well.
The biggest problem in CMD is actually getting the ESC character (ASCII 27) printed. I had the actual “character” pasted in here which would transfer via copy/paste to CMD, but it was erased the first time I made another edit to this post. The character is still there in the (source) edit history for this answer, but let’s find a better way to do this.
From PowerShell
, use this to create a CMD
batch file:
@"
@echo off
echo $([char]27)[2J
"@ | Out-File -FilePath .\clear.cmd -Encoding ASCII
Executing the resulting clear.cmd
batch file in CMD should clear the screen (but not the scrollback).
pwsh -c "Write-Output "`e[2J""
And just to provide some additional detail on one of your comments:
So yes, we’ve come up with a workaround, but it honestly wouldn’t surprise me if we hadn’t. Remember, Windows Console Host (in which CMD used to run by default) dates back to Windows 95 (so 27 years now), well before XTerm even added those codes.
And while Windows Terminal is much more modern, I don’t think CMD (which needs to generate the codes) has seen any substantial update since before PowerShell was released in 2006.
Really, I count ourselves lucky we’ve got a workaround ;-).
Windows Subsystem for Linux
- Ctrl
+ L
also works from many Linux shells to send aESC[2J
(leave scrollback). -
clear
will act like on PowerShell, clearing the screen and
scrollback (ESC[3J
). -
clear -x
will leave the scrollback (ESC[2J
)
Delete files and folders with complex and long paths using the command line
Sometimes you may encounter an error while trying to delete an item that may suggest that the path is too long, or the item cannot be deleted as it is buried too deep. Here is a neat trick you can apply using both Command Prompt and PowerShell to initially empty the folder, and then remove it using any of the methods above.
Use the command below to copy the contents of one folder (which is empty) into a folder that cannot be deleted. This will also make the destination folder empty, hence making it removable.
robocopy "D:\EmptyFolder" D:\FolderToRemove /MIR
In this scenario, the EmptyFolder
is the source folder that we have deliberately kept empty to copy it to the target folder “FolderToRemove.”

You will now see that the folder that was previously unremovable is now empty. You can proceed to delete it using any of the methods discussed in this article.
- . Дата обращения: 22 сентября 2021.
Архивировано
25 сентября 2019 года.
- . Дата обращения: 22 сентября 2021.
Архивировано
14 апреля 2019 года.
- Microsoft TechNet Cls article
. Дата обращения: 22 сентября 2021.
Архивировано
cls
3 февраля 2018 года.
- Running MS-DOS Version 6.22 (20th Anniversary Edition), 6th Revised edition. —
, 2003. — ISBN 0-7356-1812-7
.
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
/* Standard error macro for reporting API errors */
#define PERR(bSuccess, api){ if(!(bSuccess)) printf("%s:Error %d from %s \
on line %d\n", __FILE__, GetLastError(), api, __LINE__); }
HWND GetConsoleHwnd(void) {
#define MY_BUFSIZE 1024 // Buffer size for console window titles.
HWND hwndFound; // This is what is returned to the caller.
char pszNewWindowTitle[MY_BUFSIZE]; // Contains fabricated WindowTitle.
char pszOldWindowTitle[MY_BUFSIZE]; // Contains original WindowTitle.
// Fetch current window title.
GetConsoleTitle(pszOldWindowTitle, MY_BUFSIZE);
// Format a "unique" NewWindowTitle.
wsprintf(pszNewWindowTitle,"%d/%d", GetTickCount(), GetCurrentProcessId());
// Change current window title.
SetConsoleTitle(pszNewWindowTitle);
// Ensure window title has been updated.
Sleepclear
;
// Look for NewWindowTitle.
hwndFound=FindWindow(NULL, pszNewWindowTitle);
// Restore original window title.
SetConsoleTitle(pszOldWindowTitle);
return(hwndFound);
}
void cls( HANDLE hConsole ) {
COORD coordScreen = { 0, 0 }; /* here's where we'll home the cursor */
BOOL bSuccess;
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi; /* to get buffer info */
DWORD dwConSize; /* number of character cells in the current buffer */
/* get the number of character cells in the current buffer */
bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi );
PERR( bSuccess, "GetConsoleScreenBufferInfo" );
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
/* fill the entire screen with blanks */
bSuccess = FillConsoleOutputCharacter( hConsole, (TCHAR) ' ',
dwConSize, coordScreen, &cCharsWritten );
PERR( bSuccess, "FillConsoleOutputCharacter" );
/* get the current text attribute */
bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi );
PERR( bSuccess, "ConsoleScreenBufferInfo" );
/* now set the buffer's attributes accordingly */
bSuccess = FillConsoleOutputAttribute( hConsole, csbi.wAttributes,
dwConSize, coordScreen, &cCharsWritten );
PERR( bSuccess, "FillConsoleOutputAttribute" );
/* put the cursor at (0, 0) */
bSuccess = SetConsoleCursorPosition( hConsole, coordScreen );
PERR( bSuccess, "SetConsoleCursorPosition" );
return;
}
int main (void) {
// why does this fail?
HWND cons = GetConsoleHwnd();
cls(cons);
return 0;
}
EFI Shells and Scripting
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
/* Standard error macro for reporting API errors */
#define PERR(bSuccess, api){ if(!(bSuccess)) printf("%s:Error %d from %s \
on line %d\n", __FILE__, GetLastError(), api, __LINE__); }
HWND GetConsoleHwnd(void) {
#define MY_BUFSIZE 1024 // Buffer size for console window titles.
HWND hwndFound; // This is what is returned to the caller.
char pszNewWindowTitle[MY_BUFSIZE]; // Contains fabricated WindowTitle.
char pszOldWindowTitle[MY_BUFSIZE]; // Contains original WindowTitle.
// Fetch current window title.
GetConsoleTitle(pszOldWindowTitle, MY_BUFSIZE);
// Format a "unique" NewWindowTitle.
wsprintf(pszNewWindowTitle,"%d/%d", GetTickCount(), GetCurrentProcessId());
// Change current window title.
SetConsoleTitle(pszNewWindowTitle);
// Ensure window title has been updated.
Sleepclear
;
// Look for NewWindowTitle.
hwndFound=FindWindow(NULL, pszNewWindowTitle);
// Restore original window title.
SetConsoleTitle(pszOldWindowTitle);
return(hwndFound);
}
void cls( HANDLE hConsole ) {
COORD coordScreen = { 0, 0 }; /* here's where we'll home the cursor */
BOOL bSuccess;
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi; /* to get buffer info */
DWORD dwConSize; /* number of character cells in the current buffer */
/* get the number of character cells in the current buffer */
bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi );
PERR( bSuccess, "GetConsoleScreenBufferInfo" );
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
/* fill the entire screen with blanks */
bSuccess = FillConsoleOutputCharacter( hConsole, (TCHAR) ' ',
dwConSize, coordScreen, &cCharsWritten );
PERR( bSuccess, "FillConsoleOutputCharacter" );
/* get the current text attribute */
bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi );
PERR( bSuccess, "ConsoleScreenBufferInfo" );
/* now set the buffer's attributes accordingly */
bSuccess = FillConsoleOutputAttribute( hConsole, csbi.wAttributes,
dwConSize, coordScreen, &cCharsWritten );
PERR( bSuccess, "FillConsoleOutputAttribute" );
/* put the cursor at (0, 0) */
bSuccess = SetConsoleCursorPosition( hConsole, coordScreen );
PERR( bSuccess, "SetConsoleCursorPosition" );
return;
}
int main (void) {
// why does this fail?
HWND cons = GetConsoleHwnd();
cls(cons);
return 0;
}
EFI Shells and Scripting
.
Intel
.
Дата обращения: 25 сентября 2013.
Архивировано
30 января 2009 года.
Команда CLS появилась как команда очистки экрана во многих других диалектах BASIC и интерпретаторах командной строки из-за того, что она известна благодаря включению в MS-DOS.
включает реализацию CLS. Как и остальная часть операционной системы, она находится под лицензией GPL
v3. DR-DOS
6.0 также включает реализацию команды CLS.
How to remove files and folders using Command Prompt
Del/Erase command in cmd
Del
and Erase
commands in Command Prompt are aliases of one another. Meaning, both perform the same function regardless of which one you use. These can be used to remove individual items (files) in the current working directory. Remember that it cannot be used to delete the directories (folders) themselves.
Tip:
Use the Tab
button to automatically complete paths and file/folder names.
Del File/FolderName Erase File/FolderName
Replace File/FolderName
with the name of the item you wish to remove. Here is an example of us removing files from the working directory:

If you try to remove items from within a folder, whether empty or not, you will be prompted for a confirmation action, such as the one below:

In such a scenario, you will need to enter Y
for yes and N
for no to confirm. If you select yes, the items directly within the folder will be removed, but the directory (folder) will remain. However, the subdirectories within the folder will not be changed at all.
Del /s "Final folder"
Here is its output:

As you can see in the image above, we had to enter “y” twice – once for each folder. with each confirmation, 2 text files were removed, as we had stated earlier in this example. However, if we use File Explorer, we can still see that both the directories – “Final folder” and “Subfolder” – are still there, but the content inside them is removed.
You can also make another tweak to the command so that it is executed silently and you will not be prompted for confirmation. Here is how:
Del /s /q "Final folder"
The /q
illustrates that the action be taken quietly
.

Rmdir /rd command in cmd
Similar to Del and Erase, rmdir
and rd
are also aliases for one another, which means to remove directory
. These commands are used to remove the entire directory and subdirectories (recursively) including their contents. Use the command below to do so:
rmdir "New Folder"


In this case, we will need to apply the option for recursive deletion of items as we have done earlier with the Del
command.
rmdir /s "Final folder"

Of course, this can also be performed with the /q
option so that you are not prompted with a confirmation.
rmdir /s /q "Final folder"
Delete multiple files and folders
Up until now, we have completed the task of deleting single items per command. Now let’s see how you can remove multiple selective files or folders. Use the command below to do so:
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
/* Standard error macro for reporting API errors */
#define PERR(bSuccess, api){ if(!(bSuccess)) printf("%s:Error %d from %s \
on line %d\n", __FILE__, GetLastError(), api, __LINE__); }
HWND GetConsoleHwnd(void) {
#define MY_BUFSIZE 1024 // Buffer size for console window titles.
HWND hwndFound; // This is what is returned to the caller.
char pszNewWindowTitle[MY_BUFSIZE]; // Contains fabricated WindowTitle.
char pszOldWindowTitle[MY_BUFSIZE]; // Contains original WindowTitle.
// Fetch current window title.
GetConsoleTitle(pszOldWindowTitle, MY_BUFSIZE);
// Format a "unique" NewWindowTitle.
wsprintf(pszNewWindowTitle,"%d/%d", GetTickCount(), GetCurrentProcessId());
// Change current window title.
SetConsoleTitle(pszNewWindowTitle);
// Ensure window title has been updated.
Sleep
;
// Look for NewWindowTitle.
hwndFound=FindWindow(NULL, pszNewWindowTitle);
// Restore original window title.
SetConsoleTitle(pszOldWindowTitle);
return(hwndFound);
}
void cls( HANDLE hConsole ) {
COORD coordScreen = { 0, 0 }; /* here's where we'll home the cursor */
BOOL bSuccess;
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi; /* to get buffer info */
DWORD dwConSize; /* number of character cells in the current buffer */
/* get the number of character cells in the current buffer */
bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi );
PERR( bSuccess, "GetConsoleScreenBufferInfo" );
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
/* fill the entire screen with blanks */
bSuccess = FillConsoleOutputCharacter( hConsole, (TCHAR) ' ',
dwConSize, coordScreen, &cCharsWritten );
PERR( bSuccess, "FillConsoleOutputCharacter" );
/* get the current text attribute */
bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi );
PERR( bSuccess, "ConsoleScreenBufferInfo" );
/* now set the buffer's attributes accordingly */
bSuccess = FillConsoleOutputAttribute( hConsole, csbi.wAttributes,
dwConSize, coordScreen, &cCharsWritten );
PERR( bSuccess, "FillConsoleOutputAttribute" );
/* put the cursor at (0, 0) */
bSuccess = SetConsoleCursorPosition( hConsole, coordScreen );
PERR( bSuccess, "SetConsoleCursorPosition" );
return;
}
int main (void) {
// why does this fail?
HWND cons = GetConsoleHwnd();
cls(cons);
return 0;
}
Del “File1.txt” “File3.txt” “File5.txt”
rd “Folder1” “Folder3” “Folder5” cls
Here is a before and after comparison of the directory where both of the above commands were executed:
cmd /k cls
Here is an example of us removing all .txt files from our current working directory:
Del “*.txt”
Delete files and folders in any directory
We are working on removing content within the current working directory. However, you can also use the commands we have discussed till now to remove files and folders from any directory within your computer.
Simply put the complete path of the item you want to delete in enclosed parenthesis, and it shall be removed, as in the example below:

Check the existence of file or folder then remove using IF command
We have already discussed that you can view the contents of the working directory by typing in Dir
in Command Prompt. However, you can apply an “if” condition in Command Prompt to remove an item if it exists. If it will not, the action would not be taken. Here is how:
if exist File/FolderName (rmdir /s/q File/FolderName )
Replace File/FolderName
in both places with the name of the item (and extension if applicable) to be deleted. Here is an example:
if exist Desktop (rmdir /s/q Desktop)

Clear Screen on Windows Subsystem for Linux

How to remove files and folders using Windows PowerShell
The commands in Windows PowerShell to delete and remove content from your PC are very much similar to those of Command Prompt, with a few additional aliases. The overall functionality and logic are the same.
The main thing to note here is that unlike Command Prompt, all commands can be used for both purposes – removing individual files as well as complete directories. We ask you to be careful while using PowerShell to delete files and folders, as the directory itself is also removed.
The good thing is that you do not need to specify recursive action. If a directory has sub-directories, PowerShell will confirm whether you wish to continue with your deletion, which will also include all child objects (subdirectories).
Here is a list of all the commands/aliases that can be used in PowerShell to remove an item:
- Del
- Rm-dir
- remove-item
- Erase
- Ri
We tested all of these commands in our working directory and each of them was successful in deleting the folders as well as individual items, as can be seen below:

As can be seen above, the syntax of all the aliases is the same. You can use any of the commands below to delete an item using PowerShell:
Del File/FolderName Rm-dir File/FolderName remove-item File/FolderName Erase File/FolderName Rd File/FolderName Ri File/FolderName Rm File/FolderName
Delete multiple files and folders
You can also delete multiple selective files and folders just as we did while using Command Prompt. The only difference is that you will need to provide the complete path of each item, even if you are in the same working directory. Use the command below to do so:
Del " DriveLetter:\Path\ItemName ", " DriveLetter:\Path\ItemName "
Remember to append the file type if the item is not a directory (.txt, .png, etc.), as we have done in the example below:

You can also use an asterisk (*)
concatenated with a file type or file name to perform bulk removal of files with the Del
command, as done in Command Prompt. Here is an example:

The command shown above will remove all.txt files in the directory “New folder.”
Delete files and folders in any directory
You can also remove an item in a different directory, just like we did in Command Prompt. Simply enter the complete path to the item in PowerShell, as we have done below:

Clear Command Prompt Screen without Erasing Everything
Step 1:
Scroll Down through Command Prompt
After you have opened Command Prompt and started work, you can use the “Ctrl + Down Key ↓” to move below the screen. Continue to do that until your current command line is only visible on screen.

Step 2:
Access the Previous Command by Scrolling Upward
You can scroll upward using the mouse to access the previous command. Use the “ Ctrl + Up Key ↑
” on a laptop to scroll upwards.

Close and Reopen Command Prompt to Clear the Screen
Step 1:
Close the Command Prompt to Clear the Screen
Once you have done your task in the Command Prompt and need to clear the screen, press the “X” icon from the top right corner to close CMD. When you reopen the Command Prompt, the screen will be cleared.

Step 2:
Open the Command Prompt on your Device
