Nov 052014
 

What’s a Command Prompt?

This is the line of text prefixed automatically by the environment to the command you’re writing for an e.g. see below screenshot…

Customizing Command Prompt

How Can I Customize The Command Prompt?

Microsoft provides a built in command named as Prompt. As the name suggests this just help customize the prompt text shown in a command window. See the help for this command…

c:\Windows\System32>prompt /?
Changes the cmd.exe command prompt.

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
drive.

Some Killer Sample Prompt Commands and Their Output

Please refer above help to figure what every character after the $ mean…

  • Command: prompt ——$G$P$G
    • New Prompt: ——>c:\Windows\System32>
  • Command: c:\Windows\System32>prompt $V$G$P$G
    • New Prompt: Microsoft Windows [Version 6.3.9600]>c:\Windows\System32>
  • Command: c:\Windows\System32>|>prompt $P$G$B$+$G
    • New Prompt: c:\Windows\System32>|>.
      The above prompt adds a ‘+’ sign for every pushd you do and removes the last ‘+’ after a popd. See below…
  • c:\Windows\System32>|>pushd c:\
    c:\>|+>pushd e:\
    e:\>|++>popd
    c:\>|+>popd
    c:\Windows\System32>|>
  • Funky Command:  prompt ╔═════════════════════╗$_║$P:$G$+║$_╚═════════════════════╝$_
    • New Prompt:
      ╔═════════════════════╗
      ║c:\Windows\System32:>║
      ╚═════════════════════╝

This just shows that you can customize the prompt to some extent. Above prompt will be ok if the current directory path is a small one but once it gets bigger you’ll have to adjust the square…

How to Make the Command Prompt Permanent?

Your custom command prompt will stick only for this session of cmd. If you start another instance of a cmd.exe you’ll end up seeing the default value or the one that’s setup elsewhere (as shown below).

So the question is how do we setup a command prompt that stays across sessions? Via the environment variable PROMPT. See below for my case…

Permanently Customizing Command Prompt

My personal favorite prompt is the one set by following command…

PROMPT $P$G$_$$$G

To set this as your prompt you can add an environment variable called PROMPT. Open environment variable window and then add the value as shown below…

Permanently Customizing Command Prompt

So now if you open a cmd instance you should see the following prompt…

Permanently Customizing Command Prompt

How do I revert my changes to the Command Prompt?

Valid question. To revert back to the original prompt, just type in command PROMPT without any arguments. You should see the prompt revert back to default. You might also want to remove the environment variable PROMPT else for next session you’ll again see the prompt you’ve setup.

Oct 212014
 

What’s Fsutil?

Fsutil is a Windows command line utility to help manage FAT and NTFS file systems. Common uses of this command is to…

  • Manage 8dot3name filenames, remove all short names in a folder.
  • View disk details
  • Query file system parameters
  • Dismounting volumes
  • Turning on last access time stamp on NTFS volumes
  • Figuring out file links
  • etc

I’ll be showing you few sample commands using Fsutil.

How to manage 8dot3name filenames using Fsutil?
Query 8dot3name filename status…

C:\>Fsutil 8dot3name query
The registry state is: 1 (Disable 8dot3 name creation on all volumes).

Scan registry to figure impact if 8dot3name filenames were removed from a directory

C:\>Fsutil 8dot3name scan /s c:\users\username\documents
Scanning registry…
<snip>

Enable or Disable 8dot3name file creation

C:\>Fsutil 8dot3name set
usage : set [0 through 3] | [<Volume Path> 1 | 0]

When a volume is not specified the operation updates the registry value:

0 – Enable 8dot3 name creation on all volumes on the system
1 – Disable 8dot3 name creation on all volumes on the system
2 – Set 8dot3 name creation on a per volume basis
3 – Disable 8dot3 name creation on all volumes except the
system volume

When a volume is specified the operation updates the individual
volume’s on disk flag.  This operation is only meaningful
if the registry value is set to 2.

0 – Enable 8dot3 name creation on this volume
1 – Disable 8dot3 name creation on this volume

This operation takes effect immediately (no reboot required).

Sample commands:
“Fsutil 8dot3name set 1”      – disable 8dot3 name creation on all volumes
“Fsutil 8dot3name set C: 1”   – disable 8dot3 name creation on c:

Strip a folder of 8dot3name file names

C:\>Fsutil 8dot3name strip
Usage : Fsutil 8dot3name strip </t> </s> </f> </l log file> </v> DirectoryPath

This command permanently removes 8dot3 file names from your volume. It will
list the registry keys pointing to the stripped 8dot3names but will not modify
the affected registry keys. Stripping will not be performed on files with full
path names longer than the maximum path length of 260 characters.

***WARNING***
If there are affected registry keys and you decide to use the override
switch /f, it is recommended that you backup your volume as it may lead to
unexpected application failures, including the inability to uninstall.

/t – Test mode – specifies that all operations should be performed
except the actual stripping of the file names.
/s – Recurse mode – specifies that this operation should also be
applied to subdirectories.
/f – Force mode – specifies that the directory should be stripped even
if there are registry conflicts.
/v – Verbose mode – specifies that all information logged should also
be printed out to the console.
/l – Specifies a log file to write to.  This must be followed by a path to the
log file.  If this option is not specified the log file will be:
“%temp%\8dot3_removal_log@(GMT YYYY-MM-DD HH-MM-SS).log”

Sample command:
Fsutil 8dot3name strip /l mylogfile.log /s D:\MyData

Modifying filesystem behavior using Fsutil

Queries or sets NTFS volume behavior, which includes:

  • The last access time stamp on NTFS volumes
  • How often quota events are written to the system log
  • The internal cache levels of NTFS paged pool and NTFS non-paged pool memory
  • The amount of disk space reserved for the master file table (MFT) Zone
  • The silent deletion of data when the system encounters corruption on an NTFS volume.
Disable8dot3 file system behavior using Fsutil

Sample commands…

C:\>Fsutil behavior set Disable8dot3 1
The registry state is now: 1 (Disable 8dot3 name creation on all volumes).

C:\>Fsutil behavior set Disable8dot3 0
The registry state is now: 0 (Enable 8dot3 name creation on all volumes).

Disable or Enable LastAccess timestamps on files using Fsutil

Sample commands…

C:\>Fsutil behavior set DisableLastAccess 1
DisableLastAccess = 1

You should now see LastAccess timestamp enabled on your files

C:\>Fsutil behavior set DisableLastAccess 0
DisableLastAccess = 0

LastAccess timestamp is now disabled for your files.

Sample SymlinkEvaluation command using Fsutil

C:\>Fsutil behavior set SymlinkEvaluation L2L:1 L2R:0
– Will enable local to local symbolic links and disable local to
remote symbolic links. It will not change the state of remote to
remote links or remote to local links.
– This operation takes effect immediately (no reboot required)

Using Fsutil to manage volumes

C:\>Fsutil volume
—- VOLUME Commands Supported —-

diskfree            Query the free space of a volume
dismount            Dismount a volume
querycluster        Query which file is using a particular cluster
filelayout          Query all the information available about the file
allocationreport    Allocated clusters report

How to view free disk space using Fsutil

C:\>Fsutil volume diskfree
Usage : Fsutil volume diskfree <volume pathname>
Eg : Fsutil volume diskfree C:

File usage on clusters using Fsutil

To find the file(s) that are using the clusters, specified by the logical cluster numbers 200 and 0x1000, on drive C, type:

C:\>Fsutil volume querycluster C: 200 0x10000
Cluster 0x0000000000010000 used by —-D \Users\nthomas\AppData\Local\Microsoft\Windows\INetCache\IE\Microsoft.VisualStudio.Data.Tools.Package.resourcesT8HR0EQA.HTM::$DATA
Cluster 0x00000000000000c8 used by —-D \Windows\WinSxS\ia64_microsoft.vc90.debugcrt_1fc8b3b9a1e18e3b_9.0.30729.4148_none_2a4c9d845558f4b7\msvcr90d.dll::$DATA

Using Fsutil to manage files

Usage…

fsutil file [createnew] <FileName> <Length>
fsutil file [findbysid] <UserName> <Directory>
fsutil file [queryallocranges] offset=<Offset> length=<Length> <FileName>
fsutil file [quaeryfileid] <FileName>
fsutil file [queryfilenamebyid] <Volume> <Fileid>
fsutil file [setshortname] <FileName> <ShortName>
fsutil file [setvaliddata] <FileName> <DataLength>
fsutil file [setzerodata] offset=<Offset> length=<Length> <FileName>

More on Fsutil can found on TechNet: http://technet.microsoft.com/en-us/library/cc753059.aspx

Sep 242013
 

Default Settings for Command Prompt

The default command prompt setting on Windows is pretty limited. Some limitation that I found while working on the command prompt is as follows…

  • Screen buffer size is very little. This means output of commands like ‘tree’ will not show up entirely in the command prompt. Once you scroll up you’ll not see the whole text. As a workaround you’ll have to redirect output to a text file.
  • Same with horizontal text, the text wraps around once the text touches the horizontal screen limit. I find this behavior annoying since this reduces readability.
  • Color is black and white. Its always cool to have different colors. I normally have dark red as background and white as foreground color.
  • Window size is limited. When you maximize command prompt it will only take half the screen size horizontally.
  • Its so painful to copy and paste. I want this feature to behave as in text editors like notepad. For e.g. just drag to select, instead of right clicking and selecting the “Mark” option.

After Customization of Command Prompt

Its very easy to customize our good old command prompt so that it stores more text vertically as well as horizontally. We can easily give good colors, better height and width etc. After customization this is how my command prompt looks in normal mode.

Command Prompt

Keep an eye on the scrollbar. The scrollbar thumbs are very small in size meaning they can scroll a lot more, which means more text. If you maximize the command prompt it occupies the entire screen as well.

Command Prompt Full Screen

If you look at the above output and the vertical scrollbar, I still have lots of screen buffer. If I scroll up I still see the command’s entire output. Isn’t this cool.

Copying and pasting is easy as well. Drag to select, right click on the selected area to copy and right click again to paste Smile. LOL that’s real cool. The selection is a free selection, always selects as a rectangle. See screenshot below…

Command Prompt with Selected Text

How to Customize Command Prompt

The whole customization lies in the command prompt’s system menu. Click on the dark icon at the far left corner, i.e. the system icon, of command prompt, select “Properties”. You should see a properties dialog popup.

To customize selection, copy, paste behavior check the “Quick edit” checkbox…

Command Prompt Properties Dialog: Options

To customize Font select appropriate fonts on the “Font” tab. This is how mine looks.

Command Prompt Properties Dialog: Font

To customize color, select appropriate colors in the “Colors” tab. This is how mine looks…

Command Prompt Properties Dialog: Colors

Please note there is a screen background and a popup background. Also there is a “Screen Text” and “Popup Text”. Screens stands for command prompt background, while popup stands for popup command dialogs, for e.g. press F7, the command history ‘popup’ window pops up…

Command Prompt Popup Dialog

Now comes my favorite, increasing the screen buffer size, or increasing the text buffer size of command prompt. This setting controls how much text the command prompt can hold. Please select the layout tab in the command prompt..

Command Prompt Properties Dialog: Layout

I’ve set the “Screen buffer Size” field values to high values so that it can hold as much text as possible. You can set your own values based on your preferences.

Hope this helps you in some way. Smile

Mar 162009
 

Use SUBST command…

SUBST [drive1: [drive2:]path]
SUBST drive1: /D

drive1:        Specifies a virtual drive to which you want to assign a path.
[drive2:]path  Specifies a physical drive and path you want to assign to
a virtual drive.
/D             Deletes a substituted (virtual) drive.

Type SUBST with no parameters to display a list of current virtual drives. An e.g. usage, create a  “p:” virtual drive for documents and settings folder path…

subst p: "C:\Documents and Settings"

To delete an existing virtual drive use…

subst /D p:

To see all existing virtual drives created…

C:\Documents and Settings>subst
N:\: => C:\
P:\: => C:\Documents and Settings

Also note that on machine restart these drives are not restored, for restoration after startup, create a batch file and put it into “Startup” folder in explorer. After a virtual drive is created, explorer shows this as an independent drive.