Exercise 12: View a File (less, MORE)

To do this exercise you're going to do some work using the commands you know so far. You'll also need a text editor that can make plain text (.txt) files. Here's what you do:

  • Open your text editor and type some stuff into a new file. On OSX this could be TextWrangler. On Windows this might be Notepad++. On Linux this could be gedit. Any editor will work.
  • Save that file to your desktop and name it test.txt.
  • In your shell use the commands you know to copy this file to your temp directory that you've been working with.

Once you've done that, complete this exercise.

Do This

Linux/OSX

$ less test.txt
[displays file here]
$

That"s it. To get out of less just type q (as in quit).

Windows

> more test.txt
[displays file here]
>

Note

In the above output I'm showing [displays file here] to "abbreviate" what that program shows. I'll do this when I mean to say, "Showing you the output of this program is too complex, so just insert what you see on your computer here and pretend I did show it to you." Your screen will not actually show this.

You Learned This

This is one way to look at the contents of a file. It's useful because, if the file has many lines, it will "page" so that only one screenful at a time is visible. In the Do More section you'll play with this some more.

Do More

  • Open your text file again and repeatedly copy-paste the text so that it's about 50-100 lines long.
  • Copy it to your temp directory again so you can look at it.
  • Now do the exercise again, but this time page through it. On Unix you use the spacebar and w (the letter w) to go down and up. Arrow keys also work. On Windows just hit the spacebar to page through.
  • Look at some of the empty files you created too.
  • The cp command will overwrite files that already exist so be careful copying files around.

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