In order to run Maven (which we will discuss in the next post), it is necessary to know how to run commands from the command line. If you are not familiar with using the command window, this post will explain the two most important commands. My instructions will refer to the Windows command line, but they can be adapted without too much difficulty to Linux or Mac.
To bring up the command line, go to the Start menu and type “cmd” in the search field. Click the return key and a command window should open.
cd stands for “change directory”. You will use this to navigate through your file system. When you opened your command window, you probably saw something like this: C:UsersYourName>. This is your user folder. If you were to navigate to it in the File Explorer, you would go to Computer->Windows7_OS (C:)
->Users->YourName. (The OS will vary based on your computer, and the YourName will be your user name.)
Let’s try navigating to the Users folder. In the command window, type “cd Users” and click return key. Note that the command prompt now says C:Users>.
There is another way to navigate up one folder. First, let’s return to your folder. Type “cd YourName” (replacing the words YourName with your actual user name) and click Return. Now the command prompt should say C:UsersYourName. Now type “cd ..” and click Return. Notice that you have returned to the Users folder. The two dots send the instruction to go up one level. If you type “cd..” and Return again, you will see C:> in the command prompt.
You can also navigate through more than one folder at a time. Type “cd Users/YourName” (replacing the YourName with your user name) and click Return. Now the command prompt will say C:UsersYourName. You’ve navigated down two levels, from the C: level to the YourName level.
dir is the command used to list all the files in a particular location. This really comes in handy when you can’t remember what you named a file.
Let’s try using the dir command. In the command window, verify that the command prompt currently reads C:UsersYourName. If it doesn’t, use the cd command to navigate there. Now type “dir” and click Return. You should get a list of all the files in your personal folder.
Let’s add a new file to this location. It’s possible to do this through the command line, but that is beyond the scope of this tutorial. Instead, create a simple Word or Notepad file called MyCommandFile, and save it in your folder. Now return to the command window and type the “dir” command again. You should see your new file in the directory.
Another shortcut to navigation when you have forgotten a file name is the tab key. In the command line, type “cd My” and then click the tab key. You should see the file name auto-complete for you.
One more helpful command to use is the up arrow key. This key will go back through your most recent commands. This really comes in handy if you have typed a particularly long command and would rather not type it again.
The command window is very helpful, and there are a number of good tutorials available if you would like to learn more about what it can do for you.