Starting to feel a little more comfortable with CLI? Good! However, we have a long way to go to become an expert. Thus far, we have explored what a directory is, how to change directories, how to create and delete directories, how to create text files with echo and redirects, how to move files, and how to delete them. But, I bet in GUI, you probably know how to do a lot more than just that.
For example, when we do a dir to list the content in a directory, shouldn’t there be more options for that? In GUI, we can view a file and sort by name, by type or recent. We can also do a list, do a detailed list, or as thumbnails.
Well, in CLI, there is no need for thumbnails, because there is no graphics (of course!). But, we can change the order of how items are displayed on the screen. Just like there are options that can be changed in GUI, there are options that can be changed in CLI as well. This can be done by using a flag option. A flag is a setting that can be changed that effects the behaviour of a command or program. It is marked with a forward slash (/) in front of it, followed by a word or a letter. If you have ever used the ipconfig command, you know that renewing your DHCP address is done by typing ipconfig /release followed by ipconfig /renew. The /release and /renew are flags of ipconfig.
NOTE: On most other platforms, flags are called ‘switches’, and use a hyphen (-) in front of it instead of a forward slash (/).
In order to play around with dir and flags, a great directory to do this in is the windows directory, because it contains a lot of files and folders to play around with. I am assuming that your windows directory resides on c:\, because most systems are setup that way. However, if the dir command cannot find the folder, then it might be on another drive, such as d:\. So just place d:\ instead.
WARNING: THE WINDOWS DIRECTORY IS A VERY, VERY, VERY IMPORTANT DIRECTORY ON YOUR COMPUTER. DO NOT MAKE ANY CHANGES TO IT, BECAUSE YOUR COMPUTER CAN BECOME UNSTABLE OR NOT BOOT. THESE EXERCISES ARE DONE AT YOUR OWN RISK, AND I AM NOT RESPONSIBLE FOR YOU MAKING YOUR COMPUTER UNBOOTABLE.
Since the windows directory is a very important directory, we will be using the dir command on it only. While the dir command does not make any changes, I don’t know every single key combination in existence, so I cannot guarantee that you cannot mess up your computer with the dir command. If you want to experiment with the dir beyond this post, at least do it in another directory first (like your batch files directory.)
Ok, open up a command line window by start->run and type ‘cmd’. Now, type in dir c:\windows and press enter. This will display the content of the windows directory. Were you able to read everything? Don’t worry, you don’t have to be a fast reader in order to read a directory list that does not fit on your screen. There is a flag we can use to slow it down. To see what flags we can use, type in help dir and press enter. You can see all the flags dir supports.
What we want to do is use the pause flag. Type in dir /P c:\windows and press enter. This is going to display what can fit in your window, and pause until you hit a key.
OK, that is simple, but what if you just want to list the directories (try doing that in GUI
). Type in help dir again (or press the up key to go through the history until it is displayed) and press enter. Look at the attributes flag. You can list directories only, hidden files only or even files that are just read only. Depending on what letter you use with the attributes flag is what option it will use. The proper syntax is to do the flag, followed by the letter you want to use with no spaces. So, in order to just display the directories in windows, type in dir /AD c:\windows and press enter.
As you might have guess, you can combine flags as well. If the list is too big to fit on your screen (it should be), you can combine the attributes flag with the pause flag. Type in dir /AD /P c:\windows and press enter. You can now view the list and have it pause screen by screen.
NOTE: As far as I can tell, it does not matter the order you type in flags. However, I like to type in the flags first, and then the path, even though that order does not really matter, either.
Well, this is a short post. Feel free to play around with the other flags. However, like I said in my warning earlier, you might want to test out the flags in the ‘batch files’ we have been working in first before you do it on the windows directory. Copy and erase have flags as well, but DO NOT USE THEM ON THE WINDOWS DIRECTORY.
Join the forum discussion on this post
