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
echo 'x = 1' >> example.py
echo 'x += 1' >> example.py
echo 'print("x=", x)' >> example.py
python3 example.pyAnswer
x= 2
Question 5
echo 'xs = [1, 2]' >> example.py
echo 'xs.append(5)' >> example.py
echo 'print("xs=", xs)' >> example.py
python3 example.pyAnswer
xs= [1, 2, 5]
Question 6
cat > example.py <<EOF
x = 1
x += 1
print("x=", x)
EOF
python3 example.pyAnswer
x= 2
Question 7
touch hello_world
touch hola_mundo
touch salve_munde
ls | wc -lAnswer
3
Question 8
touch 'hello world'
touch "hola mundo"
touch salve munde
ls | wc -lAnswer
4
Question 9
touch README
echo 'API_KEY=asd' > .env
ls -1Answer
README
Question 10
touch README
echo 'API_KEY=asd' > .env
ls -1aAnswer
.
..
.env
README
Question 11
touch README
mkdir test
touch test/README
cd test
echo 'API_KEY=asd' > ../.env
ls -1aAnswer
.
..
README
Question 12
touch README
mkdir test
mkdir test/test
touch test/README
touch test/test/README
cd test/../test
ls | wc -lAnswer
2
Question 13
touch README
mkdir test
touch test/README
touch test/.env
ls -a test | wc -lAnswer
4
Question 14
touch README
mkdir test
touch test/README
touch test/.env
ls test | wc -lAnswer
1
Question 15
touch README
mkdir test
mkdir test/test
touch test/README
touch test/test/README
cd test/../test
ls .. -a | wc -lAnswer
4
Question 16
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 17
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 18
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 19
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 20
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 21
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 22
echo '200 GET /old-page' > access-2026-10-02.log
echo '404 GET /cats' > access-2026-10-10.log
echo '500 GET /search' > access-2026-10-11.log
echo '200 GET /' > access-2026-10-12.log
cat access-2026-10-1?.log | grep -v '200'Answer
404 GET /cats
500 GET /search
Question 23
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 24
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 25
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 26
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 27
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 28
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 29
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 30
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 31
touch access-2026-10-11.log access-2026-10-12.log
cat > names.sh <<'EOF'
echo '*.log'
echo *.log
EOF
bash names.shAnswer
*.log
access-2026-10-11.log access-2026-10-12.log
Question 32
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 33
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 34
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 35
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