Showing posts with label command-line tips. Show all posts
Showing posts with label command-line tips. Show all posts

Saturday, October 9, 2010

Equivalent of Unix’s ls –lah | grep something for Windows

Hello, ever since I am using linux based platforms I loved them for the rich command shell. It’s been very easy for me to find what I am looking for using command piping and the grep command. A very common combination that I’ve been through is “ls –lah | grep something”, which searches for specific file in current folder. Or “ps –ax | grep processname” which searches for specific processanme in the list of all running processes. Recently I had to, on Windows OS, very often run “netstat –an” to search whether specific port is occupied and by which executable. However that Windows OS is Windows Server, and it has lots of services running, so finding a specific port was terribly hard. A quick search gave me desired result.

You can use Windows’ command “find” exactly the same way you use “grep” in linux/unix! So finding a specific port occupation is like that:

netstat –anb | find “:80”

this will list all “:80” in the list, which basically means – all 80 ports occupied!

Great stuff!

Monday, February 5, 2007

Command-line tips & tricks

Ever wander how to automate specific services starting and stopping ?
Well, at first the easiest part:
How to start or stop windows service from command-line ?use the tool "net" provided by windows:
net start [name of the service]
for example:
net start "SQL Server (MSSQLSERVER)"
We can also, stop the service with this tool:
net stop "SQL Server (MSSQLSERVER)"

Now the tricky part - how to START / STOP IIS site using command-line?
(Tested against IIS 6.0)
Microsoft provides some useful scripts that automate this work, and we can use them with the command-line tool cscript.exe. Let's assume we have the "Default Web Site" configure on the IIS and we want to start / stop it. Then open a command prompt and write down:

cscript /nologo %SystemRoot%\System32\IIsWeb.vbs /start "Default Web Site"
to start the site
or
cscript /nologo %SystemRoot%\System32\IIsWeb.vbs /stop "Default Web Site"
to stop the site.

You will find a number of other useful scripts and manual here.

All this helped me to make a batch files (.bat), which I use to start / stop services on my machine (I do not always need the services running and consuming memory and resources).