Exercise 13: Stream a File (cat)

You're going to do some more setup for this one so you get used to making files in one program and then accessing them from the command line. With the same text editor from the last exercise, create another file named test2.txt but this time save it directly to your temp directory.

Do This

Linux/OSX

$ less test2.txt
[displays file here]
$ cat test2.txt
I am a fun guy.
Don't you know why?
Because I make poems,
that make babies cry.
$ cat test.txt
Hi there this is cool.
$

Windows

> more test2.txt
[displays file here]
> cat test2.txt
I am a fun guy.
Don't you know why?
Because I make poems,
that make babies cry.
> cat test.txt
Hi there this is cool.
>

Remember that when I say [displays file here] I'm abbreviating the output of that command so I don't have to show you exactly everything.

You Learned This

Do you like my poem? Totally going to win a Nobel. Anyway, you already know the first command, and I'm just having you check that your file is there. Then you cat the file to the screen. This command just spews the whole file to the screen with no paging or stopping. To demonstrate that, I have you do this to the test.txt which should just spew a bunch of lines from that exercise.

Do More

  • Make a few more text files and work with cat.
  • Unix: Try cat test.txt test2.txt and see what it does.
  • Windows: Try cat test.txt,test2.txt and see what it does.

Buy Learn Python the Hard Way, 5th Edition

When you buy Learn Python the Hard Way, 5th Edition directly from the author, Zed A. Shaw, you'll get access to the digital content for all 60 exercises, plus all 60+ videos that are normally sold separately. You'll also have access to direct help from Zed via Discord chat and live streams on special topics when I have time.

$29

Buy Learn Python The Hard Way, 5th Edition

Learn JavaScript the Hard Way

If you want to learn to be a Web Developer then my new Learn JavaScript the Hard Way course is a great choice. It's currently out as an Early Access release and already has more content than the Python Course, with even more content coming at a 80% discount from the final price.

Buy Learn JavaScript the Hard Way