Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to modify my CMD, to show only current dir name dynamically like:

Desktop $

When i switched the folder, it must be updated.

It is not required to be code in purely batch file, it may depend any external commands, cygwin bash, etc.

@echo off
set a=bash -c "pwd | sed 's,^\(.*/\)\?\([^/]*\),\2,'"    


Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. Tüm hakları saklıdır.


>> prompt %a%


bash -c "pwd | sed 's,^\(.*/\)\?\([^/]*\),\2,'"
share|improve this question
up vote 1 down vote accepted

Using Microsoft's PowerShell, the prompt is produced by a function that can do anything at all.

A prompt function that does what you want is :

function prompt { (Split-Path -Leaf $pwd) + '$ ' }

For more information see :

Configure the Windows Powershell to display only the current folder name in the shell prompt
Powershell about Prompts
Perfect Prompt for Windows PowerShell

share|improve this answer
It is time to switch off CMD age and switch to PowerShell :) Thanks. Difficult to give up habituation but it is more likely cygwin, cd ~ works on PowerShell, but not in cmd. – guneysus Nov 12 '13 at 9:57

I believe you can use the prompt command.

PROMPT [text]

  text    Specifies a new command prompt.

Prompt can be made up of normal characters and the following special codes:

  $A   & (Ampersand)
  $B   | (pipe)
  $C   ( (Left parenthesis)
  $D   Current date
  $E   Escape code (ASCII code 27)
  $F   ) (Right parenthesis)
  $G   > (greater-than sign)
  $H   Backspace (erases previous character)
  $L   < (less-than sign)
  $N   Current drive
  $P   Current drive and path
  $Q   = (equal sign)
  $S     (space)
  $T   Current time
  $V   Windows version number
  $_   Carriage return and linefeed
  $$   $ (dollar sign)

If Command Extensions are enabled the PROMPT command supports
the following additional formatting characters:

  $+   zero or more plus sign (+) characters depending upon the
       depth of the PUSHD directory stack, one character for each
       level pushed.

  $M   Displays the remote name associated with the current drive
       letter or the empty string if current drive is not a network


setx PROMPT $P$S$$$S


Create a batch file containing the code below and run.

@echo off

set root=%~p0
for %%F in ("%root%.") do set "ParentFolder=%%~nF"
setx PROMPT %ParentFolder%$S$F$S

Result is:

enter image description here

share|improve this answer
Can you see above CURRENT DIRECTORY variable? Let's test it. Open cmd, and set prompt to: set prompt=$B$C$D$E$F$G$H$L$N$P$Q$S$T$V$_$$ which contains all variables except $+ and $M. But still I can not see still current dir, but give |(Pzt 04.11.2013←)<CC:\Users= 17:44:02,69Microsoft Windows [Version 6.3.9600] Why? Is there a huge bug on cmd.exe? – guneysus Nov 4 '13 at 15:44
@guneysus I updated my answer. :-) – quark8 Nov 4 '13 at 17:54
Thanks but i must change it, because current folder is not dynamic and with setx it is systemwide :) It shoud be set not setx In addition i will try replace cd function, to update it dynamically. – guneysus Nov 4 '13 at 18:49

Based on the wikipedia entry for AUTOEXEC.BAT prompt $P$G will do what you want. This is a holdover from good old DOS. God only knows why something like this was never made a default since the early days of ... DOS3.3 or so.

share|improve this answer
This is not what OP wants. It gives the complete path. OP wants only the last part of the current directory (without its parent-path). And it needs to change when changing the directory. It's not possible with the current prompt command. At least not in cmd.exe. – Rik Nov 30 '13 at 0:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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