• Home
  • About
  • Schedule
  • Sessions
  • Exercises
  • Code of Conduct

Contents

  • This session
  • Learning objectives
  • recipes project
  • Exercises
    • Navigate the file system
    • Create files and folders
  • 🚀 Bonus exercises
    • Writing and opening files
    • Creating multiple files
    • Wildcards
    • Combining commands
  • Slides
  • Cheatsheet

Solutions

Session 2

Starts at:

10:15

Slides Chapter

This session

In this session, you will work on the following tasks:

  1. Reading: Read the chapter(s) ?meta:chapter in the Version Control Book.
  2. Implementation: Try out the commands in the chapter.
  3. Exercises: Work on the exercises for the recipes project.

As always:

  1. Try out the commands of this session and play around with them.
  2. Check whether you have achieved the learning objectives.
  3. Ask questions!
  4. Let’s git started!

Learning objectives

At the end of this session, you should have achieved the following learning objectives:

💡 You can name the advantages of command-line interfaces for Git.
💡 You can navigate directories using absolute and relative paths.
💡 You can use shortcuts like the tilde or dots to navigate your file system.
💡 You can apply arguments and flags to customize command-line commands.
💡 You can use wildcards (*) for file selection.
💡 You can combine command-line commands.

recipes project

At the end of this session, you should have accomplished the following:

  1. You used the command line to create a folder on your computer called recipes.
  2. You used the command line to create a file called recipes.txt inside the recipes folder.

Please keep the recipes folder! We will continue to use it in the following sessions.

Exercises

Navigate the file system

Identify a folder on your computer where you (want to) keep course-related files. If you don’t have one, choose a suitable location in your file system.

  1. Navigate into the chosen location using the command line.
  2. Use the command line to display the path of your chosen folder. What is the output?

Create files and folders

  1. Within your chosen folder, create a new subfolder called recipes.
  2. Navigate into the recipes folder.
  3. Create a new text file called recipes.txt.
  4. Confirm that the file was created by listing the contents of the folder.
  5. Add the title “My Favorite Recipes” to recipes.txt. Which command or method did you use?

🚀 Bonus exercises

Writing and opening files

Add a first recipe to recipes.txt. Include at least a title and a short list of ingredients. Which command or method did you use?

Creating multiple files

Go back to your main course-related folder. Using the command line, create three new files: notes.txt, assignments.txt, and schedule.txt. Provide the command you used.

Wildcards

Use a wildcard pattern to list all .txt files in your folder. Which command did you use?

Combining commands

Imagine, that you are in a folder containing multiple text files with various extensions, including .txt, .md, and .docx. You want to move all the .txt files to a subfolder named text_files while keeping the other file types in the current directory. Write a series of command-line commands to accomplish this task, including creating the text_files subdirectory. Explain each step in your solution.

Slides

NoteHow can I download the slides as a PDF file?

To export the slides to PDF, do the following:

  1. Toggle into Print View using the E key (or using the Navigation Menu).
  2. Open the in-browser print dialog (CTRL/CMD+P).
  3. Change the Destination setting to Save as PDF.
  4. Change the Layout to Landscape.
  5. Change the Margins to None.
  6. Enable the Background graphics option.
  7. Click Save.

Note: This feature has been confirmed to work in Google Chrome, Chromium as well as in Firefox.

These instructions were copied from the Quarto documentation (MIT License) and slightly modified.

Cheatsheet

Command Description
pwd Displays the path of the current working directory
cd <PATH> Changes the current working directory to <PATH>
cd ~ Changes the current working directory to the user’s home directory
cd .. Moves up one folder
cd ../.. Moves up two folders
clear Clears the contents of your command line window
ls Lists files and folders in the current working directory
ls <PATH> Lists files and folders in <PATH>
ls -a Lists all files (including hidden files) in the current working directory
ls -alh Lists all files in a long format that is easy to read for humans
[Command] --help Displays all possible flags for a specific command (on Windows)
man [Command] Displays all possible flags for a specific command (on macOS)
mkdir <FOLDER> Creates a new folder called <FOLDER>
mkdir <FOLDER1> <FOLDER2> Creates two separate folders called <FOLDER1> and <FOLDER2>
touch <FILE> Creates a new empty file called <FILE>
open <FILE> Opens the file called <FILE> (on macOS)
start <FILE> Opens the file called <FILE> (on Windows)
echo "example text" >> file.txt Writes “example text” into file.txt
cat <FILE> Displays the content of <FILE>
mv FILE.txt <FOLDER> Move FILE.txt into <FOLDER>
mv <FOLDER_OLD> <FOLDER_NEW> Renames <FOLDER_OLD> to <FOLDER_NEW>
ls -alh *.csv Uses a wildcard to list all .csv files in the current working directory
rm -r <FOLDER> Removes the folder <FOLDER>
history Display the command history of the current terminal session
history > history.txt Saves the entire command history to a file named history.txt (overwrites existing content in history.txt)
history >> history.txt Adds the entire command history to the end of the file named history.txt
tree Displays a graphical representation of the directory structure
wget <URL> Downloads a file from the specified to the current directory
TipSolution: Navigation and setup

For folder navigation, use cd. To display the contents of a folder, use ls. To display the path of the current working directory, use pwd.

For example, on macOS if you navigated to the Documents folder and used pwd, the path looks like this:

/Users/myusername/Documents
TipSolution: Creating a folder and a file
  1. Create a folder called recipes:
mkdir recipes
  1. Navigate into the recipes folder:
cd recipes
  1. Create a file and name it recipes.txt:
touch recipes.txt
  1. List the contents of the recipes folder:
ls
TipSolution: Writing and opening files

I added the title to recipes.txt by using the following command:

echo "My Favorite Recipes" > recipes.txt

This command writes “My Favorite Recipes” to the file, overwriting any existing content.

TipSolution: Creating multiple files
touch notes.txt assignments.txt schedule.txt
TipSolution: Wildcards
ls *.txt
TipSolution: Bonus question
  1. Creating the “text_files” subfolder:
mkdir text_files
  1. Moving all the .txt files to the “text_files” subfolder:
mv *.txt text_files

© 2026 Dr. Lennart Wittkuhn

 

License: CC BY 4.0