Windows CLI utilities are odd but not bad (part I)

Being a unix- and linux-centric person, I have been spoiled by various useful small utilities. It’s a bit frustrating to find their Windows‘ counterparts, when I need to do some quick work on Microsoft Windows platforms (such as Windows XP or Windows Server 2003).

While studying for MCP 70-290 certification, I hold my nose and read the Microsoft’s self-study guide. Surprise, surprise! Once I RTFM (read the fine manual) line by line, I found them magical utilities. Some with different names, while some are just an oddly-named switch away.

The following are a few examples. In the example, the windows util is shown bold-faced, unix/linux command is shown after the infamous root prompt ‘#’, while the Windows counterpart is shown after c:>. Output is shown in italic.

  • findstr : to find a line matching a given string

# grep localhost /etc/hosts
c:>findstr localhost c:\windows\system32\drivers\etc\hosts
127.0.0.1 localhost

  • netstat : to find TCP ports that the operating systems are listening to.

# netstat -tln

c:> netstat -p tcp -n -a | findstr LISTEN

TCP 0.0.0.0:135 0.0.0.0:0 LISTENING
TCP 0.0.0.0:445 0.0.0.0:0 LISTENING
TCP 10.1.1.8:139 0.0.0.0:0 LISTENING

  • netstat : to find programs listening to a given TCP/port. It is a bit interesting to notice svchost.exe listening to TCP/135 as a stab for for five different DLL.

# lsof -i -P | grep :22 | grep LISTEN
sshd 19092 root 3u IPv6 214110 TCP *:22 (LISTEN)

c:> netstat -p tcp -n -a -b

Active Connections

Proto Local Address Foreign Address State PID
TCP 0.0.0.0:135 0.0.0.0:0 LISTENING 936
C:\WINDOWS\system32\mclsp.dll
C:\WINDOWS\system32\mclsphlr\gdlsphlr.dll
C:\windows\system32\WS2_32.dll
C:\WINDOWS\system32\RPCRT4.dll
C:\windows\system32\rpcss.dll
[svchost.exe]
TCP 0.0.0.0:445 0.0.0.0:0 LISTENING 4 [System]
TCP 10.1.1.8:139 0.0.0.0:0 LISTENING 4 [System]
TCP 192.168.27.1:139 0.0.0.0:0 LISTENING 4 [System]
TCP 192.168.153.1:139 0.0.0.0:0 LISTENING 4 [System]
TCP 10.1.1.8:1994 10.1.1.9:22 ESTABLISHED 2928 [SshClient.exe]
TCP 10.1.1.8:2133 216.49.88.156:80 ESTABLISHED 1524 [MpfTray.exe]
TCP 10.1.1.8:2189 66.249.83.83:80 ESTABLISHED 2108 [firefox.exe]

  • date, time to get the current date and time. A ‘/T’ switch is needed to avoid prompting for changes.

# date
Sat Jan 20 16:15:57 EST 2007

C:> date /T
01/20/2007 Sat
C:> time /T
04:15 PM

  • rename to rename a file or directory

# mv oldname newname
c:> rename oldname newname

  • rd to remove a directory

# rmdir dirName
c:> rd dirName

Leave a Comment

Powered by WP Hashcash