Tips and Tricks

Maintained on

The Command Prompt has many features and techniques that can noticeably speed up your work once you know them.

This article introduces a selection of tips you can use every day.

Using Command History

Browse History with the Up and Down Keys

Press ↑ and ↓ to recall previously entered commands one by one.

Show the History List with F7

Press F7 to display a popup list of command history. Select an entry with the arrow keys and press Enter to run it.

Show History as Text with doskey /history

doskey /history
- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>doskey /history
dir
cd Documents
echo Hello
ipconfig
C:\users\user>
チェック

Redirect the output, as in doskey /history > commands.txt, to save the history to a file.

How Much History Is Kept

By default, the most recent 50 commands are kept, and they are lost when you close the window. Save commands you want to keep as a batch file so you can reuse them.

Function Keys

KeyFunction
F1Re-enter the previous command one character at a time
F2Copy the previous command up to a specified character
F3Re-enter the previous command in full
F4Delete the typed text up to a specified character
F5Same as ↑ (previous history entry)
F7Show the command history list
F8Search history for entries matching the typed text
F9Recall a command by its number
Handy Use of the F8 Key

Type dir and press F8 to cycle through past commands that start with dir. This is a quick way to re-run frequently used commands.

Tab Completion

Press Tab to autocomplete file and folder names.

cd Doc[Tab]

Type part of a name and press Tab, and it completes to something like “Documents”.

  • When there are several candidates, keep pressing Tab to cycle to the next one
  • Press Shift+Tab to go back to the previous candidate

Keyboard Shortcuts

ShortcutFunction
Ctrl+CInterrupt the running command
Ctrl+VPaste from the clipboard
Ctrl+ASelect all text on the screen
Ctrl+MToggle Mark mode (range selection)
Ctrl+HomeScroll the view to the top
Ctrl+EndScroll the view to the bottom
Alt+EnterToggle full-screen display
EscClear the command being typed
If You Use Windows Terminal

In Windows Terminal, the default terminal on Windows 11, you can also copy with Ctrl+Shift+C and paste with Ctrl+Shift+V (or Ctrl+V). Shortcuts may differ depending on the terminal and its settings.

Changing the Screen Colors (color Command)

The color command changes the background and text colors.

color [background][foreground]

Color Codes

CodeColorCodeColor
0Black8Gray
1Blue9Light blue
2GreenALight green
3AquaBLight aqua
4RedCLight red
5PurpleDLight purple
6YellowELight yellow
7WhiteFBright white

Examples

color 0A
color 1F
color
Use Different Colors for Background and Text

If you specify the same code for both, the color command fails with ERRORLEVEL 1 and the colors do not change.

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>color 0A
おすすめ書籍※ 広告を含む場合があります
中小企業経営者のためのRPA入門 RPA導入を成功させる方法

中小企業経営者のためのRPA入門 RPA導入を成功させる方法

60分でわかる! AIエージェント 超入門

60分でわかる! AIエージェント 超入門

コマンドラインの黒い画面が怖いんです。

コマンドラインの黒い画面が怖いんです。

知識・才能ゼロでもらく~に月10万円稼ぐ! よくわかるAI副業超入門

知識・才能ゼロでもらく~に月10万円稼ぐ! よくわかるAI副業超入門

Changing the Title Bar (title Command)

title Backup - Running
- □ ×
Command Prompt Icon
Backup - Running
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>title Backup - Running

Changing the title while a batch file runs lets you see at a glance which step is in progress.

Using It in a Batch File

@echo off
title Data Processing [1/3] - Copying files
copy /Y source\*.* dest\ >nul

title Data Processing [2/3] - Converting data
rem Conversion...

title Data Processing [3/3] - Cleaning up
del /Q temp\*.tmp >nul

title Data Processing - Done
echo All processing is complete.
pause

Changing the Prompt String (prompt Command)

The prompt command changes the text displayed at the prompt.

prompt $P$_$G

This shows the current path with > on the line below.

Special Codes for prompt

CodeDisplays
$PCurrent directory
$G>
$DDate
$TTime
$NCurrent drive
$_Line break
$$$

Restoring the Default

prompt

Useful Environment Variables

Here are some standard environment variables worth knowing.

VariableContents
%USERPROFILE%The user’s home folder
%APPDATA%Application data folder
%TEMP%Temporary files folder
%COMPUTERNAME%Computer name
%USERNAME%Current user name
%OS%OS name (Windows_NT on Windows)
%DATE% / %TIME%Current date and time (format depends on regional settings)
%RANDOM%Random number from 0 to 32767
%CD%Current directory (dynamic)
%ERRORLEVEL%Exit code of the previous command
%~dp0Folder path of the batch file itself (batch files only)

Example

echo User name: %USERNAME%
echo Home: %USERPROFILE%
echo PC name: %COMPUTERNAME%
echo Random: %RANDOM%
Using %~dp0

%~dp0 returns the path of the folder that contains the batch file itself. Use it to reliably refer to files in the same folder as the batch file. Example: set CONFIG=%~dp0config.ini

Storing Command Output in a Variable

Use for /f to store the output of a command in a variable.

@echo off
for /f "tokens=2 delims=:" %%A in ('ipconfig ^| findstr "IPv4"') do set IP=%%A
echo IP address:%IP%
Command Line vs. Batch File

The for variable is written %%A in a batch file but %A when typed directly at the Command Prompt. The value of %IP% also starts with a space. If there are several network adapters, or if autoconfiguration IPv4 lines also match, the value from the last matching line is kept.

Chaining Multiple Commands

SymbolMeaning
&Run the next command regardless of the previous result
&&Run the next command only if the previous one succeeds
||Run the next command only if the previous one fails
mkdir backup && echo Folder created || echo Failed to create folder
チェック

In the form A && B || C, C also runs if A succeeds but B fails. When you need strict branching, use the IF command.

Drag and Drop Files

Drag a file or folder onto the Command Prompt window to type its full path automatically.

This saves you from typing long paths by hand.

QuickEdit Mode

Enable “QuickEdit Mode” in the Command Prompt properties to select a range with the mouse, copy it with Enter, and paste with a right-click.

Summary

TipAction
Show command historyF7 key
Tab completionTab key
Interrupt a commandCtrl+C
Change screen colorscolor background-foreground
Change the titletitle text
Change the promptprompt format
Batch file’s folder path%~dp0

Keeping these tips in mind makes working in the Command Prompt much faster.

Practice Quiz

Practice Problem

Which key do you press to show the command history list as a popup in the Command Prompt?

回答がサーバーに送信されることはありません
#Command Prompt #Tips #Shortcuts #Customization #Productivity