Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Introduction to the Terminal!
You have completed Introduction to the Terminal!
Preview
In this stage, we're going to introduce some helpful commands you can run in the terminal. We'll start with the "less" command, which is a convenient way to look at the contents of files.
- Let me change to the
~/workspace/library/non-fiction
directory:cd ~/workspace/library/non-fiction
ls
- I have a text file here, called
terminal.txt
. - It's not huge, but it's bigger than the text files we've looked at so far. It contains more that a terminal screen's worth of text.
- If I want to look at its contents, I could use the
cat
command:cat terminal.txt
- But there's a couple problems with this.
- First, the text doesn't all fit on the screen. The top part is cut off.
- Second, it leaves the file contents sitting in my terminal output. I can't see my previous commands or their output any more.
- This file's still pretty short, so it isn't too bad, but with bigger files this could be a real issue.
- This is why pager programs were created. They're interactive programs that display a file on your terminal screen, one page at a time.
- When I say they're interactive, I mean that they don't finish running immediately; they wait for input from you.
- The original pager on most Unix-like systems is a program called
more
.- In fact, it's still around on many systems today.
- You type the
more
command name, and pass the names of one or more files you want to read as arguments:more terminal.txt
- Notice the "More" indicator at the bottom of the screen. It's showing that there's more content in the file that isn't displayed yet.
- If I press the spacebar, it will display another terminal screenful, or "page", of text.
- It will keep doing this until it reaches the bottom of the file, at which point it will quit, leaving the file contents displayed on the terminal.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
--More--(30%)
- Many systems have another, newer pager program installed that's inspired by
more
, calledless
.- It works in the same way. You type
less
, followed by the names of one or more files you want to view:less terminal.txt
-
less
starts by showing the top of the file. - You can use the space bar to show additional pages, if you want, but you can also use the arrow keys to scroll up and down, one line at a time.
- Unlike
more
,less
does not automatically quit when you reach the bottom of the file, because that would prevent you from scrolling back up. - When you want to quit
less
, you press the "q" key.
- It works in the same way. You type
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
terminal.txt
- Notice that unlike
more
,less
doesn't leave the file contents up on your terminal screen when it's done. It restores everything just the way it was.- This lets you easily review your previous commands and their output.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
[MUSIC]
0:00
In this stage,
0:04
we're going to introduce some helpful
commands you can run in the terminal.
0:05
We'll start with the less command,
0:09
which is a convenient way to
look at the contents of files.
0:11
Let me change to the workspace/
library/non-fiction directory.
0:15
I have a text file here
called terminal.text.
0:22
It's not huge, but it's bigger than
the text files we've looked at so far.
0:25
It contains more than a terminal
screen's worth of text.
0:30
If I wanna look at its contents, I could
use the cat command cat terminal.txt.
0:33
But there's a couple
of problems with this.
0:39
First, the text doesn't
all fit on the screen.
0:41
The top part is cut off.
0:43
Second, it leaves the file contents
sitting in my terminal output.
0:45
I can't see my previous commands or
their output anymore.
0:49
This file's still pretty short,
so it isn't too bad.
0:53
But with bigger files,
this could be a real issue.
0:56
This is why pager programs were created.
0:59
They're interactive programs that
display a file on your terminal screen
1:01
one page at a time.
1:05
When I say they're interactive, I mean
they don't finish running immediately.
1:07
They wait for input from you.
1:11
The original pager on most Unix-like
systems is a program called More.
1:13
In fact,
it's still around on many systems today.
1:18
You type the more command name and
pass the names of one or
1:22
more files you want to read as arguments.
1:25
More terminal.txt.
1:27
Notice the More indicator at
the bottom of the screen,
1:30
it's showing that there's more content
in the file that isn't displayed yet.
1:33
This is the indicator that gives
the More program its name.
1:36
If I press the space bar it will
display another terminal screenful or
1:40
page of text.
1:45
It will keep doing this until it
reaches the bottom of the file,
1:46
at which point it will quit, leaving the
file contents displayed on the terminal.
1:49
Many systems have another pager program
installed that's inspired by More,
1:54
called Less.
1:59
It works in the same way.
2:00
You type less followed by the names of
one or more files you want to view.
2:02
So, less terminal.text.
2:06
Less starts by showing
the top of the file.
2:07
You can use the space bar to show
additional pages if you want, but
2:11
you can also use the arrow keys to
scroll up and down, one line at a time.
2:14
Unlike More, Less does not automatically
quit when you reach the bottom of the file
2:20
because that would prevent
you from scrolling back up.
2:24
When you want to quit
Less you press the Q key.
2:27
Notice that unlike More,
2:30
Less doesn't leave the file contents up
on your terminal screen when it's done.
2:31
It restores everything
just the way it was.
2:35
This lets you easily review your
previous commands and their output.
2:37
The cat program is still occasionally useful
especially with short files, but now you
2:41
know a better way to review the contents
of larger files, the Less program.
2:46
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up