14 Windows Command Line Tricks
Matthew Inman of SEOmoz recently wrote Web Developers: 13 Command Line Tricks You Might Not Know. This was an excellent post which can really make your life easier in the *NIX world. But, for many, it is a Windows kind of life. So, for those of you out there, I have put together some Windows command line tricks that might make your life easier.
Save A List of Files to a Text File by Extension
This command line will create a file called files.txt. When you open this file, there will be a complete list of all the files in that directory and all subdirectories with the .ext extension. You can then open up this text file in any text editor and work this the information.By changing the ext part, you can select different files. For example, if you wanted to list all of the PDF documents, you would type:Get Your IP Address Information
- Host Name
- Primary DNS Suffix
- Node Type
- IP Routing Enabled
- WINS Proxy Enabled
- DNS Suffix Search List
- Connection-specific DNS Suffix
- Network Adapter Description
- Physical (MAC) Address
- DHCP Enabled
- IP Address
- Subnet Mask
- Default Gateway
- DNS Servers
Get Installed Driver Information
It can be very useful when troubleshooting to know what drivers are installed on a system. This command will give you a complete listing of the drivers and when they were installed.
Copy Files Via Infrared Port
This will fire up the Wireless Link dialog so that you can copy the specified file via an infrared port.
Find Files Opened By Network Users
If you are running a system and you want to know who has files open on your computer, this command will provide you a list of those users and the files that they have open.
Note: If you get an error saying The system global flag ‘maintain objects list’ needs to be enabled to see local opened files, you can fix this issue by typing
openfiles /local on. You will have to reboot the system but it will resolve the issue.
Monitor Port Activity
This will show you all of the TCP/IP ports that are being used on your system and what they are connecting to (or being connected from). It will continue to monitor these ports and refresh the information every 30 seconds. You can change the refresh rate by changing the number at the end of the command.
Recover Information From A Corrupt File
If you have a disk with damaged sectors, you can attempt to recover as much information as possible from the damaged file. Data that is not damaged can be retrieved but data in damaged sectors will be lost.
Defragment Remote Computer
This command used the rexec command to force a defragment of the C: drive on the computer named remotePC. You can use whatever you want to for the command (I just used defrag C: /F as an example). This is very useful for remote maintenance.
Retrieve Detailed System Information
With this command, you can retrieve the following information:
- Host Name
- OS Name
- OS Version
- OS Manufacturer
- OS Configuration
- OS Build Type
- Registered Owner
- Registered Organization
- Product ID
- Original Install Date
- System Up Time
- System Manufacturer
- System Model
- System type
- Processor(s)
- BIOS Version
- Windows Directory
- System Directory
- Boot Device
- System Locale
- Input Locale
- Time Zone
- Total Physical Memory
- Available Physical Memory
- Virtual Memory Max Size
- Virtual Memory Available
- Virtual Memory In Use
- Page File Location(s)
- Domain
- Logon Server
- Hotfix(s)
- NetWork Card(s)
Automatically Defragment C: Daily
This will set your computer to automatically perform a complete defrag of the C: drive each day at 11:00:00 PM (23:00:00). It does this by creating a scheduled task called Defrag C. It will run this command under the computer’s system account.
Map A Drive Letter to a Folder
Sometimes, your directory structure can get pretty deep and complicated. You can simplify this a bit by mapping a drive letter to commonly used folders. In the example that I have given, this will create a drive letter W: and map it to the C:\windows directory. Then, whenever you go into My Computer, you will see a W: drive and when you browse to it, it will automatically take you to the contents of the C:\windows folder.
You can do this with any unused drive letter and any folder that exists on your system.
List All Tasks Running On The Computer
It’s always good to know what is running on your system. This is the command line version of the processes tab in Taks Manager.
Kill A Program
If, when using the tasklist command, you discover that there is something running you just want killed. This is the way to do it! Just note the program name and use it in place of programname.exe.
Reboot a Remote Computer
Sometimes, you just need to reboot a system. This will do it remotely and give the user a 20 second warning. If you found this post useful, why don't you buy me a cup of coffee to show your gratitude?
17 Responses to “14 Windows Command Line Tricks”
-
runpcrun Says:
February 9th, 2007 at 6:52 amExcellent post, learnt a few things there.
My additions:-
Command line shortcuts
cmd /c - Carries out the command specified by string and then terminates
&& - concatenates commands togetherThis way you can create a shortcut for short scripts without creating batch files.
e.g. a shortcut for stopping and starting the print spooler.
%windir%\System32\cmd.exe /c "net.exe stop Spooler && net start Spooler"Sleep
No sleep command in Windows 2000/XP (AFAIK) unless you have the Resource Kit, and then you have to move extra files around with your scripts.
Simply use the ping command to wait predefined times. In this example it’s 10 seconds.ping -n 10 127.0.0.1 > NUL 2>&1Find
Windows answer to grep. Not as powerful but still useful.
e.g. In conjunction with systeminfo above to find out the Virtual Memory on the PC.
systeminfo |find "Virtual Memory" -
Phil Says:
February 9th, 2007 at 7:52 amThanks. Very helpful.
For a huge collection of very useful Windows utilities, including a bunch of command line tools (including remote control tools), I recommend the SysInternals collection at http://www.sysinternals.com (bounces to a Microsoft site, but that’s because Microsoft bought the company).
-
Nuke’s NEWS & VIEWS Says:
February 10th, 2007 at 3:26 pmThis was an excellent post which can really make your life easier in the *NIX world. But, for many, it is a Windows kind of life. So, for those of you out there, I have put together some Windows command line tricks that might make your life easier. Source: dailycupoftech.com While you’re there be sure to check out the many helpful links to previous DCoT articles. I hope you enjoy this week’s selection for Website of the week, Daily Cup of Tech. Enjoy. [IMG Add Photos & Videos]
-
Ates Goral Says:
February 11th, 2007 at 10:31 pmMy two cents worth:
To flush the DNS lookup cache (in case you’re using a dynamic DNS service for connecting to a remote machine etc.):
ipconfig /flushdnsIf you’re using IIS for local web development and you need to restart the web server (to clear the application data, to fix a DLL problem etc.), don’t take the long trip through Control Panel -> Administrative Tools -> Internet Information Services etc. Simply issue:
iisreset -
WebSlackr - Stuff on the Web Says:
February 12th, 2007 at 8:14 pmlike terminating a program in Task Manager. The command even allows you to kill remote processes. shutdown - Reboot a remote computer This command can also be used to shutdown or restart your own computer. So check them out and have some fun. 14 Windows Command Line Tricks [Daily Cup of Tech] [IMG Add to del.icio.us] [IMG Digg This] [IMG Add to Reddit] [IMG ] [IMG ] [IMG ]
-
Nogz Blogz 3.4 Says:
February 21st, 2007 at 11:40 pmThis was an excellent post which can really make your life easier in the *NIX world. But, for many, it is a Windows kind of life. So, for those of you out there, I have put together some Windows command line tricks that might make your life easier. Read More
-
Dave Zeltserman Says:
February 22nd, 2007 at 1:46 pmThanks for the tips–very helpful. I’m trying to figure out if there’s a command that will allow me to determine whether hyperthreading is enabled. Do you know of any way to through the command line to read bios information, such as hyperthreading status?
thanks!
-
Aubrey Bailey Says:
February 27th, 2007 at 1:55 pmAbout the shutdown one, I cant seem to get it to work from my laptop to my desktop, it says access denied. I assume that this is because I don’t have them in the same domain. How can I specify a username and password for the netbios name?
the command I’m using is
shutdown -r -f -m 192.168.0.2 -t 1
thanks for the help -
lapu zeme Says:
March 1st, 2007 at 10:57 amvisu šīs direktorijas un apakšdirektoriju failu nosaukumus file.txt dir *.pdf /s /b > file_pdf.txt <- sadrukā visu šīs direktorijas un apakšdirektoriju .pdf failu nosaukumus failā file_pdf.txt Pāris citas viltības var pamācīties te
-
TommyK's Blog Says:
March 5th, 2007 at 7:15 pmDaily Cup of Tech » 14 Windows Command Line Tricks
-
martin Says:
March 18th, 2007 at 1:28 amTry:
runas /user:domain\user “cmd.exe /c shutdown -r -f -m 192.168.0.2 -t 1″if you also supply the password it will not prompt
-
Matt Says:
September 30th, 2007 at 11:39 pmYou forgot cat…
Useful for text files
in conjunction with |find “something” -
edsmiley.com Says:
October 3rd, 2007 at 4:42 amMy Del.icio.us [IMG RSS] Information Security Magazine (Oct 2007) : Putting Snort to Work Twelve Essential Photographic Rules - - PopPhotoSeptember 200714 Windows Command Line Tricks | Daily Cup of TechPython for system administrators deligoo - Delicious Search Engine Gary Voth Photography: The Forgotten Lens iPhone Native Applications List - iPod Touch Applications » Blog Archive » The List Quicksilver: Get to Know Quicksilver from Its Maker -
-
MARTiN Says:
February 5th, 2008 at 5:12 amAddition to “Tasklist” command.
To only get a list of the programs that the current user is running use “qprocess.exe” instead =)
-
John Says:
February 12th, 2009 at 2:29 pmfindstr is Window’s answer to grep
-
victor Says:
June 15th, 2009 at 7:28 amhow can i use the taskkill to kill an url filter? am not the one that install the filter so , do not know the name but would like to kill it .How would i do it using the taskkill command
-
NICK Says:
July 8th, 2009 at 11:32 pmGood collection

