Changing windows command prompt

PROMPT – изменение приглашения командной строки CMD Windows.

Формат командной строки:

текст — Новое приглашение командной строки.

Приглашение может включать обычные символы и следующие коды:

$A & (амперсанд)
$B | (вертикальная черта)
$C ( (левая круглая скобка)
$D Текущая дата
$E ESC (символ ASCII с кодом 27)
$F ) (правая круглая скобка)
$G > (знак «больше»)
$H BACKSPACE (удаление предыдущего символа)
$L $N Текущий диск
$P Текущие диск и каталог
$Q = (знак равенства)
$S (пробел)
$T Текущее время
$V Номер версии Windows
$_ Возврат каретки и перевод строки
$$ $ (символ доллара)

Когда расширенная обработка команд включена, команда PROMPT поддерживает следующие дополнительные символы форматирования:

$+ Отображение нужного числа знаков плюс (+) в зависимости от текущей глубины стека каталогов PUSHD, по одному знаку на каждый сохраненный путь.
$M Отображение полного имени удаленного диска, связанного с именем текущего диска, или пустой строки, если текущий диск не является сетевым.

При использовании PROMPT без параметров, выполняется установка текста приглашения в значение по умолчанию — $P$G — текущий диск и каталог и знак “Больше”.

prompt /? — отобразить подсказку по использованию команды.

В тексте приглашения можно использовать значение переменных окружения:

prompt %computername% $P$G — перед стандартным приглашением будет отображаться имя компьютера.

prompt $C%computername%$F $P$G — то же, что и в предыдущем примере, но имя компьютера будет заключено в скобки.

prompt $c%computername%$F$M$P$G — в скобках будет отображаться имя локального компьютера, путь сетевого ресурса в формате UNC, буква сетевого диска и путь, например:

(COMP0)\\SERVER\install i:\Piriform > — Локальный компьютер COMP0, сетевой ресурс \\SERVER\install , подключен как диск I: , текущий каталог — Piriform

prompt $D$_$T$_$P$G — текст приглашения представлен тремя строками, в первой отображается дата, во второй – время, в третьей – полный путь текущего каталога. Пример:

В примере, время представлено с точностью до сотых долей секунды — 17:50:58,62 . Для того, чтобы избавиться от них, и знака запятой в том числе, можно использовать три кода $H для удаления 3-х предшествующих им символа:

prompt $D$_$T$H$H$H$_$P$G — то же, что и в предыдущем примере, но время отображается без долей секунды — 17:50:58

Tips for changing directories in windows command line

In Windows command prompt, we can change the directory using the command cd . Both cd and chdir refer to the same command. Syntax of this command is explained below with some examples.

Читайте также:  Windows installer package script required

Change directory

When we launch command prompt, the default directory it opens with is C:\Documents and Settings\logind. This is in Windows XP. In Windows 7 command prompt opens up with the directory C:\Users\loginid. Now let’s say you want to traverse to the directory C:\Windows\System32. The command for this is given below.

Change to a directory with spaces in the name

In Windows, we can have spaces in the directory names. cd command can interpret the space correctly. So we do not need to enclose quotes around the directory name, as with most of other windows commands. An example is shown below.

Change drive and directory with single command

The basic cd command does not work if you are trying to change to a directory that is located on a different drive. Say you are in C:\users\cmdadmin\ directory and want to change to E:\docs directory. If you run ‘cd e:\docs‘ you won’t get any error but you would still be in the same folder. Only when you switch the drive by running the command ‘E:’ you will move to the folder e:\docs. You can avoid this by using /d option with cd command.

This command changes to the drive E: and also changes the directory to E:\docs.

Tips for changing directories in windows command prompt

If you frequently work with windows command line, then the below tips would help you in easily changing the directories in command line.

Use Pushd and Popd commands:

Pushd command is similar to cd but it also saves the current directory path. So if you want go back to the directory where you have come from, you can just use popd command. It will take you to the last directory you were working in.

Pushd can remember all the previous directories you traversed as long as you change the directory using pushd instead of cd command. Using popd you can go back to all the previously visited folders in the reverse order. See the below example.

Changing default startup directory for command prompt in Windows 7

How do I change default startup directory for command prompt in Windows 7?

I usually do the following to start command prompt from C:\

I want to do the following to start command prompt from C:\

23 Answers 23

While adding a AutoRun entry to HKEY_CURRENT_USER\Software\Microsoft\Command Processor like Shinnok’s answer is the way to go it can also really mess things up, you really should try to detect a simple cmd.exe startup vs a script/program using cmd.exe as a child process:

Читайте также:  Как открыть файл vhd windows

Make a shortcut pointing to cmd.exe somwhere (e.g. desktop) then right-click on the copy and select «properties». Navigate to the «Shortcut» menu and change the «Start in:» directory.

The following solution worked well for me. Navigate to the command prompt shortcut in the start menu:

C:\Users\ your username \AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Accessories\Command Prompt

Right click on the shortcut file to open the properties dialog. Inside the «Start in:» textbox you should see %HOMEDRIVE%%HOMEPATH%. If you want the prompt to start in C:\ just replace the variables with «C:\» (without quotes).

update

It appears that Microsoft has changed this behavior recently and so now an additional step is required. After performing the steps above copy the modified shortcut «Command Prompt» and rename it to «cmd». Then when typing «cmd» in the start menu it should once again work.

PROMPT – изменение приглашения командной строки CMD Windows.

Формат командной строки:

текст — Новое приглашение командной строки.

Приглашение может включать обычные символы и следующие коды:

$A & (амперсанд)
$B | (вертикальная черта)
$C ( (левая круглая скобка)
$D Текущая дата
$E ESC (символ ASCII с кодом 27)
$F ) (правая круглая скобка)
$G > (знак «больше»)
$H BACKSPACE (удаление предыдущего символа)
$L $N Текущий диск
$P Текущие диск и каталог
$Q = (знак равенства)
$S (пробел)
$T Текущее время
$V Номер версии Windows
$_ Возврат каретки и перевод строки
$$ $ (символ доллара)

Когда расширенная обработка команд включена, команда PROMPT поддерживает следующие дополнительные символы форматирования:

$+ Отображение нужного числа знаков плюс (+) в зависимости от текущей глубины стека каталогов PUSHD, по одному знаку на каждый сохраненный путь.
$M Отображение полного имени удаленного диска, связанного с именем текущего диска, или пустой строки, если текущий диск не является сетевым.

При использовании PROMPT без параметров, выполняется установка текста приглашения в значение по умолчанию — $P$G — текущий диск и каталог и знак “Больше”.

prompt /? — отобразить подсказку по использованию команды.

В тексте приглашения можно использовать значение переменных окружения:

prompt %computername% $P$G — перед стандартным приглашением будет отображаться имя компьютера.

prompt $C%computername%$F $P$G — то же, что и в предыдущем примере, но имя компьютера будет заключено в скобки.

prompt $c%computername%$F$M$P$G — в скобках будет отображаться имя локального компьютера, путь сетевого ресурса в формате UNC, буква сетевого диска и путь, например:

(COMP0)\\SERVER\install i:\Piriform > — Локальный компьютер COMP0, сетевой ресурс \\SERVER\install , подключен как диск I: , текущий каталог — Piriform

prompt $D$_$T$_$P$G — текст приглашения представлен тремя строками, в первой отображается дата, во второй – время, в третьей – полный путь текущего каталога. Пример:

Читайте также:  Как сменить группу линукс

В примере, время представлено с точностью до сотых долей секунды — 17:50:58,62 . Для того, чтобы избавиться от них, и знака запятой в том числе, можно использовать три кода $H для удаления 3-х предшествующих им символа:

prompt $D$_$T$H$H$H$_$P$G — то же, что и в предыдущем примере, но время отображается без долей секунды — 17:50:58

prompt

Changes the Cmd.exe command prompt, including displaying any text you want, such as the name of the current directory, the time and date, or the Microsoft Windows version number. If used without parameters, this command resets the command prompt to the default setting, which is the current drive letter and directory followed by the greater than symbol (>).

Syntax

Parameters

Specifies the text and information that you want to include in the command prompt. /? Displays help at the command prompt.

Remarks

The character combinations you can include instead of, or in addition to, one or more character strings in the text parameter:

Character Description
$q = (Equal sign)
$$ $ (Dollar sign)
$t Current time
$d Current date
$p Current drive and path
$v Windows version number
$n Current drive
$g > (Greater than sign)
$l | (Pipe symbol)
$_ ENTER-LINEFEED
$e ANSI escape code (code 27)
$h Backspace (to delete a character that has been written to the command line)
$a & (Ampersand)
$c ( (Left parenthesis)
$f ) (Right parenthesis)
$s Space

When command extensions are enabled the prompt command supports the following formatting characters:

Character Description
$+ Zero or more plus sign (+) characters, depending on the depth of the pushd directory stack (one character for each level pushed).
$m The remote name associated with the current drive letter or the empty string if current drive is not a network drive.

If you include the $p character in the text parameter, your disk is read after you enter each command (to determine the current drive and path). This can take extra time, especially for floppy disk drives.

Examples

To set a two-line command prompt with the current time and date on the first line and the greater than sign on the next line, type:

The prompt is changed as follows, where the date and time are current:

To set the command prompt to display as an arrow ( —> ), type:

To manually change the command prompt to the default setting (the current drive and path followed by the greater than sign), type:

Оцените статью