Saturday, November 26, 2011

Basic Command Prompt Skills

Believe it or not, computers weren’t always the point-and-click wonders we know now.  No, they used to be giant creatures who’d take their input on punch cards and spit out a result on actual paper.  Almost makes you want to do your math in your head, yes?
Although those days are long over, one fact of those eras remains: the stench of the command line.  Yes, ladies and gentlemen, they still exist in modern computers, and I’m going to explain to you how to use it in your favorite operating system – Mircosoft Windows.
Essentially, there are only two different desktop (to distinguish from iOS or Android) operating systems out there.  Yes, I know that sounds ludicrous, but bare with me, because it’s true.  These two operating systems are MS-DOS (from which Windows is based), and Linux.
Now, hold on, you’re saying.  My nephew has a Mac, my husband uses Ubuntu at work, and surely they fit in somewhere!
They do, actually.  Both those fit into the Unix category.  Ubuntu is a form of Linux, which is a form of Unix written by Linus Torvalds.  And Macs are actually built on top of Linux and utilize a special form of Unix underneath called the Darwin Terminal (I’m sure you Mac diehards will know this already; for everyone else, Unix is a topic for another day).
Now, Windows is based upon MS-DOS.  In the beginning of Windows’s existence, it basically echoed all your commands to DOS which performed the action (to all of you who are wondering – MS-DOS is an acronym for Mircosoft Disc Operating System).  However, in modernity Windows can perform most of its actions itself now, and DOS is provided mainly for compatibly with old programs.
Now, onto using DOS and the terminal in general.  Here we go; here’s how to access the terminal:
  • In Windows: Go to the Start Menu, click All Programs, click Accessories, click Command Prompt.
  • In Mac OS X: Open a Finder window.  Go to your applications folder and find a folder called Utilities.  Open that folder then find the program called Terminal.  Double-click it to start it up.
  • Ubuntu: Use these instructions, taken from the Ubuntu docs:
Unity is the default Desktop Environment used in 11.04. Where systems are not ready for Unity they revert to Gnome which is also used in previous releases such as Ubuntu 10.04 LTS (Lucid), see next sub-section.
The easiest way to open the Terminal is to use the 'search' function on the dash. Or you can click on the 'More Apps' button, click on the 'See more results' by the installed section, and find it in that list of applications. A third way, available after you click on the 'More Apps' button, is to go to the search bar, and see that the far right end of it says 'All Applications'. You then click on that, and you'll see the full list. Then you can go to Accessories > Terminal after that. So, the methods in Unity are:
Dash -> Search for Terminal
Dash -> More Apps -> 'See More Results' -> Terminal
Dash -> More Apps -> Accessories -> Terminal
Keyboard Shortcut: Ctl + Alt + T
Today we’re going to focus on the MS-DOS commands.  In a later post I will cover Linux, which will apply to Mac users as well.

1.  Basics

The most standard thing you can do as simply navigate around your directory file structure.  You can do it by typing each of these commands into the MS-DOS window, then pressing Enter to confirm the command.
  • cd
    Change Directory Access a new directory by typing “cd directory-name”.  Navigate to “..” (that’s two periods), to go up a directory level.
  • dir
    Get a listing of every file and folder on the current directory you are in.
  • type
    Enter the contents of a plain, text (.txt extension) file, and the computer will write it out for you.  If it’s a long file, though, the lines may print so fast you can’t see them.  Also, don’t enter a Mircosoft Word file into this command: you won’t like the result.  Example: “type readme.txt”
Now that you know the three basic commands, try everything out.  Use “dir” to obtain a list of files and folders, “cd” to go to a different folder, and when you see a .txt file, use “type filename.txt” to print it onto the window.
And don’t worry: none of these commands in this section change your computer in any way.  Don’t be afraid to play around.

2. Getting Funky

You can do lots of things in the command prompt.  Things that are difficult, or even impossible, to do using the standard Windows interface.  Just type “help” to see them all.  Some of the commands may sound alien to you, like “mklink”, “icacls”, etc.  Best word of advice: don’t mess around with them.  Until you know what something does, don’t play with it.
We’re going to do something small and neat.  There exists a Windows command called “fc” that examines two files and displays the differences between them.  So go ahead and create two text files with Notepad.  Put anything in them, and save them (be sure with the .txt extension).  Navigate to where you saved them with “cd” then type “fc first-file second-file”.  Be sure to include the .txt extension – if you don’t the computer doesn’t like it.
The computer should spit out some output.  If it doesn’t, check your input, otherwise message me in the comments.  Happy Hunting!

No comments: