2012-09-03

DOS vs Unix commandline

I did have to work on Windows and Unix in parallel for pretty much my entire coding life, where I had a Windows machine as workstation, and the servers were some dialect of Unix. In this situation, the following may be useful. This doesn't want to be complete.
Operation Windows Unix csh-based (csh, tcsh)
initialisation NT: set to the values in "System Properties/Environment", DOS: set in autoexec.bat set in /usr/local/env/.cshrc (sometimes /etc/.cshrc), followd by ~user/.login if login shell.
I/O redirection cmd <in-file >out-file-new
cmd >>out-file-append
stderr cannot be redirected, always goes to screen.
dito.
filename expansion ? single char, * any number of any (including the dot at the beginning of filenames). eg dir test*.doc will find all files starting with test and the extention doc. dir test* and dir test*.* are the same. dito, but * doesn't match a dot when it's the first char in a filename (as such files are used as system ressources.). Mask meta-chars with \.
whitespace protection cmd "with blank" cmd 'with blank'
Process piping with cmd1 | cmd2 dito
Version winver showrev
environment setting set [var=[string]] sets env vars.
Note: no space behind =. Without var, all vars are shown on stdout. set vars locally for a skript between setlocal and endlocal . each setlocal must be freed by the endlocal before skript end.
set var = text with mandatory spaces. setenv name text sets and exports variable. set ! (bangs) in text are replaced by incremental numbers. array vars are defined as set var = ( foo bar baz )
path path=newpath;%path% set path = ( /bin /usr/bin /usr/local/bin ) path is defined as an arry.
directory listing dir ls
help option command /h man command or command --help
file identity check comp cmp
file difference comparison comp f1 f2 for same sized file (default binary)
fc f1 f2for text files.
cmp
file length
grepping find
findstr with regexen
grep
timing
size check
view users who -al, whoami, groups
view host hostname hostname, showrev
view user on remote host finger usrname@hostname dito
processes ps -elf
jobs jobs
rights chown, chgrp
file attribs chmod
scheduled execution at cron
Sortieren sort sort
Output paging more use pipeing to page output from other programs, file redir and name expansion to page contents of files. more
html downloading wget wget
free memory mem
show text file contents type f1 [f2 ..] cat
route tracing tracert traceroute
internet IP-name lookup nslookup nslookup
show net connections netstat
ping if computer is on network ping ping
printing lpr lp
prompt style prompt $p$g$p = pfad, $g = > # superuser, % normal, set prompt = "`hostname`:` pwd`>"
variables args for batches are stored in %1 to %9.
environment var contents are accessed like this: %VARNAME% Expansion works here too, i.e %* means a list of all %1 to %9.
$var for normal vars or full arrays, $array[2-4] for array slices, $#array number of elements, $?var if var is defined 1, else 0.
executable search path path without param shows path. entries separated by ;(semicolon).
append old path with path newdir;%path%