Session 2: Basics of the Command Line

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

Course at Max Planck Institute for Human Development

Slides | Source

License: CC BY 4.0 DOI

10:00

1 Logistics & Admin

Schedule

No Time Title Contents Reading Survey/Quiz
1 9:30 - 10:00 Welcome & Introduction to Version Control Logistics and course admin
Results of course survey
Introduction to Version Control
Introduction to Git
Introduction to Version Control Course survey
2 10:00 - 11:00 Basics of the Command Line File systems and navigation
Benefits of the command line
Basic command line commands
Command Line Command Line Quiz
3 11:00 - 12:00 Setup & First steps with Git Configuration and setup of Git
Initializing a Git repository
Fundamental Git commands
Setup, First steps with Git Git Basics Quiz
4 12:00 - 13:00 Branches, Merging & Merge Conflicts Understanding branches in Git
Creating and switching between branches
Merging branches
Resolving merge conflicts
Branches Git Branches Quiz
5 13:00 - 14:00 Lunch Break Enjoy your lunch!
6 14:00 - 15:00 Integration with GitLab / GitHub Introduction to remote repositories
Creating and managing repositories on GitLab / GitHub
Pushing and pulling changes
Cloning a remote repository
GitHub Intro GitHub Quiz
7 15:00 - 16:00 Collaboration on GitLab / GitHub Forkinga repository
Collaboration with GitHub Flow
Pull / Merge Requests
Issues
README files
GitHub Advanced, GitHub Issues GitHub Quiz
8 16:00 - 16:30 Summary & Outlook Summary of course contents
Outlook to more Git topics
Discussing open questions

Course exercise: Building an online recipes book

https://lennartwittkuhn.com/recipes

2 Basics of the Command Line

This session: 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

https://lennartwittkuhn.com/version-control-book/chapters/command-line.html

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
history >> history.txt Adds the entire command history to the end of the file named history.txt

Tasks

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

  1. Reading: Read the chapter “Command Line” in the Version Control Book.
  2. Implementation: Try out the commands in the chapter.
  3. Exercises: Work on the exercises for the recipes 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!

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

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. Navigate into the chosen location using the command line. Use the command line to display the path of your chosen directory. What is the output?

Creating a folder and a file

Within your chosen folder, create a new subfolder and name it recipes. Navigate into the recipes folder. Create a new file and name it recipes.txt. Confirm the creation of the file by listing the contents of the recipes folder. Which commands did you use?

Writing and opening files

Add the title “My Favorite Recipes” to recipes.txt. 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?

Bonus question

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.