Simple Command Line Tricks

17 Mar

I use cmd.exe quite a bit every day and have never really bothered looking into to making this experience a bit more pleasurable.

When I think about it, the window is a bit small, I kinda wish it kept a bigger history and copying text is a bit of a pain the the ass.

This is the standard window that I’m sure you’re all used to:

Right click on the title bar and then view properties.

You can then set the following options:

Buffer Size: 500
Discard Old Duplicates: True
Quick Edit Mode: True
Screen Buffer Size Height: 900
Windows Size Height: 50
You can set the colours if you so wish, along with a different font.

Whilst we’re at it, there are some other useful shortcuts that you might want to take note of:

Up arrow: this repeats the previous commands, you can scroll through all your previously entered commands
F7: Shows a command history window
Drag & Drop: Simplyt drag and drop file into the window
Tab: This will complete the rest of the file/directory name for you. (Shift-Tab will go backwards through the available options)
Alt-Enter: Full screen command prompt

If you want to get a little more advanced, then try out these commands:

Export to a text file.

This will list all .jpg files (in that directory and and subdirectories) and save them in export.exe

dir *.jpg /s /b > export.txt

List open files

openfiles /query

This will list all the files

that are open on your machine by remote users

Monitor port activity

nestat -1 30

This will whaow all the TCP/IP ports that are being used on your machine and will refresh every 30 seconds

Retrieve detailed system information

systeminfo

This will bring back a whole heap of information about the machine you are on,  such ase OS, Processor(s), RAM, Network cards etc. If you know exactly which bit of information you are after then run this:

systeminfo |find “Total Physical Memory”

List all tasks

tasklist

This does exactly what itsays on the tin, well, it will tell you what’s running. If you  spot something you don’t like, you can kill it using this command:

If you want only the processes running by the current user, then use this command instead:

qprocess.exe

Kill a process

taskkill /im /prog.exe /f

This will kill the process prog.exe

Reboot a machine

Shutdown –f –m localhost –t 2 -r

Sometimes you’re not give the shutdown/reboot options, I often get this when I’m connected via RDC. The above command translates to: Shutdown, force this please, on the machine:localhost, in2 seconds, and reboot it.

Restart IIS

iisreset

This will restart IIS, of course.

Show which files are associated with which programs

assoc .html

Quite handy to quickly see which file type is associated with which program