Unit 02: Command Line

  1. Overview
  2. CLI - ping
  3. CLI - g++
  4. CLI - ls
  5. CLI - cd
  6. CLI reference sheet

This week's stuff:

Overview

As we learn the core concepts of programming, we tend to avoid working with GUI (graphical user interface) creation so as to not distract from the primary concepts. Additionally, every business is going to use different libraries and tools for interfaces, but the underlying language (C++, or C#, or Java) remains the same.

Additionally, while most average users only interact with their computers and phones through GUIs, there are still lots of command-line-based tools, especially used in software development, IT, and computer configuration.

My goal in teaching you some basics about the command line is so that you can explore it at your own pace in this class and see that it's not so scary to get around and run basic commands. In the professional world, I'm worked with both GUI (Graphical User Interface) tools and CLI (Command Line Interface) tools at the same time.

Command line programs

Example: Ping program

Command line programs take this form: PROGRAM OPTIONS
The program name always comes first, and then zero, one, or more options follow. For example, the ping command is used to send data-packets to a web address you provide, and is often used to test to see if your computer is online, or the intended URL is online.

ping google.com -i 5
This command means the following:

  1. Run the ping program
  2. Send packets to google.com
  3. Only send packets every 5 seconds (the -i stands for "intervals")

Command line programs

Example: g++

The g++ program is a C++ compiler, which allows us to turn our C++ source code into an executable program.

g++ test.cpp -o MyProgram.exe
This command means the following:

  1. Run the g++ program
  2. Build the test.cpp file
  3. Set a custom program name MyProgram.exe (-o stands for "output")

After building the program, I then run ./MyProgram.exe to start my program.

Command line programs

Navigating folders with the command line

When you're browsing a folder on your computer, you can open up the terminal from that directory. You can see the same files from the command line as well.

  • ls - (lower case L and S) - This command LISTS the files and folders where you are currently at.
    • You can use ls by itself for a simple list,
    • Or you can use ls -l for a more detailed list

Command line programs

Navigating folders with the command line

When you're browsing a folder on your computer, you can open up the terminal from that directory. You can see the same files from the command line as well.

  • cd FOLDERNAME - This is the Change Directory command, you can move between folders with this.
    • cd FOLDERNAME will move you deeper into a folder.
    • cd ../ is like the "up" arrow in your file browser, it will move you BACK OUT one folder.

Reference sheet

CLI commandWhat it does
cd FOLDERNAMEChange Directory into the FOLDERNAME given.
cd ../Move back or "out" one folder.
lsView a simple list of files and folders in this directory.
g++ FILENAME.cppBuild a C++ file into an executable (a.out or a.exe is the default name).
g++ FILENAME.cpp -o PROGRAM.exeBuild a C++ file into an executable with the given PROGRAM name.
./PROGRAM.exeRun the program.