Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Chapter 1: The Command Line

Navigate, inspect, and run a project safely

The terminal is a text interface to your computer. In COMP 521 you will use it for a small, repeatable set of tasks: enter a project directory, activate an environment, run code, and use Git. You do not need to memorize a catalog of commands.

Before you begin

Open the course terminal

macOS
Linux
Windows

Open Terminal from Applications → Utilities, or search for it with Command + Space.

Terminal, shell, and prompt

A command usually has this shape:

command  option  argument
ls       -la     project

Here ls is the action, -la changes how it behaves, and project is the target. Type only the command—not the explanatory prompt characters shown in some documentation.

Your navigation loop

These three commands answer the questions you will ask most often.

Where am I? — pwd

pwd

pwd prints the full path to your current directory.

What is here? — ls

ls
ls -la

ls lists visible files. ls -la adds hidden files and details. A name beginning with ., such as .gitignore, is hidden by convention.

How do I move? — cd

cd Documents
cd ..
cd ~

Directory names are case-sensitive in the course examples. Use Tab completion instead of retyping a long path: type its first few characters, then press Tab.

Paths: directions to a file

An absolute path starts at the filesystem root and identifies one location:

/Users/yourname/Documents/comp521/project-1

A relative path starts from your current directory:

project-1/analysis.ipynb

Useful path symbols are:

SymbolMeaning
~your home directory
.the current directory
..the parent directory
-the previous directory when used as cd -

Paths containing spaces need quotes:

cd "My Projects"

For course work, prefer simple directory names such as comp521 and project-1.

Create, inspect, copy, and move

Make a harmless practice workspace:

cd ~
mkdir comp521_cli_practice
cd comp521_cli_practice
touch notes.txt
ls -la

Now inspect and rename the file:

cat notes.txt
cp notes.txt notes-backup.txt
mv notes.txt observations.txt
ls -la
CommandPurpose
mkdir directorycreate a directory
touch filecreate an empty file, or update its timestamp
cat fileprint a short text file
cp source targetcopy a file
mv source targetmove or rename a file

Use less file.txt for a long text file; press q to quit. Use head file.txt or tail file.txt to inspect its beginning or end.

Remove only what you have identified

rm -i observations.txt
rmdir an_empty_directory

rm -i asks before removing each file. rmdir removes only an empty directory, so it is the right teaching tool for an empty-directory example.

Find files and text

You do not need to click through every directory to locate something:

find . -name "*.py"
grep -n "flux" analysis.py
grep -r -n "TODO" .

The * is a wildcard: it matches multiple characters. Quote the pattern in the find command so the shell does not expand it too early.

Run Python from the project directory

After you create the course environment in Chapter 2, the usual loop is:

cd path/to/your/project
conda activate comp521
which python
python -c "import sys; print(sys.executable)"
python script.py

In Git Bash or another Bash-compatible shell, which python may print a path under Miniforge. The Python command reports the same interpreter using Python itself and works across shells. On all platforms, the important observation is that the active Python belongs to the comp521 environment.

Use Ctrl + C to interrupt a running command. This asks the program to stop; it does not undo work the program already completed.

Read errors before changing anything

MessageWhat it establishesFirst evidence to collect
command not foundThis shell could not locate that executable.Check spelling, installation, echo $PATH, and the active environment.
No such file or directoryThe path given does not resolve here.Run pwd and ls; inspect one path component at a time.
Permission deniedThe requested action is not allowed for this user or file.Run ls -l and ask for help; do not add sudo as a guess.
Python tracebackPython reports the call path and final exception.Save the complete traceback and read the final line first.

A fresh terminal starts a fresh shell session. It can reset session state such as the active conda environment, but it does not undo commands or restore files.

Keyboard shortcuts worth learning

KeyEffect
Tabcomplete a file or command name
↑ / ↓move through command history
Ctrl + Cinterrupt the current command
Ctrl + A / Ctrl + Emove to the beginning/end of the line
Ctrl + Lclear the visible terminal

Optional: combine small commands

A pipe sends one command’s output to the next:

ls -la | grep -E '\.ipynb$'

Redirection saves output:

python script.py > output.txt

> replaces the target file; >> appends. Inspect the target name before using either. These are reference skills, not prerequisites for P1 readiness.

Proof task

Without using Finder or File Explorer:

  1. Go to your home directory.

  2. Create comp521_cli_practice/project-1.

  3. Enter project-1 and confirm its absolute path.

  4. Create notes.txt, copy it to notes-backup.txt, and list both files.

  5. Return to your home directory using one command.

Keep the practice directory; you can revisit it without deleting anything.