1

Is there a keyboard shortcut for selecting all of what's currently being typed (sorry, I've forgotten what the proper term is) in CMD? This article from HTG says Ctrl+A should do the job, but for me that just outputs:

^A

While I'm at it, I'd also love to know how the same input can also be written to a file. Doing, for example...

dir B:\Users\ThisUser >> File.txt

...prints the output of the dir command to the file rather than the command itself.

2
  • echo dir B:\Users\ThisUser >> File.txt – DavidPostill Nov 1 '16 at 11:36
  • @DavidPostill - This works perfectly for the latter half of the question. Thanks! – Hashim Aziz Nov 1 '16 at 21:53
1

You can't use the CTRL key in command prompt, it will just result in a ^. As a result, there is no "select all" keyboard shortcut in command prompt.

Instead, right-click on the title bar (not the console window), and there is a different menu; go to "Edit" and "Select All".

enter image description here

Also, you can kind of do a psuedo-keyboard-shortcut, by first right-clicking on the title bar, and then pressing E and then S to shortcut through the menu. You will notice that the E of "Edit" is underlined, and the S of "Select All" is underlined. This is what the underline means, press that key on your keyboard and it selects the menu item.

The downside to this is that it does not select just the current line, but rather the whole console window.

You can then copy and paste this text into a text editor once you copied the whole window, and then copy and paste what you want back into command prompt.

Unfortunately, this is a limitation of command prompt, because a simple "select all of current line" keyboard shortcut would certainly be very useful!!


UP and DOWN Keyboard Shortcut

However, something worth noting, is that what you can do if you want to refer back to a previous line you had typed in the same console window, you can use the "UP" and "DOWN" arrow keys on your keyboard. This is a shortcut for both windows command prompt as well as linux console, it is a very useful trick I use often when coding in linux ssh.

For example, say this was your console:

C:\> cd users<br>
C:\Users> cd myusername<br>
C:\Users\MyUsername> cd documents<br>
C:\Users\MyUsername\Documents> _

If I now press UP once it will show this in the current console line:

C:\Users\MyUsername\Documents> cd documents

If I now press UP twice it will show this in the current console line:

C:\Users\MyUsername\Documents> cd myusername

Windows 10: Enable CTRL shortcuts in command prompt

Windows 7 doesn't have this option, but Windows 10 does! Now in Windows 10 you can enable CTRL + C and CTRL + V to copy and paste. I am expecting you should also be able to do CTRL + A for select all.

You can do that like this:

  1. Right-click on the title bar
  2. Choose "Properties"

enter image description here

  1. In the properties menu, choose "Enable new Ctrl key shortcuts"

enter image description here


Enable Ctrl key Copy and Paste shortcuts on Windows 7 and 8

Even though there is no native option on Windows 7 and 8, you can use an AutoHotKey script to emulate copy and paste! You can't select all however, unfortunately, although p[erhaps you could find a way to code the autohotkey script to do that, not sure if you can.

Here is how you Enable CTRL + C and CTRL + V in command prompt on windows 7 and 8:

  1. Create a text file and name it copy-paste-command-promt.ahk or any name you want ending in .ahk (ahk is the extension for autohotkey scripts).
  2. Paste the below text into the text file (please exclude the "CODE" that starts below because that was required due to a limitation with superuser):

"CODE" #IfWinActive ahk_class ConsoleWindowClass
{
^c::
If toggle != 1
{
CoordMode, Mouse, Window
MouseGetPos, x, y
MouseClick, Right, 40, 80 ; this opens the Console Window's context menu... and then selects 'Mark'.
Sleep, 0050
Send, {Down}{Enter}
MouseMove, x, y
toggle = 1
}
else
{
Send, {Enter}
toggle = 0
}
Return

^v::
SendInput {Raw}%clipboard%
Return
}
#IfWinActive

  1. Now to make sure it always starts with WIndows, drag the .ahk file you just created to:

C:\Users\YOURUSERNAME\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

(make sure you change YOURUSERNAME to your actual Windows username folder)

Now you can copy and paste into command console in Windows 7 and 8!

4
  • This isn't an answer to the question as Select All selects everything in the console as opposed to just the command being inputted. The easiest way I know of to do what I want here is by using Mark to select the text manually, but that has its limitations when dealing with multiple-line commands, hence why I'd prefer a shortcut or even an option to select just the current command. – Hashim Aziz Nov 1 '16 at 21:58
  • Unfortunately, as I said, there is no "select all" keyboard shortcut in windows command prompt. Additionally, there is no "select all in current line" keyboard shortcut in windows command prompt. The answer I gave is the best option within the limitations of command prompt in windows. You can then paste this text into a text editor once you copied the whole window, and then copy and paste what you want back into command prompt. – user7783780 Nov 2 '16 at 21:24
  • Updated answer with another keyboard shortcut trick – user7783780 Nov 2 '16 at 21:32
  • UPDATE: Added more tips, on enabling it in windows 10 and some tips for cmd copy and paste in window 7 and 8 – user7783780 Nov 2 '16 at 21:55
0

There is no preset way do get the console history, but you can use the doskey utility. It will also handle aliases. If may be invoked on every start of a cmd shell via Registry Autorun, you can hit [F7] to get a small scrollable window with the history to choose an entry to copy to the console. To get the whole history (of this cmd.exe invocation) you might redirect the output of doskey /historyto a file or the clipboard doskey /history|clip.

Edit Btw, in recent Win10 releases you may check Enable Ctrlkey shortcutsin the options tab of the cmd.exe properties dialog to get Ctrl-A,X,C,V working and I love it. /Edit

This is part of my init.cmd which I run on every new pc / os installation. It stores an Aliases.txt file in the %UserProfile%, installs the Autorun key and several other things which you may take as a template (it auto elevates for some changes):

:: Init.cmd::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off & setlocal EnableExtensions DisableDelayedExpansion
net file 1>nul 2>&1 || (powershell -ex unrestricted -Command ^
  "Start-Process -Verb RunAs -FilePath '%comspec%' -ArgumentList '/c %~f0 %*'"
  goto :eof)
:: TODO: Put code here that needs elevation

Set Aliases="%UserProfile%\Aliases.txt"
If Not Exist %Aliases% (
  Echo ~+=PushD "%UserProfile%"
  Echo ~=CD /D "%UserProfile%"
  Echo \+=PushD \
  Echo \=CD \  
  Echo -+=PushD ..
  Echo -=CD ..
  Echo +=PopD
  Echo CDD=CD /D $*
  Echo X=Exit /b 0
  Echo clear=cls
  Echo Alias=Doskey $*
  Echo Aliases=Doskey /MACROS:ALL
  Echo mc=far
)>%Aliases% 
Doskey /Macrofile=%Aliases%

Set "Key=HKCU\Software\Microsoft\Command Processor"
Reg ADD "%Key%" /f /v AutoRun /t REG_SZ /d "Doskey /MacroFile=\"%Aliases:"=%\""
Reg Add "%Key%" /f /v CompletionChar      /t REG_DWORD /d 0x9
Reg Add "%Key%" /f /v PathCompletionChar  /t REG_DWORD /d 0x9
Reg Add "%Key%" /f /v DelayedExpansion    /t REG_DWORD /d 0x1
Reg Add "%Key%" /f /v EnableExtensions    /t REG_DWORD /d 0x1
Set "Key=HKCU\Control Panel\International"
Reg Add "%Key%" /f /v sShortDate          /t REG_SZ /d yyyy-MM-dd
Set "Key=HKCU\Control Panel\Desktop"
Reg Add "%Key%" /f /v PaintDesktopVersion /t REG_DWORD /d 0x1
Reg Add "%Key%" /f /v MenuShowDelay       /t REG_SZ /d 50
Set "Key=HKEY_USERS\.Default\Control Panel\International"
Reg Add "%Key%" /f /v sShortDate          /t REG_SZ /d yyyy-MM-dd
:: Keep Net Use Drives in UAC Mode
Set "Key=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System"
Reg Add "%Key%" /f /v EnableLinkedConnections /t REG_DWORD /d 0x1
:: Sort Dirs first orde by name
if not defined DirCMD (Setx /m DirCMD /OGN 1>NUL)
:: Have the prompt on two lines with ansi colour (req. an actual Windows 10)
:: 19:57:10 \TMDat1\Daten +Q:\Test\2016-11\02__________________________...
:: > 
(Setx Prompt "$E[92m$t$h$h$h $m$+$p________________________________________$_$g $E[0m" 1>NUL)
:: RefrweshEnv is a too from Chocolatey which does what the name says.
RefreshEnv 2>NUL

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.