Tuesday, 22 September 2009

By Your Command: A Rough Guide to the Command Prompt, Part 2

In a previous post I explained how to navigate to different drives and folders using Command Prompt. I also showed how to list the contents of the current folder using the dir command. We will now look a little closer at this command.

In the tutorial, I suggested typing the following command dir /a-d /b > filelist.txt. We shall not worry about the > filelist.txt part for now, but rather look at the anatomy of the dir command itself to serve as an example of how Command Prompt works.

Following the dir command there are two switches: /a-d and /b. These switches alter the way in which the command works. In this case they adjust what folder contents is listed and how it is presented: /a-d stops the dir command from listing folders; /b prevents the command from showing the extra information you see if you just type dir and hit Return.

You can list all the switches associated with dir by entering dir /? in the Command Prompt. The /? switch provides help for any command it follows. In the case of dir it returns something like this:

This may be a little forbidding for the novice; so, I will give another example of switches in action. If you wanted to list all the folders (or directories as they are known in Command Prompt) at the top level of your D:/ drive you would enter -

dir d: /ad
[Note that switches are not case sensitive]

If you wanted to also list all the sub-folders, you would enter -

dir d: /ad /s

You may notice how all the information scrolls past really quickly. To pause after each page of information you can use the /p switch. Thus, the command becomes -

dir d: /ad /s /p

To list all the mp3 files on drive D: pausing after each page use the following command -

dir d:\*.mp3 /s /p

The asterisk is a wildcard. In other words. it means 'any combination of letters'. So if you wanted to list all the mp3 files with the word 'Beatles' in the filename you would use -

dir d:\*beatles*.mp3 /s /p

The dir command is a good way of having a play with the command prompt safe in the knowledge that you will do no harm to your files. If you have any questions about this command feel free to leave a comment and I will do my best to address them. More commands next time.

3 comments:

Jayce said...

Windows UI is user friendly now. I hardly use CMD nowadays. ^_^

KAT said...

I always find your blog very informative and interesting, and I don't know if you participate in blog awards or not, but I have given you one over at Candles, Crafts and Whatnot. Congrats!

:) Kat

Stepterix said...

J: I rarely use it myself. Except for diagnosing network problems and using the powerful xcopy command.

K: Thank you for the award.