Photo by Sweetyoga Justine / Unsplash

Exercises for cat, head and tail

Exercises Jun 19, 2025 (Jun 19, 2025) Loading...

If we're live, go to https://envs.workroomprds.com/ and pick an environment. Read about these tools at cat, head and tail for Testers

Exercise 1 – exchange experiences

Let's talk: What have we seen cat head and tail used for in testing?

Exercise 2 – demo cat , head and tail to ourselves

Open the terminal, and

1) Try this to pick out all the test definitions in a test file

cat ~/code/rs_py/tests/test_* | grep "def test_"

and consider why you might do this rather than

grep "def test_" ~/code/rs_py/tests/test_*

2) try this to see the tops of all the test files in a directory:

head ~/code/rs_py/tests/test_*

3) Try this to see the access log for the web server – you'll see it change as the page you're working in makes requests of the server.

sudo tail -F /var/log/nginx/access.log

You need sudo to get system access. -F follows the log, updating as it changes.

4) cat will do some transforms – and especially cat -tve will sanitise otherwise unprintable data. Compare head -n 2 /var/log/wtmp and head -n 2 /var/log/wtmp | cat -tve

Exercise 3 – oddities

The stream `/dev/urandom` is full of randomness, so head -c 5 /dev/urandom returns stuff. Try it – then try tail ... . Try cat if you're brave. What's happening here?

Open two terminals, or a terminal and an editor.On the commandline (of a terminal), tail -F whatever.txt. In the other terminal, or in the editor, open whatever.txt , add text, save, check the terminal, repeat. What's happening here?

Just type cat. What's happening here?

Member reactions

Reactions are loading...

Sign in to leave reactions on posts

Tags

Comments

Sign in or become a Workroom Productions member to read and leave comments.

James Lyndsay

Getting better at software testing. Singing in Bulgarian. Staying in. Going out. Listening. Talking. Writing. Making.

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.