]> Essential Windows commands tips – part 1 « MOleYArd (MOYA) blog


This blog mostly presents different approaches, methods and practices in software and web development, but also contains some "out of main topic" articles. MOYA (MOleYArd) products are presented here as well.



Valid XHTML 1.0 Transitional

Essential Windows commands tips – part 1

I decided to write a series about Windows commands targeted to less skilled users (there will be nothing new for the advanced Windows users, so if you belong to this group, you may skip this article :) )

This series is not intended to be a complete tutorial, its intent is just to show some of the most useful tricks. However, since as I already mentioned, it is targeted to rookies, so in this first part we will deal with the very basics – how to actually work with commands, command line and batch files in general.

There are two ways of using commands – you can use it in the command prompt (cmd.exe or in old versions of Windows command.com) or you can use it in batch files.

Using commands in command prompt

Command Prompt can be found in Accessories. The fastest way to run it in Windows 7 is to press Start and type cmd in the search bar and press Enter. In Windows XP, you can do the same, but instead of typing it in the search bar, you run Start->Run. Hopefully you are not fed up with mentioning these trivial tasks :) .

So assume that we have already started Command Prompt (CMD). We probably see the path of our user’s account root directory (or possibly other path, it’s not relevant now). There are 4 commands that I consider the most important and crucial to mention for people who are running CMD for the first time – cd, dir, help and more. After learning these four commands you can start using the command line relatively proficiently.

Type help. You will see a list of commands with their short description as an output. You will probably not see the complete list, but just the bottom of it. But you can use a scrollbar to see the upper part. However, sometimes an output of CMD commands might be so large that you cannot see the full output.

Let’s type tree. This will start outputting the whole structure of your directories. You can wait quite long to finish it, or you may stop it by pressing CTRL + C after a while. In any case (if you were not too fast :) ), if you try to scroll on the top of command line window, you will not see the beginning of the output. For these situation there is a command called more.

Now type tree | more. The outputting will now stop so you can see the beginning of the output. You can shift it by pressing Enter line by line or by pressing Space screen by screen. Press CTRL + C to stop it.

When you type help together with another command name, it will show you help for this particular command. Try help cd for example. The second or further typed word of command is called argument or parameter. Instead of typing help cd you can also write cd /?. Arguments that starts with a forward slash (or with a hyphen, but this is not the case of standard Windows commands) are also sometimes called switches.

Now you can see outputted help of cd command. It contains text description, examples and in the beginning the command syntax. Note that arguments are in [] brackets. It means that these arguments are optional. Try to read instructions from that help output. Also try help dir.

I have not yet explicitly mentioned what are the tasks of cd and dir commands, but you had probably noticed it in the output of help command. In short, cd changes current active directory and dir lists all files and folders in the current or specified directory.

Here are som usage examples (commented odd lines contain description, even lines contain actual command):

'show contents of the current directory
'show contents of the current directory
dir .
'change the current directory to the parent directory
cd ..
'show contents of the parent directory
dir ..
'change directory to drive C root directory
cd C:\
'change directory to directory C:\Users
cd C:\Users
'change directory to directory C:\Program Files
cd "C:\Program Files"
'show contents of directory C:\Program Files
dir "C:\Program Files"
'change drive to D:\

You probably noticed two things, if you were attentive. We used double quotes in the antepenultimate and the penultimate example. That’s because the path of the chosen directory included white space, but white space is a delimiter for arguments. If an argument includes white spaces, you have to put it inside double quotes. The last example contains just D: and this switches the current drive. In fact, you cannot change a directory with cd command to directory outside the current drive. Although you can show its contents with dir command.

The last thing I will mention in this section is how to select and copy text from the command line. It differs from usual Windows way. Right-click on the CMD window and choose Select All. Then press Enter. Now the complete visible output is in the clipboard and you can paste it for example into Notepad. If you want to select just the part of CMD output, right-click again, but this time choose Mark. Click anywhere in the window and move cursor to select area to be copied and then press Enter.

Well, that’s enough for now. You can close CMD by typing exit. I intended to include also the basics of using batch files, but I don’t want to make this article too long. So, wait for the next time :) .

Comments are closed.