We are done with the OSI model series! Now that we are finished with that, I decided to start a new one: CLI and Batching. This series is all based on Windows. In the future, I might do other platforms as well
.
Way back when during the dinosaur age of computing, graphics didn’t really exist (at least on the PC side
). There was no mouse. Only a keyboard. The screen you looked at consisted of a flashing dash. If you wanted to run a program, you have to type in the correct path and file name. As far as multitasking, what was that non-sense? Only one program was executed at a time (at least for the average user.)
Apple, on the other hand, decided to use technology that they obtained from Xerox (who saw no use for it) and used a completely revolutionary interface that we all enjoy to date. Instead of text, they decided to use graphical representations. Instead of just a keyboard, they also included a mouse. This interface was then used by Microsoft in order to release a PC version (well, IBM at the time) of this interface and called it ‘Windows.’
The interface that you are using right now with a mouse is called GUI (pronounced as ‘gooey,’ stands for Graphical User Interface). Although it demands more processing power than the other interface, it is the most popular to date. You don’t have to type in commands to do something. You can click on a program to run it, you can bring up a menu to do a command, you can easily multitask, and you don’t have to worry about correct syntax.
The other interface is known as CLI (command-line interface). Before GUI was invented, CLI was your only option, but a powerful one. However, CLI definitely has a bigger learning curve than GUI.
When I was growing up, my parents gave me an old Tandy computer. It ran on DOS. There was no GUI, only CLI. I am happy with that experience, because all through out college I had a much easier time with scripting and batching than my classmates because I had some experience using CLI. Some classmates just had a hard time wrapping their minds around it. But, once you get the basic concepts of it, CLI can be pretty easy and powerful.
But, now that we are in the 21 century, why is CLI still around? Isn’t it dead if not fading away? Well, the answer to that is no. It is actually starting to pick up some steam again. While most home users will probably not even see CLI in their life times, CLI is still used by power users and IT professionals. In fact, my web server, powered by Linux, is 100% CLI and does not have a GUI installed.
So, what is the advantages of CLI over GUI? Why even care to learn about it? There are a couple of reasons why. First of all, some utilities will only work on CLI. If you have read the OSI model series, we have used ‘ping’ and ‘tracert’ a few times. The second reason why you would want to know CLI is to create batch files. A batch file is a script file in Windows. It follows a list of commands, line-by-line, as though it was reading a ‘script.’
These can be created to write full-blown applications, but usually they are used to automate tasks. For example, back 10 plus years ago, hard drive space was a big issue to me. I used three different MP3 players because I liked the advantages of each one. However, each one had their own way of organizing my MP3 files. Some saved j-peg images of the album artwork, some used their own file format for track information. It annoyed me to no end. All I wanted in my MP3 folder were MP3 files, that was it! So, I created a batch file that would go through my folder at start-up and delete any file that was not an MP3 file.
That was just one example of how to use a batch file. There are many more uses for batch files:
- Automatically delete temporary files
- Do automatic backups
- Used in conjunction with other programs
- Repeat CLI utilities (like retry pings)
- Automatically launch programs based on conditions
- Create log files
- Many, many more uses…
I am not an export in creating batch files or the CLI, but I know the basics and enough so that I can build on my knowledge. Hopefully, after this series, you would be able to, too!
Alright, let’s do something a little fun. Go to start->run and type ‘cmd.’ This will bring up a command window. Type in ‘help’ and press enter. This will give you a list of most all the commands you can use. If you want to see what a command does, type ‘help <command>’, where <command> is the command you want info on. This will give you a help page on how to use it. This series will not tell you how to use each and every one of these commands, but we will do a lot of them. WARNING: SOME COMMANDS CAN ERASE OR DESTROY YOUR DATA. BE VERY CAUTIOUS ON WHAT YOU TYPE!!!!!
After you are done playing with the help, minimize the window. We will create a simple batch file. However, before you can do that, you need to make sure that you can see file extensions. First, open up a folder (it can be your documents folder.) Then, go to tools->folder options, click on the view tab, and make sure ‘hide extensions for known file types’ is not checked. See picture below:
Now, click on ‘apply’, and close the window. On your desktop, right-click, select new->text document. This will put a text document on your desktop. Now, open it up, and type echo hello world! Save the file, and close it. Now, rename the file to ‘hello.bat.’ Accept the warning you receive.
NOTE: I have AVG as my virus scan, which as of this writing will interfere with batch files. If you have an issue and have AVG, open up your resident shield and turn ‘Identity Protection’ off. Don’t forget to turn it back on when you are done creating batch files.
If you have done it right, your file should now be an icon with a gear inside it. Double-click on it. A command window will flash for less than a second. What happened? The batch file ran the the command and then exited the window. We want it to stay on the screen so we can actually read it.
Right-click the batch file, and select ‘edit.’ This will bring up notepad again. Click just after world!, hit enter so that a second line is created. Now, type in pause, save the file, close it and double-click on it again.
The window will now stay open until you press a key. However, it looks a little messy because not only it does the commands, it shows what commands it is doing. Let’s get rid of that.
Edit the file again, and type echo off as the first line. The file should now be:
- echo off
- echo Hello world!
- pause
Now, save the file and re-run it. It looks a lot better, but ‘echo off’ is still displayed in the window.
Edit the file one more time. After echo off, create a line that says cls. This will run the echo off command, then clear the screen. You should now have:
- echo off
- cls
- echo Hello world!
- pause
Save the file and run it one more time. There! You have now just created a simple script. Cool, huh? We will get into a lot of more detail in later posts. You might want to create a folder dedicated just for batches and put that file in there. Also, if you still have the command window minimized, go ahead and bring it up. You can type help echo, help pause and help cls to see what these commands do.
WARNING: SOME OF THE BATCHES THAT WE WILL DO MAY MESS UP DATA IF NOT TYPED IN CORRECTLY. ALWAYS MAKE SURE YOU BACK UP YOUR DATA. THESE POSTS ARE DONE AT YOUR OWN RISK. I AM NOT RESPONSIBLE FOR ANY LOST OR DAMAGED DATA.
I will give ample warning before we do anything that can be risky.

