35

My path on my DOS prompt is ridiculously long. How can I shorten this?

C:\RUBY\Ruby_Practice\prep-work-master\coding-test-2\practice-problems\spec>
Mark
  • 3,609
  • 1
  • 22
  • 33
jingyang81
  • 453
  • 1
  • 4
  • 7

4 Answers4

85

To remove the path from the prompt use 'prompt $g' which will just show the chevron. You can then use the 'cd' command anytime to see the directory you are in. E.g.

C:\Windows\System32\drivers\etc>prompt $g
>
>cd
C:\Windows\System32\drivers\etc

>
Daniel Ellis
  • 1,225
  • 1
  • 11
  • 6
38

Right-click on My Computer|Properties. Then from the Advanced Tab, click Environment Variables, then add a new User Variable called PROMPT and set it to $p$_$+$g.

http://www.hanselman.com/blog/ABetterPROMPTForCMDEXEOrCoolPromptEnvironmentVariablesAndANiceTransparentMultiprompt.aspx

davidmdem
  • 3,763
  • 2
  • 30
  • 33
Jiminion
  • 5,080
  • 1
  • 31
  • 54
14

In addition to the @Daniel's answer, if you want to go back to the normal state, You can type prompt (without any arguments) and press Enter

It's not related to the question exactly, but i find it more useful to this scenario. When we use this prompt $G, this changes the command prompt path to >. Even when you navigate to the sub folders, the prompt will still remain as > which is not much useful.

Rather than doing this, we can map the most used path to a virtual drive. like C:\Users\ram\Desktop\temp to a virtual drive X:. By this way, you need not to see the unneeded path, as well as you can see the sub folder navigations like X:\subfolder>.

This is more useful to map your project to a virtual drive and do all the operations.

To Map a path to a virtual Drive

1) type subst [Drive:] [path] Example: cmd>subst X: C:\Users\ram\Desktop\temp

2) Then go to the drive by typing X: and Enter

To back to the earlier mode, you can just type the corresponding drive letter. In this case C: and Enter

RamValli
  • 4,389
  • 2
  • 33
  • 45
  • 1
    Nice! Thank you! You just upped my productivity! – Frecklefoot Jul 07 '16 at 17:29
  • Running the `subst X: C:\path` command (and accessing it with `X:`) will create a duplicate icon of the drive if you look at your mounted drives. To remove the duplicate you can use `subst X: /D` – alejandro May 10 '22 at 01:33
3

Here is a .bat file that displays the prompt with the final folder name in the current dir path.

for %%* in (.) do set CurrDirName=%%~nx*
echo %CurrDirName%
prompt %CurrDirName% $G

Lines 1 and 2 come from This answer to SuperUser: "How can I find the short path of a Windows directory/file?"