How-To Geek
5 Windows Command Prompt Tricks You Probably Don’t Know
We tend to use the command prompt quite a lot here at How-To Geek, so we decided to show you 5 tricks we use in the command prompt that you might not know–read on to find out what they are.
Send a Command’s Output to the Clipboard
Note: This will work for any command.
How many times have you used the ipconfig command only to copy and paste the output? You will never have to do that again as you can simply send the output directly to the clipboard.
ipconfig | clip


Open Command Prompt From a Folder
Have you ever opened the command prompt and entered endless cd commands trying to get to a folder ? If the answer is yes then you will pleased to know that you can actually save a lot of time by opening a command prompt within a folder from Explorer. All you have to do is hold shift while right-clicking on a folder and the option will appear in the context menu.


Command History
You most likely have been pressing the up key to get to your previous commands, but this can be a pain when you are trying to track down a particular command. One other way you can view your past command is to use the doskey command.
doskey /history


Drag and Drop Files to Change the Current Path
Another neat trick if you are not a fan of opening a command prompt from the context menu is the ability to drag and drop folders onto the prompt and have it automatically enter the path of the folder. You’ll need to type the CD command and then drag the folder over to actually change the path, but you can use the same technique for a lot of different commands.


Run Multiple Commands In One Go
Our final trick of the day is one that many command line geeks may already know, the ability to run multiple command at once by linking them with double ampersands. You can do this with any commands and you can link up as many as you want:
ipconfig && netstat


Got Feedback? Join the discussion at discuss.howtogeek.com
Comments (55)
Taylor Gibb is a Microsoft MVP and all round geek, he loves everything from Windows 8 to Windows Server 2012 and even C# and PowerShell. You can also follow him on Google+
- Published 07/30/12





Love the clip one.
My favourite is to write directly to a file:
copy con filename.txt
enter text
enter text
Ctrl and Z to finish
Dont forget the option of hitting F7 and F9 for the history list of commands…
People still use cmd.exe?
I thought we were supposed to switch over the PowerShell over 4 years ago?
Many things work differently in powershell, but there is much more control.
By now, I hope that everyone knows about tab completion. There’s never any reason to type so much. Hit a few characters and press tab until the file/directory you want shows up. This seems to work for almost every shell on almost all platforms.
awesome and useful
beautiful….
wow. i did not know you could pipe to clipboard. f’in A that’s a good tip. thanks HTG!
The only reason to use double ampersands, instead of a single one, is if one of the commands depended on a previous one completing successfully to run. Using a single ampersand runs all commands in order, regardless of results. Using double ampersands prevents it from running later commands if the previous command failed to complete successfully.
Great tips!
Nice tips . . . Thanks
You can also redirect the output of a command to a file, to the printer, etc.:
ipconfig > filename.txt
ipconfig > prn
Loved your tipe!
@theFu I have been using power shell as my CLI for several months now. Really the main reason is that I can scroll up several pages to view a previous result from a command. At the cmd prompt it will cut off after so many lines.
@thFu aaaaand we were supposed to have all upgraded XP and all be using the Metric system here in the US.
My favorite would have to be the history. Now if people are running commands and I wanna find out what they ran, I type doskey /history.
The metric system is the tool of the devil! My car gets 40 rods to the hogshead and that’s the way I likes it.
Actually, to expand on the idea of running multiple commands at one time:
Single Ampersand is used to run the commands no matter what.
Double Ampersands runs the second command only if the first one runs without error.
Double Bars (||) runs the command afterward only if the first command has an error.
To clarify:
Command1 & Command2
Will always run Command1 and Command2
Command1 && Command2
Will only run Command2 if Command1 doesn’t have an error
Command1 || Command2
Will only run Command2 if Command1 does cause an error.
You can expand this even more:
Command1 && Command2 || Command3
This is an if-then-else construct – if Command1 is successful, then run Command2, else run Command3.
One example of the use for this if-then-else construct would be to decide what to do when checking to see if a file exists:
DIR xyzzy && ECHO Found the file || Echo Stopping because the file doesn’t exist.
And then you can really get obtuse by the hazardous use of parenthesis:
DIR xyzzy && (ECHO Found the file & DEL xyzzy) || (ECHO Stopping because the file doesn’t exist & SHUTDOWN /s)
Things could get ugly at this point so I highly recommend using a real IF statement before you end up earning a Spaghetti Code award. :)
One note: the “Drag and Drop Files to Change the Current Path” feature doesn’t seem to work if CMD is opened with “Run as administrator”
And I thought I knew the CMD!
That pipe to CLIP tip rules.
And I had no idea about the & and && trick. I thought && was only for within batch files. Jim, to get the effect of “&&” in a batch file is it necessary to enter “&&&&”?
Jim love the if-than-else construct. I’ve been using the cmd IF command for years, but that is far more effective, and going in to the toolbag. Thanks so much.
PS tried PowerShell, just can’t get onboard with it yet. I’ve tried.
Jeff: I think you’re thinking of the % when used with things like the FOR statement. That is, use %f from the command line and %%f in a batch file. The ampersands and bars can be used on the command line and batch files without any modifications.
The only people still using SAE over metric are home bodies or left over home builder throw backs. All science, medical, architecture, engineering, automotive, farming(get the idea?) use metric. They then waste their time to convert to SAE for home users (sometimes). The only industry that makes a profit is the tools manufacturers as they need to make and outfit homes with both sets of tools. Time to change over like we did with digital TV.
GREAT tips, by the way.
@Ant – Reminds me of one of my favorite T-shirts of all time…
“Real programmers use ‘Copy con > program.exe’”
Could have used this alot last week. Kept having to cd to the android platform-tools folder.
over
and over
and over
Tried googling a “open cmd.exe here” addon or registry hack, couldn’t find it.
Tried writing a batch file with 2 cd commands…
Going to make sure to remember this now.
Great! I only use the cmd once in a while.
How but some examples of using the Type command.
I often combine two of your tips with
ipconfig | clip && notepad
followed by a Ctrl-V when Notepad opens.
Tip 1:
The clip command didn’t work for WindowsXP, although you can find clip.exe in the web and install it, and get the same function.
Tip 2:
Also the shift-right-click “open with command line” tip didn’t work for me in XP either.
(you can find a tip on how to add it yourself on the web, too)
beautiful stuff THX
Thanks for typing all that out Jim, I was about to just now, but you already did a great job!
@Tape wizard
You were having trouble with displaying past commands. Do this to fix it. Find your Command or PowerShell shortcut in the Start menu, right click and select Properties. Select the Options, Fonts, Layout and Color tabs one by one and adjust the parameters to suit your style. Options adjusts the buffer size to allow more memory use, Layout allows you to set the Window size and the screen buffer size. Set your screen buffer width same as window size and your screen buffer height to 5000 or whatever suits.
Is there a book on how to use command line and where do you find it (nobe):)
@TheFu: You obviously haven’t read what Microsoft said about PowerShell and the future of CMD, though granted it was back in 2007: https://blogs.msdn.com/b/powershell/archive/2007/05/18/replacing-cmd-exe.aspx
@Dave
Instead, how about:
ipconfig > ipconfig.txt (or prepend the path where you want the file to exist, such as C:\CONFIG\ipconfig.txt)
ipconfig.txt
This would save the results to ipconfig.txt and then open it in Notepad.
Another great tip if you’ve already got Explorer open (Windows Explorer/File Explorer(Win8) is to click in the address bar and type ‘cmd’ and hit enter (without the single quotes). It will open a command prompt directly to the folder you’re in.
@Joe that is awesome I didn’t know about that, the fact that it works for PowerShell actually makes it killer awesome. Cheers.
You can also send to text files this way:
(echo First text && echo Second Text && echo. && echo Text after an empty line && echo This dir list && dir) >> mytext.txt
>> allows appending while
> overwrites
Here is my contribution:
mode con: lines=80 cols=132
The above will make your DOS window full screen. I actually put the above line in a file called wide.bat.
And to get your DOS window back to normal:
mode con: lines=25 cols=80
and I put the above line in a file called narrow.bat
If you want to grab two or more command results to the clipboard without having to issue them separately you can use a pause command:
ipconfig /all | clip && pause && set | clip
I usually prefer to just put everything to a text file and then open it up for viewing:
ipconfig /all >> result.txt && set >> result.txt && notepad.exe result.txt
I’ve been using this registry tweak since Windows 3.1:
****************************************************************************************************
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\Command Prompt Here]
@=”Command &Prompt Here”
[HKEY_CLASSES_ROOT\Directory\shell\Command Prompt Here\command]
@=”cmd.exe /k cd %1 ”
****************************************************************************************************
Just make a textfile containing the text between the lines of stars, name it what-you-like.reg
and double-click it in order to modify the registry. Thanks, Microsoft; only took you 20 years.
uhh,..no, I know them
great tips,
I saw teh title and i was like, yea sure. i will know most of their tips;
I have been using the command line since windows 3.11 but I didn’t know any of these!!
Only problem is i will have forgot them by the time i need to use them :)
Coooool …
i love the clip trick
Awesome ! Very helpful.
@Jim Thanks. I wasn’t thinking of % v %%, I just thought it was true for ampersands as well. Nice to know it’s not though. Ta.
:)
I use the shutdown command a lot. The reson is that I do a lot of TV recording and also encoding of the recorded programs. Sometimes I might not be sure if the recordings will finish first or the encodings, so I do a guesstimate then issue the shutdown command:-
(NB shutdown /? displays shutdown help)
shutdown /s /t xxx (where xxx is the time out period before shutdown)
(note /f is implied in the above usage = forces running apps to close)
eg
shutdown /s /t 3600
… will shutdown the PC in 1 hour.
should you want to abort the shutdown:-
shutdown -a
(can only use during the time-out period)
Thanks for those tips.
Really appreciate the clip one
Thanks for the great tips!
The clip one will definitely save me a lot of time.
My personal favorite is “cmd /f” to enable file and directory name completion.
One trick I have used for years that I really haven’t see others do (at least not the way I do it) is copy and paste from the cmd window. First you need to make sure your cmd window is setup in properties for “Quick Edit Mode”. This needs to be selected first. Once you do it the first time your set.
Then, use your mouse to highlight the text you want to copy. No surprise there, but then hit [Enter]. This copies the text to the clipboard. Now you can paste it where you want. No marking needed.
Hope this saves someone some time.
i like the drag and drop file path
I like the ncpa.cpl to goto the networking stuff, since they keep changing it many time.
enable quick edit is a simple yet many don’t know about.
good job….
Great article HTG….and thank you to all the “positive” reader feedback who also share their tips (such as @Jim). As someone who is just starting to learn command prompt tricks, this really helps out. Keep up the great work.
This is awesome. I like it very much. Thanks for sharing. I know only two doskey & open from context menu
Interesting, although I routinely added “doskey /history” to autoexec.bat for over a decade; in XP it was often the only line. pipe to clip is the most interesting tip. Looked up “clip” on a GNU/Linux box, it is a very different command there!
Here is a really cool cmd window trick that is kind of an hidden egg in windows works all the way back to xp
Make sure that your telnet is turned on in windows features on vista and 7
In the start menu search for “telnet”
Hit enter then a new cmd like window will open type “o” w/o quotes of course
it should say , where you should type in “towel.blinkenlights.nl” the same way no quotes
Then bam STAR WARS
Just like that your in a digital version of episode IV
Thanks for the tips. Clip.exe was a new one to me (might want to mention that us Windows XP users will need to download Clip.exe (free) and add it to a folder in the the PATH…) QUESTION: is there any way to output single lines of text to the clipboard WITHOUT having a linebreak (“CR/LF”) at the end? (clip.exe DOES put a linebreak at the end)
thank you so much some of these are so usefull :-)
Nice Tips, but how can i get a file properties dialog box from cmd ?
GODMODE with bat file easy way
Run command
type
md GodMode.{ED7BA470-8E54-465E-825C-99712043E01C}
save file as “Godmode.bat”