Command Line
Objectives
💡 You can name the advantages of command-line interfaces.
💡 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.
Tasks
In this session, you will work on the following tasks:
- Reading: Read the chapter(s) Command Line in the Version Control Book.
- Implementation: Try out the commands in the chapter.
- Exercises: Work on the exercises.
As always:
- Try out the commands of this session and play around with them.
- Check whether you have achieved the learning objectives.
- Ask questions!
Exercises
Use only command line commands for all tasks.
Exercise 1: Set up your research workspace
- Navigate to a folder where you want to keep course-related files and display its path.
- Create a new directory called
my-research-project. - Navigate into this directory and confirm your location.
Exercise 2: Create project structure
- Create three subdirectories inside your research project:
data,scripts, anddocs. - List all contents and verify the directories were created.
- Navigate into the
docsdirectory.
Exercise 3: Create project documentation
- While in the
docsdirectory, create a file calledREADME.md. - Add the text “# My Research Project” to this file.
- List the directory contents and confirm the file was created.
Exercise 4: Set up data organization
- Navigate to the
datadirectory. - Create two subdirectories:
rawandprocessed. - Navigate to the
rawdirectory and create three sample data files:experiment1.csv,experiment2.csv, andsurvey.txt.
Exercise 5: Add project metadata
- Navigate back to your main project directory.
- Create three files:
project-notes.txt,todo-list.md, andreferences.bib. - Use wildcards to list only the
.txtfiles in your project.
Exercise 6: Organize and clean up
- Create a new directory called
archive. - Move all
.txtfiles from your main project directory into thearchivedirectory. - Display the full directory tree of your project and see the final structure.
Slides
To export the slides to PDF, do the following:
- Toggle into Print View using the E key (or using the Navigation Menu).
- Open the in-browser print dialog (CTRL/CMD+P).
- Change the Destination setting to Save as PDF.
- Change the Layout to Landscape.
- Change the Margins to None.
- Enable the Background graphics option.
- Click Save.
Note: This feature has been confirmed to work in Google Chrome, Chromium as well as in Firefox.
Here’s what the Chrome print dialog would look like with these settings enabled:
These instructions were copied from the Quarto documentation (MIT License) and slightly modified.
Solutions
Exercise 1: Set up your research workspace
- Navigate to your home directory and display its path:
cd ~
pwd- Create a new directory called
my-research-project:
mkdir my-research-project- Navigate into this directory and confirm your location:
cd my-research-project
pwdExercise 2: Create project structure
- Inside your research project, create three subdirectories:
data,scripts, anddocs:
mkdir data scripts docs- List all contents to verify the directories were created:
ls- Navigate into the
docsdirectory:
cd docsExercise 3: Create project documentation
- In the
docsdirectory, create a file calledREADME.md:
touch README.md- Add the text “# My Research Project” to this file:
echo "# My Research Project" > README.md- List the directory contents to confirm the file was created:
lsExercise 4: Set up data organization
- Navigate to the
datadirectory:
cd ../data- Create two subdirectories:
rawandprocessed:
mkdir raw processed- In the
rawdirectory, create three sample data files:experiment1.csv,experiment2.csv, andsurvey.txt:
touch experiment1.csv experiment2.csv survey.txtExercise 5: Add project metadata
- Navigate back to your main project directory:
cd ../../- Create three files:
project-notes.txt,todo-list.md, andreferences.bib:
touch project-notes.txt todo-list.md references.bib- Use wildcards to list only the
.txtfiles in your project:
ls *.txtExercise 6: Organize and clean up
- Create a new directory called
archive:
mkdir archive- Move all
.txtfiles from your main project directory into thearchivedirectory:
mv *.txt archive/- Display the full directory tree of your project to see the final structure:
tree
# or if tree is not installed:
ls -R