Skip to content
Ameen Abozaid
BEG-006

Command line

  • 8 Lessons
  • 88 min of reading
  • 3 h practice (estimate)
On this page 8 topics

Overview

Topics

  • Terminal
  • shell
  • directories
  • file commands
  • paths
  • permissions
  • environment variables
  • pipes
  • redirection
  • basic Bash/PowerShell

Learn first

88 min of reading · 3 h of practice (estimate)

Learning outcomes

  1. Navigate directories with absolute and relative paths (pwd, cd, ls/dir).
  2. Create, copy, move, and delete files and folders from the terminal.
  3. Use pipes and redirection to filter output and save it to a file.
  4. Read and set an environment variable for the current session in Bash and PowerShell.
  5. Explain file permissions at a basic level and why a script may fail to execute.

Lessons

  1. 01Terminal, shell, and prompt12 min read
  2. 02Paths: absolute, relative, home, . and ..11 min read
  3. 03Working with files and folders10 min read
  4. 04Pipes and redirection10 min read
  5. 05Environment variables in the shell11 min read
  6. 06Permissions basics12 min read
  7. 07Bash vs PowerShell cheat sheet11 min read
  8. 08Demo: setting up a project folder using only the terminal11 min read

Lab and exercises

Lab

BEG-006-LAB1 · Terminal-only project setup

Outcomes: 1–5 · Time: ~2 h Using only the terminal: create a project folder structure, create files, list them sorted by size, save the listing to a file, and search it for a word. Acceptance: a command history file plus the final folder tree.

Exercises

IDOutcomeTask
BEG-006-EX011From your home folder, go into Documents, then back up two levels using relative paths.
BEG-006-EX021Print your current folder, then the same location as an absolute path.
BEG-006-EX032Create a/b/c, create a file in c, copy it to b, move the original to a.
BEG-006-EX042Delete the whole a folder you made, after checking where you are.
BEG-006-EX053Save a folder listing to list.txt and show only the lines containing a chosen word.
BEG-006-EX064Set a variable COURSE=java for this session and print it.
BEG-006-EX075Make a script file executable and run it. What happens before and after?
Show solutions
  • EX01 cd Documents then cd ../...
  • EX02 pwd (Bash) or Get-Location (PowerShell).
  • EX03 mkdir -p a/b/c; touch a/b/c/f.txt; cp a/b/c/f.txt a/b; mv a/b/c/f.txt a.
  • EX04 pwd first, then rm -r a.
  • EX05 ls > list.txt then grep word list.txt.
  • EX06 export COURSE=java; echo $COURSE (PowerShell: $env:COURSE = "java"; $env:COURSE).
  • EX07 Before: "Permission denied". After chmod +x script.sh: it runs.

Quiz

Outcomes: O1 paths · O2 files · O3 pipes · O4 variables · O5 permissions.

A self-check for you: nothing is graded, saved or sent anywhere. Choose an answer, then check it. You can try again as often as you like.

  1. 1cd .. moves you to:O1
  2. 2An absolute path:O1
  3. 3pwd shows:O1
  4. 4Which command copies a file in Bash?O2
  5. 5Deleting from the terminal:O2
  6. 6> does what?O3
  7. 7| (pipe) does what?O3
  8. 8Which sets a variable for the current session in Bash?O4
  9. 9In PowerShell, you read variable X with:O4
  10. 10"Permission denied" when running a script usually means:O5

Practical part

Timed terminal task: 10 commands (navigate, create, copy, move, redirect, filter, set a variable) with no GUI use, 15 minutes. Pass: at least 8 of 10 correct.

Common mistakes

Spaces in paths without quotes; running rm/del without checking the current directory; mixing Bash and PowerShell syntax.

Assessment

Timed terminal task (10 commands) with no GUI use.

Career relevance

Daily tool from here on; deepened in JNR-048.

Type to search levels, phases, modules and lessons.