Skip to main content

Foundations of Python Programming: Functions First

Section 14.1 The Command Line

The command line, or CLI, is a powerful tool that provides direct access to the core functionalities of your operating system. While graphical interfaces are widely used, understanding the command line and its basic usage is essential for quickly navigating file systems, managing source control, and running programs.

Subsection 14.1.1 GitBash

For this section, GitBash will be used as the command line interface. GitBash is a command line interface that is included with Git for Windows. It is a Bash shell emulator that provides a Linux-like CLI environment on Windows. GitBash can be downloaded from https://gitforwindows.org/ 1  .
Once GitBash is installed, it can be opened through a shortcut, or by right-clicking in a folder and selecting Git Bash Here.
GitBash will open in the current directory. The command line prompt will be displayed, followed by the current directory. The prompt will be different depending on the operating system. For Windows, the prompt will be $. For Linux and Mac, the prompt will be %.

Subsection 14.1.2 Commands

Command lines allow users to interact with the operating system by entering commands. Commands are entered into the command line, and then executed by pressing the Enter key. Commands can be entered one at a time, or multiple commands can be entered on the same line by separating them with a semicolon.

Subsection 14.1.2.1 Navigation Commands

Arguably the most important command is cd, which is used to change directories. Directories are the folders that contain files. The current directory is displayed in the command line prompt. To change directories, enter cd followed by the name of the directory. For example, to change to the src directory, enter cd src.
In order to navigate into a parent directory - that is, the directory that contains the current directory - use cd ... For example, if the current directory is src, then cd .. will change to the parent directory.
Next, the ls command is used to list the contents of the current directory. This command will list the files and directories in the current directory. For example, if the current directory contains the files main.py and README.md, then ls will list these files. Folders, when listed, will not have a file extension, and instead will be followed by a forward slash. For example, if the current directory contains the folder src, then ls will list src/.

Subsection 14.1.2.2 File and Directory Commands

To create a new directory, use the mkdir command. For example, to create a new directory named src, enter mkdir src .
To create a new file, use the touch command. For example, to create a new file named main.py, enter touch main.py .
To remove a file, use the rm command. For example, to remove the file main.py, enter rm main.py. Be warned, this command will permanently delete the file.

Checkpoint 14.1.1.

Using the following file structure, move into the src directory, remove main.py, add the file not_main.py, and return to the home directory:
home/ src/ main.py README.md test/ test_main.py README.md plans/ whatever.txt old.txt
You have attempted of activities on this page.