Exercise 0.1: Where Am I and What’s Here?
Your First Navigation Commands
Purpose
Before you can work with files or navigate your computer, you need to know two things: Where am I? and What’s around me? This exercise introduces the two most fundamental commands for orienting yourself in the command-line environment: pwd (print working directory) and ls (list contents).
What You’ll Accomplish
By the end of this exercise, you will have successfully:
- Used the command line to identify your current directory.
- Listed the files and folders in your current directory.
- Understood the basic differences in these commands between operating systems.
The Present Working Directory
Your present working directory (or “current directory”) is the folder that your terminal is currently “in.” Any commands you run will, by default, happen in this location. When you first open a terminal, you typically start in your home directory.
Your Task 1: Find Out Where You Are
Run the command below that corresponds to your operating system to see the full path of your current directory.
In macOS and Linux, the command is pwd.
pwdExample Output: /home/username or /Users/username
In PowerShell, the command is Get-Location. You can also use the built-in alias pwd.
Get-LocationExample Output: C:\Users\Username
In the classic Command Prompt, running the cd command without any arguments will print the current directory.
cdExample Output: C:\Users\Username
Listing Directory Contents
Now that you know where you are, you need to see what’s in that directory. This command lists all the files and subdirectories in your present working directory.
Your Task 2: See What’s Around You
Run the command for your operating system to list the contents of your current directory.
The command is ls (short for “list”).
lsTo see more details, like file sizes and modification dates, use the -l (long format) flag:
ls -lThe official command is Get-ChildItem, but it has convenient built-in aliases ls and dir that work the same way.
lsIn Command Prompt, the command is dir.
dirVerification
To connect what you’re seeing in the terminal to what you already know, open your graphical file explorer (Finder on macOS, File Explorer on Windows, Files on Linux). Navigate to your home folder.
Do you see the same files and folders listed in the terminal output? This is the connection between the command-line world and the graphical world. They are just two different ways of looking at the same file system.
Reflect and Review
In your Microsoft Teams Student Notebook, answer the following:
- What was the full path to your home directory that the
pwd(or equivalent) command showed you? - List three folders you saw when you ran the
ls(ordir) command. - Why is it useful to know your present working directory before you run a command?