Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
You've learned all the basics of working with a shell in the Terminal. Let's end the course by looking at some of the other things you can do.
First up, some additional commands that come standard on most Unix-like systems.
- The
find
command is used to recursively search through a directory and all its subdirectories for files.-
find
by itself will recursively search through all subdirectories, printing the path of every directory and file it finds.
-
treehouse:~/workspace$ find
.
./statue.txt
./library
./library/periodicals
./library/fiction
./library/fiction/neal_stephenson
./library/fiction/neal_stephenson/snow_crash.txt
./library/fiction/kim_stanley_robinson
./library/fiction/kim_stanley_robinson/red_mars.txt
./library/fiction/kim_stanley_robinson/green_mars.txt
- You can limit the results to files whose name matches a particular pattern with the
-name
option.- You can use wildcards in the pattern to match partial names:
find -name "*.txt"
- Note that a wildcard expression must be surrounded by quotes, or the shell will attempt to expand it and it will never reach the
find
command.
- You can use wildcards in the pattern to match partial names:
treehouse:~/workspace$ find -name "*.txt"
./statue.txt
./library/fiction/neal_stephenson/snow_crash.txt
./library/fiction/kim_stanley_robinson/red_mars.txt
./library/fiction/kim_stanley_robinson/green_mars.txt
./library/fiction/kim_stanley_robinson/blue_mars.txt
./library/fiction/kim_stanley_robinson/red_moon.txt
./library/non-fiction/terminal.txt
./mall/dullards/jewelry/catalog.txt
./mall/starbunks/menu.txt
./mall/map.txt
./cart.txt
./pigeon.txt
./sparrow.txt
You can read more about find
here.
- The
grep
command is used to print lines in a file that match a particular pattern.cd library/non-fiction/
grep 'Windows' terminal.txt
grep 'Mac' terminal.txt
treehouse:~/workspace$ cd library/non-fiction/
treehouse:~/workspace/library/non-fiction$ grep 'Windows' terminal.txt
* [Activate Virtualbox Windows] On Windows, it's called Command Prompt, although there are alternatives like PowerShell.
. You might wonder why we're not showing the Windows way first... Let me explain.
* This isn't true with Windows. You can still do a lot from the Command Prompt on Windows, but most commands are run in a different way, and will only work on Windows.
* But, like I said, we'll have info near the end of the course for those who need to apply what they learn on Windows.
treehouse:~/workspace/library/non-fiction$ grep 'Mac' terminal.txt
* [Activate Finder] On Mac and Linux machines, it's usually simply called Terminal.
In this course, we're going to be focusing on the terminal as used in the Linux and Mac operating systems.
* These compatible OSs include Linux and Mac OS.
* We'll also show you how to access the terminal on Mac and Linux systems.
You can read more about grep
here.
Now for a couple programs that will let you edit text files within your terminal.
- The
vi
program, where "vi" stands for "visual", is the default editing program installed on most Unix-like operating systems. - It's not fancy, but it is widely available. At some point you are likely to find you have to use it, because it's the only editor available on the system you're working on.
- Some developers love it, though, and use it for their daily work, especially an expanded version called
vim
(which stands for "vi improved").-
vim
has to be installed separately, though, so we'll focus onvi
here.
-
- Let me use
vi
to edit a new file, which I'll callmyfile.txt
:vi myfile.txt
-
vi
has two important modes. - When it starts, it's in "command mode".
- You don't want to press random keys while you're in command mode, because you'll be issuing commands you probably don't want to.
- You'll want to press the "i" key, which puts
vi
into "insert mode".
Now that I'm in insert mode, I can type freely, and
the text will appear on the screen like I'm used to.
- To get back into command mode, I press the Esc key in the corner of my keyboard.
- Once I'm back in command mode, I can issue commands to save the file and quit the editor.
- I type ":", and the cursor will appear in the lower-right corner of the screen, waiting for a command.
- Then I type "w", and press Enter.
vi
will write the contents of the editor out to the file. - Now to quit the editor.
- I type ":" again, and the cursor reappears in the lower-right.
- Now I type "q", and press Enter, and
vi
will quit, returning us to the shell. cat myfile.txt
You can read more about vi
here.
vi
can be a powerful editor, but it's not very friendly to beginners. Now let's look at an alternative editor.
- The
nano
editor is installed by default on some, but not all Unix-like systems. - It's already available on the Linux OS used by Workspaces.
- The command is similar to the
vi
command; you just typenano
and the name of the file you want to edit:nano file2.txt
Editing here is pretty straightforward; just type.
Use the commands at the bottom when you are ready to save
and exit. The ^ symbol stands for the Ctrl key. So to
write out your file, press Ctrl-o. To exit Nano, press
Ctrl-x.
- Installing
nano
:
You can read more about nano
here.
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
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