Session 2: Basics of the Command Line

Track, organize and share your work: An introduction to Git for research

Course at University of Hamburg & Erasmus University Rotterdam

Slides | Source

License: CC BY 4.0 DOI

October 25 2024 (10:15 am)

1 Logistics & Admin

Schedule

No Date Title Contents Reading Survey/Quiz
1 2024-10-18 Introduction to version control Organizational matters
Overview of seminar sessions
Introduction to version control
Introduction to Git and its advantages
Intro to version control Course introduction Survey
2 2024-10-25 Command line File Systems
Benefits of the Command Line
Basic Command Line commands
Command Line Command Line Quiz
3 2024-11-01 Setup + Git Fundamentals Installation and configuration of Git
Initializing a Git repository
Basic Git commands
Installation, Setup, First steps with Git Installation Survey, Git Basics Quiz
4 2024-11-08 Basic Git workflow Practicing basic Git commands
Ignoring files with .gitignore
Good commit messages
First steps with Git Git Basics Quiz
5 2024-11-15 Git Essentials (Repetition & Practice) Practicing basic Git commands
Ignoring files with .gitignore
Good commit messages
Git Essentials Git Basics Quiz
6 2024-11-22 Git Branching and Merging Understanding branches in Git
Creating and switching between branches
Merging branches
Resolving merge conflict
Branches Git Branches Quiz
7 2024-11-29 Quarto Workshop Introduction to Quarto
8 2024-11-06 Introduction to GitHub Introduction to remote repositories
Creating a GitHub account
Creating and managing repositories on GitHub
Pushing and pulling changes
GitHub Intro GitHub Quiz
9 2024-12-13 GitHub with collaborators Cloning a remote repository
Branching and merging in a collaborative environment
Pull Requests
GitHub Issues
Graphical User Interfaces (GUIs), e.g., GitKraken
GitHub Intro, GitHub Issues GitHub Quiz
10 2024-12-20 Repetition and Practice Repetition and Practice
11 2025-01-10 GitHub with the world Forking a remote repository
README files
Project Management
GitHub Intro, GitHub Issues GitHub Quiz
12 2025-01-17 Publishing Creating Tags with Git
Creating Releases with GitHub
Using Zenodo for scientific publishing
Licences
Citation Files
Tags and Releases
13 2025-01-24 Graphical User Interfaces Repetition and Practice
Introduction to using GUIs
Graphical User Interfaces
14 2025-01-31 Summary & Wrap-Up Course evaluation
Repetition and Practice
Introduction to using GUIs
Graphical User Interfaces

2 Last session

Last week’s learning objectives

After the last session, you should now be able to answer the following questions:

💡 You know what version control is.
💡 You can argue why version control is useful (for research).
💡 You can name benefits of Git compared to other approaches to version control.
💡 You can explain the difference between Git and GitHub.

Any questions?

Homework

1. Check if you have Git / a command line installed

Windows Users

Apple or Linux Users

3 Basics of the Command Line

Pair Programming (variant)

  • We will assign you to Zoom breakout rooms
  • Introduce yourself to your partner (see conversation starters on later slide)
  • Complete the exercises together
  • Help each other out
  • Lennart and Reza will move between breakout rooms to offer help
  • Send a message in the chat to Lennart or Reza if you need help
  • We will meet again in the main room about 10 minutes before the end of the session to discuss any remaining questions in the group.

This illustration is created by Scriberia with The Turing Way community. Used under a CC-BY 4.0 licence. DOI: 10.5281/zenodo.3332807

Course exercise: Building an online city-guide book

https://lennartwittkuhn.com/uhh-eur-city-guide/

This session: Basics of the Command Line

Source: Wikimedia Commons (free license)

Learning objectives

💡 You can navigate directories using the command line.
💡 You can use shortcuts like the tilde or dots to navigate your file system.
💡 You can explain the difference between absolute and relative paths.
💡 You can use arguments and flags to modify command-line commands.
💡 You understand the concept of wild cards (*) and can use it for system navigation.

Reading

Command Line

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

Tasks

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

  1. Reading: Read the chapter(s) Command Line in the Version Control Book.
  2. Implementation: Try out the commands in the chapter.
  3. Exercises: Work on the exercises for the city-guide project.
  4. Quiz: Test your knowledge with the quiz.

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!

city-guide 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 city-guide.
  2. You used the command line to create a file called city-guide.txt inside the city-guide folder.

Please keep the city-guide folder! We will continue to use it in the following sessions.

Conversation starter

  1. Your name?
  2. Are you based in Hamburg or Rotterdam?
  3. A (fun) fact about you? For example:
    • What did you study before and where?
    • What do you expect from this course?
    • What’s your hobby?
    • Do you have a pet?
    • What’s your favorite color?
    • Your mood on sheep scale?

Mood on a sheep scale.

Exercises

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 and give it a relevant name.
  2. Navigate into the newly created subfolder.
  3. Create a new text file and name it appropriately.
  4. Confirm that the files was created by listing the contents of the folder.

Solutions

Code
cd /path/to/your/chosen/directory # <1>
  1. Navigate into the chosen location. Replace /path/to/your/chosen/directory with a path on your computer. A good location might be within your /Documents folder or a dedicated /Projects or /University folder. This can help to easily find course-related files on your computer.

Create files and folders

Code
#!/bin/bash

pwd # <2>
mkdir city-guide # <3>
cd city-guide # <4>
touch city-guide.txt # <5>
ls # <6>
  1. Use pwd to display the path of your current working directory.
  2. Use mkdir to create a new subfolder and give it a name, within your chosen folder.
  3. Use cd to navigate into the newly created subfolder.
  4. Use touch to create a new file and name it appropriately.
  5. Use ls to confirm that the files was created by listing the contents of the folder.