The Shell: Practice Questions
For each snippet, write the output of its final command. If it prints nothing, write “No Output”.
Each snippet starts in a new, empty directory.
Question 1
echo 'hello world' >> README
echo 'hola mundo' > README
echo 'salve munde' >> README
cat README | wc -lAnswer
2
Question 2
echo 'hello world' >> README
echo 'hola mundo' >> README
echo 'salve munde' >> README
wc -l READMEAnswer
3 README
Question 3
echo 'hello world' > README
echo 'hola mundo' >> README
echo 'salve munde' > README
wc -l < READMEAnswer
1
Question 4
printf 'red\nblue' > colors.txt
wc -l < colors.txtAnswer
1
Question 5
cat > notes.txt <<'END'
Review chapter one.
Try the examples.
END
echo 'Take a break.' >> notes.txt
cat notes.txtAnswer
Review chapter one.
Try the examples.
Take a break.
Question 6
echo 'draft' > notes.txt
touch notes.txt
cat notes.txtAnswer
draft
Question 7
touch 'hello world'
touch "hola mundo"
touch salve munde
ls | wc -lAnswer
4
Question 8
touch README
echo 'API_KEY=asd' > .env
ls -1Answer
README
Question 9
touch README
echo 'API_KEY=asd' > .env
ls -1aAnswer
.
..
.env
README
Question 10
touch README
mkdir test
touch test/README
cd test
echo 'API_KEY=asd' > ../.env
ls -1aAnswer
.
..
README
Question 11
touch README
mkdir test
mkdir test/test
touch test/README
touch test/test/README
cd test/../test
ls | wc -lAnswer
2
Question 12
touch README
mkdir test
touch test/README
touch test/.env
ls -a test | wc -lAnswer
4
Question 13
mkdir notes
echo 'first' > notes/a.txt
echo 'second' > notes/b.txt
echo 'third' >> notes/b.txt
cat notes/*.txt | wc -lAnswer
3
Question 14
mkdir drafts
touch drafts/day1.txt drafts/day2.txt drafts/day10.txt
cd drafts
rm day?.txt
ls -1Answer
day10.txt
Question 15
echo '404 GET /cats' > access.log
cp access.log backup.log
echo '500 GET /search' >> access.log
mkdir logs
mv access.log logs/access-2026-10-12.log
cat backup.log logs/access-2026-10-12.logAnswer
404 GET /cats
404 GET /cats
500 GET /search
Question 16
mkdir logs
touch access-2026-10-02.log access-2026-10-10.log
touch access-2026-10-11.log access-2026-10-12.log
mv access-2026-10-1?.log logs/
cd logs
mv access-2026-10-12.log ..
ls -1Answer
access-2026-10-10.log
access-2026-10-11.log
Question 17
cat > access.log <<'EOF'
09:00 200 GET /help/404
09:01 404 GET /cats
09:02 200 GET /404-cats
09:03 404 GET /old-page
EOF
grep ' 404 ' access.logAnswer
09:01 404 GET /cats
09:03 404 GET /old-page
Question 18
cat > access.log <<'EOF'
09:00 200 GET /Cats
09:01 404 GET /cats
09:02 200 GET /cats/photos
09:03 500 GET /search
EOF
grep -i 'cats' access.log | grep -v ' 200 'Answer
09:01 404 GET /cats
Question 19
cat > access.log <<'EOF'
2026-10-11 200 GET /archive/2026-10-12
2026-10-12 404 GET /old-page
2026-10-12 200 GET /archive
EOF
grep '^2026-10-12' access.log | grep ' 200 'Answer
2026-10-12 200 GET /archive
Question 20
cat > access.log <<'EOF'
200 GET /
404 GET /favicon.ico
500 GET /search
404 GET /cats
EOF
grep -n '404' access.log | grep -v 'favicon'Answer
4:404 GET /cats
Question 21
mkdir -p webpage/archive
echo '<a href="/cats">Cats</a>' > webpage/index.html
echo '<h1>Old links</h1>' > webpage/archive/index.html
echo '<a href="/old-page">Cats</a>' >> webpage/archive/index.html
grep -rn 'old-page' webpageAnswer
webpage/archive/index.html:2:<a href="/old-page">Cats</a>
Question 22
mkdir logs
echo '404 GET /cats' > logs/access-2026-10-10.log
echo '404 GET /old-page' >> logs/access-2026-10-10.log
echo '200 GET /' > logs/access-2026-10-11.log
echo '500 GET /search' > logs/access-2026-10-12.log
grep -rl '404' logsAnswer
logs/access-2026-10-10.log
Question 23
cat > access.log <<'EOF'
200 GET /
404 GET /cats
500 GET /search
EOF
grep '404' access.log > missing.txt
echo '404 GET /old-page' >> access.log
cat missing.txtAnswer
404 GET /cats
Question 24
cat > access.log <<'EOF'
200 GET /
404 GET /cats
500 GET /search
404 GET /old-page
EOF
cat > report.sh <<'EOF'
for status in 500 404
do
echo "Status $status:"
grep "^$status " access.log
done
EOF
bash report.shAnswer
Status 500:
500 GET /search
Status 404:
404 GET /cats
404 GET /old-page
Question 25
cat > access.log <<'EOF'
404 GET /cats
500 GET /search
404 GET /old-page
EOF
for status in 404 500
do
grep "^$status " access.log > errors.txt
done
cat errors.txtAnswer
500 GET /search
Question 26
echo '404 GET /cats' > access.log
cat > report.sh <<'EOF'
mkdir -p reports
echo 'Missing pages:' > reports/missing.txt
grep '404' access.log >> reports/missing.txt
EOF
bash report.sh
echo '404 GET /old-page' >> access.log
bash report.sh
cat reports/missing.txtAnswer
Missing pages:
404 GET /cats
404 GET /old-page
Question 27
mkdir tools test
echo '404 GET /cats' > access.log
echo '500 GET /search' > test/access.log
cat > tools/report.sh <<'EOF'
grep -v '200' access.log > errors.txt
EOF
cd test
bash ../tools/report.sh
cat errors.txtAnswer
500 GET /search
Question 28
cat > labels.sh <<'EOF'
for status in 404 500
do
echo 'Status $status'
echo "Status $status"
done
EOF
bash labels.shAnswer
Status $status
Status 404
Status $status
Status 500
Question 29
mkdir logs reports
echo '404 GET /cats' > logs/access-2026-10-12.log
echo '404 GET /old-page' >> logs/access-2026-10-12.log
grep '404' logs/access-2026-10-12.log > reports/missing.txt
grep -r '404' . | wc -lAnswer
4
Question 30
cat > access.log <<'EOF'
200 GET /
404 GET /favicon.ico
500 GET /search
404 GET /cats
EOF
grep '404' access.log | grep -nv 'favicon'Answer
2:404 GET /cats
Question 31
echo '404 GET /cats' > access.log
cat > report.sh <<'EOF'
mkdir -p reports
echo 'Missing pages:' > reports/missing.txt
grep '404' access.log >> reports/missing.txt
EOF
bash report.shAnswer
No Output
Question 32
cat > access.log <<'EOF'
404 GET /cats/cats
200 GET /cats
404 GET /old-page
404 GET /cats/photos/cats
EOF
grep '404' access.log | grep 'cats' | wc -lAnswer
2