Skip to content

Journey: Linux commands

After this journey you can: navigate the filesystem, manipulate files, search for content, and chain commands together.

This journey does not cover: system administration, package management, networking, or shell scripting beyond one-liners.

How to use this page: Each task gives you a goal and links to relevant documentation. Read the docs, write your solution, and compare your output with the expected result. Complete the tasks in order - some depend on files created in earlier tasks.

Setup

Clone the onboarding repository if you haven't already:

bash
git clone git@github.com:stratorys/onboarding.git

Create your workspace and copy the practice files:

bash
mkdir -p ~/linux-practice
bash
cp onboarding/docs/public/assets/linux/server.log ~/linux-practice/
bash
cp onboarding/docs/public/assets/linux/users.csv ~/linux-practice/
bash
cd ~/linux-practice

Writing scripts

Each task asks you to write a small script. A script is a text file that runs commands:

bash
#!/bin/bash
your-command-here

Save it, make it executable with chmod +x script.sh, and run it with ./script.sh.


Task 1: Count lines in a file

Goal: Write a script count_lines.sh that prints the number of lines in server.log.

INFO

wc stands for "word count" but it counts more than words.

Docs:

Expected output:

> ./count_lines.sh
1847

Task 2: Read the first and last entries

Goal: Write a script first_last.sh that prints the first line and the last line of server.log.

Docs:

Expected output:

> ./first_last.sh
2024-03-15 10:00:00 INFO  Server started version=2.4.1
2024-03-15 10:30:06 INFO  Server shutdown completed gracefully

Task 3: Find errors with line numbers

Goal: Write a script find_errors.sh that prints every line containing ERROR in server.log, prefixed with its line number.

Docs:

Expected output:

> ./find_errors.sh
87:2024-03-15 10:01:26 ERROR Failed to connect to database error="connection refused"
342:2024-03-15 10:05:41 ERROR Disk usage critical threshold=95%
896:2024-03-15 10:15:15 ERROR Request timeout endpoint=/api/export
1204:2024-03-15 10:22:03 ERROR Out of memory during batch job=etl-daily
1698:2024-03-15 10:28:57 ERROR TLS certificate expired service=payment-gateway

Task 4: Count warnings

Goal: Write a script count_warnings.sh that prints how many lines in server.log contain WARN.

INFO

The | operator sends the output of one command as input to another. This is called a pipe.

Docs:

Expected output:

> ./count_warnings.sh
42

Task 5: List unique log levels

Goal: Write a script list_levels.sh that prints every unique log level in server.log, sorted alphabetically, one per line.

The log format is: DATE TIME LEVEL MESSAGE.

Docs:

Expected output:

> ./list_levels.sh
DEBUG
ERROR
INFO
WARN

Task 6: Save errors to a file

Goal: Write a script extract_errors.sh that saves all ERROR lines from server.log into a new file called errors.log.

INFO

> writes output to a file and overwrites it. >> appends to a file.

Docs:

Expected output:

> ./extract_errors.sh
> wc -l errors.log
5 errors.log

Task 7: List unique roles

Goal: Write a script list_roles.sh that prints every unique role in users.csv, sorted alphabetically, one per line.

WARNING

The first line of users.csv is a header. Your output should not include column names.

Docs:

Expected output:

> ./list_roles.sh
admin
analyst
developer
manager

Task 8: Count users per role

Goal: Write a script count_roles.sh that prints how many users have each role, from most to least.

Docs:

Expected output:

> ./count_roles.sh
 118 developer
  45 analyst
  25 manager
  12 admin

Task 9: Find files by extension

Goal: Write a script find_logs.sh that lists every .log file in ~/linux-practice and its subdirectories.

Docs:

Expected output:

> ./find_logs.sh
./server.log
./errors.log

Task 10: Lock a file

Goal: Make errors.log read-only for everyone: owner, group, and others can read, but nobody can write or execute.

WARNING

chmod changes permissions. chown changes ownership. They are different operations.

Docs:

Expected output:

> ls -l errors.log
-r--r--r--  1 <user>  <group>  ... errors.log

Cleanup

bash
rm -rf ~/linux-practice

You now know enough terminal commands for daily development work. When you need something specific, use man <command> or <command> --help.