Fall 2026
  • Discord
  • Gradescope
  • Syllabus

On this page

  • Question 1
  • Question 2
  • Question 3
  • Question 4
  • Question 5
  • Question 6
  • Question 7
  • Question 8
  • Question 9
  • Question 10
  • Question 11
  • Question 12
  • Question 13
  • Question 14
  • Question 15
  • Question 16
  • Question 17
  • Question 18
  • Question 19
  • Question 20
  • Question 21
  • Question 22
  • Question 23
  • Question 24
  • Question 25
  • Question 26
  • Question 27
  • Question 28
  • Question 29
  • Question 30
  • Question 31
  • Question 32

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 -l
Answer
2

Question 2

echo 'hello world' >> README
echo 'hola mundo' >> README
echo 'salve munde' >> README
wc -l README
Answer
3 README

Question 3

echo 'hello world' > README
echo 'hola mundo' >> README
echo 'salve munde' > README
wc -l < README
Answer
1

Question 4

printf 'red\nblue' > colors.txt
wc -l < colors.txt
Answer
1

Question 5

cat > notes.txt <<'END'
Review chapter one.
Try the examples.
END
echo 'Take a break.' >> notes.txt
cat notes.txt
Answer
Review chapter one.
Try the examples.
Take a break.

Question 6

echo 'draft' > notes.txt
touch notes.txt
cat notes.txt
Answer
draft

Question 7

touch 'hello world'
touch "hola mundo"
touch salve munde
ls | wc -l
Answer
4

Question 8

touch README
echo 'API_KEY=asd' > .env
ls -1
Answer
README

Question 9

touch README
echo 'API_KEY=asd' > .env
ls -1a
Answer
.
..
.env
README

Question 10

touch README
mkdir test
touch test/README
cd test
echo 'API_KEY=asd' > ../.env
ls -1a
Answer
.
..
README

Question 11

touch README
mkdir test
mkdir test/test
touch test/README
touch test/test/README
cd test/../test
ls | wc -l
Answer
2

Question 12

touch README
mkdir test
touch test/README
touch test/.env
ls -a test | wc -l
Answer
4

Question 13

mkdir notes
echo 'first' > notes/a.txt
echo 'second' > notes/b.txt
echo 'third' >> notes/b.txt
cat notes/*.txt | wc -l
Answer
3

Question 14

mkdir drafts
touch drafts/day1.txt drafts/day2.txt drafts/day10.txt
cd drafts
rm day?.txt
ls -1
Answer
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.log
Answer
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 -1
Answer
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.log
Answer
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' webpage
Answer
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' logs
Answer
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.txt
Answer
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.sh
Answer
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.txt
Answer
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.txt
Answer
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.txt
Answer
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.sh
Answer
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 -l
Answer
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.sh
Answer
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 -l
Answer
2