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


$ less test.txt
[displays file here]

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


> more test.txt
[displays file here]


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 The Python 2 Course

When you buy directly from the author, Zed A. Shaw, you'll get a professional quality PDF and hours of HD Video, all DRM-free and yours to download.


Buy The Python 2 Course Buy The Python 3 Course Instead

Try a free sample of Learn Python the Hard Way right here, video lectures not included.