Introduction to the Command Line Video:
What is a Command Line?
The command line is a text-based application used to process commands to a computer program. It’s similar to graphical interfaces like the Mac Finder or Windows Explorer, but it requires less system resources to implement. The command line is used to control and operate software systems, and convert them into files that the computer can process. You may have already heard of the command line under a different name; command-line interface or interpreter, CMD, CLI, prompt, console, or terminal.
How do you get to the Command Line?
If you have a Mac, Spotlight search the word “Terminal”. The spotlight search icon is the little magnifying glass in the top right corner, next to your name and the Siri icon. The Mac Terminal should be the first result that comes up. If you have Windows, go to the Start menu and search the phrase “Command Prompt”. If you have Linux, go to Applications, and then Accessories, and then “Terminal”. Once you’ve opened your command line, you should see a window that looks like one of these.
So now that you’re in the command line, here are some basic commands to use. To open a folder, for example, Downloads, type in “cd” all lowercase, a space, and your folder name. If you have a Mac or Linux, to view the contents of that folder, type in “ls”, all lowercase. If you have Windows, type in “dir”. Your command line should produce a list of all the files and folders within the directory that you’re currently in. To clear the command line, if you have a Mac or Linux, enter “clear” in all lower case. If you have Windows, type in “CLS” in all caps.
One of the most useful features of the command line is its ability to compile and run files. Before a file can be run, the computer needs to convert it from your programming language to a format that it can understand, called a Class file. In order to compile a Java file, type in “javac”, space, and the name of your file and “.java”. If the computer does not return any errors, then your file has been successfully compiled, and if you type in “ls”, there should be a new file with the same name, ending in .class. After compiling, run your file by typing in “java”, a space, and your file name, this time without the “.java” ending.
Note: This blog post is a courtesy of the Los Altos Computer Science Club (LACS).