InfotechGuyz.com Blog

How to manage disk related tasks from command line

> Format disk from command line
> Convert File System from command line
> View Volume Serial Number from command line
> Manage Volume label of a disk from command line
> Checks for free disk space from command line (Only Server 2003, server 2008)
> Checks and Repair Bad Sectors from command line
> Defragment Disks from command line
> View open shared files from command line
> Change File Permissions the command line (Vista uses ICACLs Utility)

 

Format disk from command line

H:\>format /?
Formats a disk for use with Windows XP.

FORMAT volume [/FS:file-system] [/V:label] [/Q] [/A:size] [/C] [/X]
FORMAT volume [/V:label] [/Q] [/F:size]
FORMAT volume [/V:label] [/Q] [/T:tracks /N:sectors]
FORMAT volume [/V:label] [/Q]
FORMAT volume [/Q]

volume Specifies the drive letter (followed by a colon),
mount point, or volume name.
/FS:filesystem Specifies the type of the file system (FAT, FAT32, or NTFS).
/V:label Specifies the volume label.
/Q Performs a quick format.
/C NTFS only: Files created on the new volume will be compressed
by default.
/X Forces the volume to dismount first if necessary. All opened
handles to the volume would no longer be valid.
/A:size Overrides the default allocation unit size. Default settings
are strongly recommended for general use.
NTFS supports 512, 1024, 2048, 4096, 8192, 16K, 32K, 64K.
FAT supports 512, 1024, 2048, 4096, 8192, 16K, 32K, 64K,
(128K, 256K for sector size > 512 bytes).
FAT32 supports 512, 1024, 2048, 4096, 8192, 16K, 32K, 64K,
(128K, 256K for sector size > 512 bytes).

Note that the FAT and FAT32 files systems impose the
following restrictions on the number of clusters on a volume:

FAT: Number of clusters <= 65526
FAT32: 65526 < Number of clusters < 4177918

Format will immediately stop processing if it decides that
the above requirements cannot be met using the specified
cluster size.

NTFS compression is not supported for allocation unit sizes
above 4096.

/F:size Specifies the size of the floppy disk to format (1.44)
/T:tracks Specifies the number of tracks per disk side.
/N:sectors Specifies the number of sectors per track.

Convert File System from command line

H:\>convert /?
Converts FAT volumes to NTFS.

CONVERT volume /FS:NTFS [/V] [/CvtArea:filename] [/NoSecurity] [/X]

volume Specifies the drive letter (followed by a colon),
mount point, or volume name.
/FS:NTFS Specifies that the volume is to be converted to NTFS.
/V Specifies that Convert should be run in verbose mode.
/CvtArea:filename
Specifies a contiguous file in the root directory to be
the place holder for NTFS system files.
/NoSecurity Specifies the converted files and directories security
settings to be accessible by everyone.
/X Forces the volume to dismount first if necessary.
All opened handles to the volume would then be invalid.

View Volume Serial Number from command line

H:\>vol /?
Displays the disk volume label and serial number, if they exist.

VOL [drive:]

Manage Volume label of a disk from command line

H:\>label /?
Creates, changes, or deletes the volume label of a disk.

LABEL [drive:][label]
LABEL [/MP] [volume] [label]

drive: Specifies the drive letter of a drive.
label Specifies the label of the volume.
/MP Specifies that the volume should be treated as a
mount point or volume name.
volume Specifies the drive letter (followed by a colon),
mount point, or volume name. If volume name is specified,
the /MP flag is unnecessary.

Checks for free disk space from command line (Only Server 2003, server 2008)

C:\Documents and Settings\Administrator>freedisk /?

FREEDISK [/S system [/U user [/P [password]]]] [/D drive/volume] [value]

Description:
This tool checks whether the specified amount of free space is
available on the specified drive or not. Returns "0" if space is
available and "1" if not available. When a value is not specified
it displays the available free space. Defaults to current drive or
volume.

Parameter List:
/S system Specifies the remote system to connect to.

/U [domain\]user Specifies the user context under which
the command should execute.

/P [password] Specifies the password for the given
user context. Prompts for input if omitted.

/D drive/volume Specifies the drive/volume on which the
availability of free space is to be known.
This option must be specified for a remote
system.

<value> Specifies the amount of free space in bytes.
It can be specified in the units of KB, MB,
GB, TB, PB, EB, ZB and YB.

/? Displays this help message.

Examples:
FREEDISK /?
FREEDISK
FREEDISK 4MB
FREEDISK /D c: 2048KB
FREEDISK /D d:\home\myvolume
FREEDISK /S system /U user /P password /D c: 4.5GB

Checks and Repair Bad Sectors from command line

H:\>chkdsk /?
Checks a disk and displays a status report.


CHKDSK [volume[[path]filename]]] [/F] [/V] [/R] [/X] [/I] [/C] [/L[:size]]


volume Specifies the drive letter (followed by a colon),
mount point, or volume name.
filename FAT/FAT32 only: Specifies the files to check for fragmentatio
.
/F Fixes errors on the disk.
/V On FAT/FAT32: Displays the full path and name of every file
on the disk.
On NTFS: Displays cleanup messages if any.
/R Locates bad sectors and recovers readable information
(implies /F).
/L:size NTFS only: Changes the log file size to the specified number
of kilobytes. If size is not specified, displays current
size.
/X Forces the volume to dismount first if necessary.
All opened handles to the volume would then be invalid
(implies /F).
/I NTFS only: Performs a less vigorous check of index entries.
/C NTFS only: Skips checking of cycles within the folder
structure.

The /I or /C switch reduces the amount of time required to run Chkdsk by
skipping certain checks of the volume.

Defragment Disks from command line

H:\>defrag /?
Usage:
defrag <volume> [-a] [-f] [-v] [-?]
volume drive letter or mount point (d: or d:\vol\mountpoint)
-a Analyze only
-f Force defragmentation even if free space is low
-v Verbose output
-? Display this help text

How to compress files to .cab from command line

H:\>makecab /?
Microsoft (R) Cabinet Maker - Version 5.1.2600.2180
Copyright (c) Microsoft Corporation. All rights reserved..
MAKECAB [/V[n]] [/D var=value ...] [/L dir] source [destination]
MAKECAB [/V[n]] [/D var=value ...] /F directive_file [...]
source File to compress.
destination File name to give compressed file. If omitted, the
last character of the source file name is replaced
with an underscore (_) and used as the destination.
/F directives A file with MakeCAB directives (may be repeated).
/D var=value Defines variable with specified value.
/L dir Location to place destination (default is current directory).
/V[n] Verbosity level (1..3).

View open shared files from command line

H:\>openfiles /?

OPENFILES /parameter [arguments]

Description:
Enables an administrator to list or disconnect files and folders
that have been opened on a system.

Parameter List:
/Disconnect Disconnects one or more open files.

/Query Displays files opened locally or from shared folders.

/Local Enables / Disables the display of local open files.
Note: Enabling this flag adds performance overhead.

Examples:
OPENFILES /Disconnect /?
OPENFILES /Query /?
OPENFILES /Local /?

Change File Permissions the command line (Vista uses ICACLs Utility)

H:\>cacls /?
Displays or modifies access control lists (ACLs) of files

CACLS filename [/T] [/E] [/C] [/G user:perm] [/R user [...]]
[/P user:perm [...]] [/D user [...]]
filename Displays ACLs.
/T Changes ACLs of specified files in
the current directory and all subdirectories.
/E Edit ACL instead of replacing it.
/C Continue on access denied errors.
/G user:perm Grant specified user access rights.
Perm can be: R Read
W Write
C Change (write)
F Full control
/R user Revoke specified user's access rights (only valid with /E).
/P user:perm Replace specified user's access rights.
Perm can be: N None
R Read
W Write
C Change (write)
F Full control
/D user Deny specified user access.
Wildcards can be used to specify more that one file in a command.
You can specify more than one user in a command.

Abbreviations:
CI - Container Inherit.
The ACE will be inherited by directories.
OI - Object Inherit.
The ACE will be inherited by files.
IO - Inherit Only.
The ACE does not apply to the current file/directory.