Step 1: Find your way around in the terminal
AI coding tools, notebooks and servers all end up in a terminal: a
text window where you type a command, press Enter and read what it
prints. Open the terminal tab (it starts in your home folder, ~).
CHEATSHEET.md lists every command this lab uses.
The folder shelfbot/ holds Brightline's small stock tools: a price
module, a stock loader, a report script, tests and a CSV of books.
1. Look around. Try each of these and read the output:
pwd # where you are
ls # what is here
cd shelfbot # go into the folder
ls -la # everything, including hidden files
head -n 4 data/stock.csv # the first lines of the stock list
wc -l data/stock.csv # how many lines it has
grep -rn "def line_total" . # which file defines line_total?
2. Run the report and keep its output. Still inside shelfbot/:
mkdir out
python3 report.py > out/report.txt
> sends what a command prints into a file instead of the screen. Open
out/report.txt with cat to see it.
3. Answer the questions below using the commands, then click Check.
CHEATSHEET.md, the file you edit27 lines
# Terminal and git cheatsheet
## Moving around
pwd where am I?
ls what is here? (ls -la shows hidden files too)
cd shelfbot go into a folder cd .. go up one cd ~ go home
cat file.txt print a file head -n 5 file.txt the first 5 lines
wc -l file.txt count lines
grep -rn "word" . search every file below here for "word", with line numbers
mkdir out make a folder mv a.txt out/ move a file
python3 report.py > report.txt run a script and save what it prints
## git
git init start tracking this folder
git status what changed since the last commit?
git add <file> / git add . stage changes for the next commit
git commit -m "message" save a snapshot
git log --oneline the history, newest first
git diff what changed, line by line (unstaged)
git diff --stat which files changed, and how much
git restore <file> throw away uncommitted changes to a file
git restore --source=HEAD <file> bring back a file deleted since the last commit
git revert HEAD a NEW commit that undoes the last one
git show HEAD what the last commit changed
In the diff: lines starting with - were removed, lines starting with + were added.
Press q to leave a long git log or diff.ai_edit.pyshelfbot/README.mdshelfbot/data/stock.csvshelfbot/pricing.pyshelfbot/report.pyshelfbot/stock.pyshelfbot/tests/__init__.pyshelfbot/tests/test_pricing.pyshelfbot/tests/test_stock.py