how to use cmd.exe and command.com

 

Overview

you can't do too much programming without learning how to use the cmd shell or command.com or the unix shells, so now is the time to learn.

Please refer to copying cmd shell contents to the clipboard, you will need to know how to do this! in *nix you select an area of the xterm/terminal and ctrl-c.

getting help

to get help from command.com or cmd.exe:
in unix, it's --help usually or -h
in windows, typically it's /? or /help or /h unless it's a program ported from unix like mysql server or pgsql server or apache httpd server. then use --help
sometimes utilities use -h for help. so be flexible and try everything, with the most obvious first.

in windows most every command except the networking stuff uses /? for help. the networking stuff uses - type of switches. for instance, if /? or ping --help

start with cmd /? and then try help from the cmd shell

/ vs. \

*nix utilities use / for directory and port and device paths. for instance, /dev/null is the bit bucket (like a trash bin - an abyss, where nothing comes out). in unix /dev/sda1 is the first partition of the drive /dev/sda

*nix paths don't have any drive letters.
drives are mounted as a filesystem to a directory you create using the command
mount -t ntfs-3g/ext4/btfs/otherFilesystemName /dev/devicename /mnt/someDirYouMade
after you are finished with the drive you can either umount /dev/devicename or umount /mnt/someDirYouMade

*nix doesn't use : in any paths. that would be considered a part of the filename if you did.

*nix filepaths are case sensitive.

not sure if the mac osx still comes under this heading, but it runs a kind of *nix, and the filesystem may or may not be case-sensitive.

in windows, you have drive letters A: through Z:

in windows, \\.\PhysicalDrive0 is the first hard disk. it MIGHT be also addressable as \\.\C:\ or \\.\C: (can't remember which, the directory name might be required in SOME Win32 API calls and not in others) or as \\.\C$ these are called UNC paths, and if you use something other than. it can refer to some remote computer if you have a drive connection to a share.

in windows, \ is used for filepaths instead \\.\PhysicalDrive0 is the first hard disk. it MIGHT be also addressable as \\.\C:\ or \\.\C: (can't remember which, the directory name might be required in SOME Win32 API calls and not in others) or as \\.\C$ (C$ is a share name for the C: drive, you can share folders and printers also).

in windows, the null device would look like NUL: and serial ports would be COM1: through COM8: and parallel ports are LPT1: if you still have these (now only available via USB devices).

basic commands

in windows, dir options filepathOrDirpath gives you a directory listing of files or folders.

in *nix, ls options filepathOrDirpath gives you a directory listing of files or folders.

in windows and *nix, cd path or chdir path changes into the directory path specified.

in windows and *nix, mkdir path creates the directory path specified.

in windows, md path creates the directory path specified.

in windows, type filepath ... dumps filepath to the console, more specifically, to stdout.

in *nix, cat filepath ... dumps filepath to the console, more specifically, to stdout.

absolute and relative paths

.. refers to the parent directory, and . refers to the current directory. if you are programming a directory walk, be sure to EXCLUDE THOSE!!!! you can include . and .. anywhere inside the path you want.

a windows absolute UNC filepath would look like \\someRemoteBox\someShare\Marketing\Rsrcs\logos\somecompany400x60.gif

a windows absolute local UNC filepath would look like \\.\someShare\Marketing\Rsrcs\logos\somecompany400x60.gif

a windows absolute local drive-letter filepath would look like C:\Marketing\Rsrcs\logos\somecompany400x60.gif

a windows absolute local relative filepath would look like logos\somecompany400x60.gif or if you are in the Engineering directory parallel to Marrketing, ../Marketing/Rsrcs/logos/somecompany400x60.gif

I don't think it's posible tohave a relative UNC path. I think UNC paths are all absolute.

a *nix absolute local drive-letter filepath would look like /user/home/joe/Marketing/Rsrcs/logos/somecompany400x60.gif

a *nix absolute local relative filepath would look like logos/somecompany400x60.gif or if you are in the Engineering directory parallel to Marrketing, ../Marketing/Rsrcs/logos/somecompany400x60.gif