Your first folder in the terminal
You can find a file in a window. This time you need to give someone a sequence of actions that they can repeat without screenshots. A shell reads text commands and runs a program or a built-in operation. The terminal is the window through which you talk to it. An operation can finish without printing anything. You can check the result with a separate command.
Where an action will start
In your file manager create a new empty WorkshopShell folder inside a suitable personal location. If that name exists, choose a fresh one. You will create small practice files here. Some commands below replace a file that already has the chosen name. Check the location before you begin and run one line at a time.
On Windows open a PowerShell terminal in the folder. Some versions offer Open in Terminal in the folder context menu. Check that the active tab really is PowerShell. On macOS open Terminal and on Linux use your desktop’s terminal. If it opens elsewhere, type cd followed by a space, drag your practice folder from the file manager into the terminal, then press Enter. If dragging is unavailable, put the absolute path in quotes after cd. Check the result with the first command of your block below. When sharing your notes, you can replace the part that identifies your personal account with the name WorkshopShell.
Two quick experiments
First find out where you are. Get-Location reports this in PowerShell and pwd does so in a macOS or Linux shell. Compare the last part with the folder’s name in the file manager. The next command lists the contents. An empty list is a reasonable result for an empty folder. If you see everyday documents or photographs, stop and locate the fresh practice folder before continuing.
Use the first steps in your block to create source and archive. Enter cd source and check your location again. Then use cd .. to return to its parent and verify the location once more. You have just tested the starting point for a relative path. A command writing to source/note.txt expects source to exist inside the current folder. If you are already inside source it looks for another folder beneath it. Check your location before trying to fix a missing path.
Read the command before running it
BLUE and GREEN are lines of text. The copy operation makes an independent file holding what existed at the time of the copy. A later command adds a line to the original. In the macOS and Linux shell a single > writes the command’s output into a new or replacement file. A double >> appends it. PowerShell uses Set-Content to set contents and Add-Content to append. Before you press Enter, say which path will change and what you expect to find there.
Choose the block for your shell. If you already created the folders, resume at the line that writes BLUE. Run each line separately and watch which file receives the second line of text.
Get-Location
Get-ChildItem
New-Item -ItemType Directory -Name source
New-Item -ItemType Directory -Name archive
Set-Content -LiteralPath source/note.txt -Value 'BLUE'
Copy-Item -LiteralPath source/note.txt -Destination archive/note.txt
Add-Content -LiteralPath source/note.txt -Value 'GREEN'
Get-Content -LiteralPath source/note.txt
Get-Content -LiteralPath archive/note.txt
Get-ChildItem -Recurse -File -Filter note.txt | Select-Object -ExpandProperty FullName
Get-ChildItem -Recurse -File -Filter note.txt | Select-Object -ExpandProperty FullName | Out-File paths.txt
Get-Content -LiteralPath paths.txt
pwd
ls
mkdir source archive
printf '%s\n' BLUE > source/note.txt
cp source/note.txt archive/note.txt
printf '%s\n' GREEN >> source/note.txt
cat source/note.txt
cat archive/note.txt
find . -type f -name note.txt
find . -type f -name note.txt > paths.txt
cat paths.txt
Practice. Deliver a folder someone can check
Before reading either note, predict which file contains one line and which contains two. Run both read commands. If the original contains only GREEN, check which operation you used for the second write. The discrepancy is evidence about the operation. Keep your first results and use a fresh directory name if you wish to repeat the experiment.
The search covers the current folder and its descendants. Two paths should end in source/note.txt and archive/note.txt. Their order can differ. The last write saves the list in paths.txt. Find that file in your file manager and open it as text. PowerShell prints full paths, while the find example starts them with a dot for the current directory. Record both relative paths and the commands you used to verify the contents. If there are three matches, identify the extra location and check whether the folder really was empty before the exercise.
Check your work
With the terminal closed, can another reader point to the file that existed before the append and identify the command that separated the copy? Next search for missing.txt without creating it: change the name only in the search command that prints to the screen. Expect an empty list. Empty output from a search in the correct directory differs from an error saying the path cannot be opened. Your completed handover includes both notes, paths.txt and a short record of the actions that produced them.
Microsoft’s Copy-Item documentation · GNU basic file utilities
Where to put a check
Change the conditions and observe this training model. It runs in your browser and does not change your computer.
A team is preparing a release. Enable the independent checks and see what remains unknown.
Choose conditions above to see an explanation of the result.
Independent exercise
A pupil kept a terminal transcript, but it begins halfway through the exercise.
Evidence
Current folder: WorkshopShell/archive Visible entry: note.txt Suggested relative path: source/note.txt
Assignment
Draw the location addressed by the suggested path. Which single change of directory restores the expected starting point?
Compare your reasoning
From archive it seeks archive/source/note.txt. Use cd .. to enter the parent, verify the current path, and source/note.txt will address the intended branch.
Personal practice environment
Check an excerpt, find matching lines and compute the SHA-256 of the original text. Temporary data expires after 30 minutes or when you close the environment.
Sign in