> ## Content Index
> Fetch the complete content index at: https://www.workroom-productions.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Exercises for cat, head and tail
- URL: https://www.workroom-productions.com/exercises-for-cat-head-and-tail/
- Published: 2025-06-19T13:52:23.000Z
- Updated: 2025-06-19T13:52:23.000Z
- Description: Get on the commandline and play with these tools
- Author: James Lyndsay
- Tags: Exercises, #PlayTime

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](https://www.workroom-productions.com/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](https://en.wikipedia.org/wiki//dev/random). 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?*