1 00:00:00,410 --> 00:00:03,400 You've learned all the basics of working with a shell in the terminal. 2 00:00:03,400 --> 00:00:06,970 Let's end the course by looking at some of the other things you can do. 3 00:00:06,970 --> 00:00:09,270 We have a lot of ground to cover in this video, so 4 00:00:09,270 --> 00:00:12,215 we're only going to have a high level description of each command. 5 00:00:12,215 --> 00:00:15,230 There'll be more info in the teacher's notes if you want it. 6 00:00:16,270 --> 00:00:21,400 First up some additional commands that come standard on most UNIX-like systems. 7 00:00:21,400 --> 00:00:24,730 The find command is used to recursively search through a directory and 8 00:00:24,730 --> 00:00:27,520 all its subdirectories for files. 9 00:00:27,520 --> 00:00:31,650 The find command by itself just searches recursively through the current directory 10 00:00:31,650 --> 00:00:34,990 and prints out the name of every file and subdirectory it can find. 11 00:00:36,410 --> 00:00:38,680 If you want to find files with particular names, 12 00:00:38,680 --> 00:00:42,160 you can use the dash name option to find. 13 00:00:42,160 --> 00:00:44,900 The name parameter accepts wildcards. 14 00:00:44,900 --> 00:00:46,410 So this command, for example, 15 00:00:46,410 --> 00:00:51,420 will find every .txt file in the current directory and its subdirectories. 16 00:00:51,420 --> 00:00:54,490 Note that a wildcard expression has to be surrounded by quotes or 17 00:00:54,490 --> 00:00:57,900 the shell will attempt to expand it, and it'll never reach the find command. 18 00:00:59,500 --> 00:01:04,310 The grep command is used to print lines in a file that match a particular pattern. 19 00:01:04,310 --> 00:01:07,740 Let's go back to the directory that contains our terminal.txt script. 20 00:01:08,740 --> 00:01:12,860 And I'm gonna find all lines in the terminal.txt file that contain the word 21 00:01:12,860 --> 00:01:14,320 Windows. 22 00:01:14,320 --> 00:01:15,611 So I run the grep command and 23 00:01:15,611 --> 00:01:19,333 as the first argument that I pass Windows is the pattern that I'm looking for. 24 00:01:19,333 --> 00:01:23,800 Then I give it the name of the file that I want to look through is the second 25 00:01:23,800 --> 00:01:24,549 argument. 26 00:01:24,549 --> 00:01:25,696 And that will find and 27 00:01:25,696 --> 00:01:29,790 print every line that contains the word Windows in the terminal.txt file. 28 00:01:30,890 --> 00:01:33,498 Now let's do the same looking for the world Mac. 29 00:01:33,498 --> 00:01:39,110 grep 'Mac' terminal.txt. 30 00:01:39,110 --> 00:01:41,360 And there are all the lines that contain the word Mac. 31 00:01:42,590 --> 00:01:45,710 Now for a couple programs that will let you edit txt files from within 32 00:01:45,710 --> 00:01:46,830 your terminal. 33 00:01:46,830 --> 00:01:50,310 The vi program, where vi stands for visual, 34 00:01:50,310 --> 00:01:55,200 is the default editing program installed on most Unix-like operating systems. 35 00:01:55,200 --> 00:01:58,250 It's not fancy but it is widely available. 36 00:01:58,250 --> 00:02:00,740 At some point you're likely to find you have to use it 37 00:02:00,740 --> 00:02:04,720 because it's the only editor available on the system you're working on. 38 00:02:04,720 --> 00:02:07,780 Some developers love it though and use it for their daily work. 39 00:02:07,780 --> 00:02:12,270 Especially an expanded version called vim, which stands for vi improved. 40 00:02:13,410 --> 00:02:16,237 Vim has to be installed separately, though, so we'll focus on vi here. 41 00:02:16,237 --> 00:02:23,739 Let me use vi to edit a new file, which I'll call myfile.txt. 42 00:02:23,739 --> 00:02:25,850 Vi has two important modes. 43 00:02:25,850 --> 00:02:28,345 When it starts, it's in command mode. 44 00:02:28,345 --> 00:02:31,854 You don't wanna press random keys while you're in command mode because you'll be 45 00:02:31,854 --> 00:02:34,495 issuing commands you probably don't want to. 46 00:02:34,495 --> 00:02:39,090 You'll wanna press the i key which puts vi into insert mode. 47 00:02:39,090 --> 00:02:41,650 Now that I'm in insert mode, I can type freely, and 48 00:02:41,650 --> 00:02:44,850 the text will appear on the screen like I'm used to. 49 00:02:44,850 --> 00:02:48,960 To get back into command mode, I press the Escape key in the corner of my keyboard. 50 00:02:50,390 --> 00:02:53,780 Once I'm back in command mode, I can issue commands to save the file and 51 00:02:53,780 --> 00:02:55,090 quit the editor. 52 00:02:55,090 --> 00:02:58,840 I type a colon character and the cursor will appear in the lower right corner of 53 00:02:58,840 --> 00:03:01,270 the screen, waiting for a command. 54 00:03:01,270 --> 00:03:03,770 Then I type w and press enter. 55 00:03:03,770 --> 00:03:06,897 Vi will write the contents of the editor out to the file. 56 00:03:06,897 --> 00:03:09,432 Now to quit the editor, I type colon again and 57 00:03:09,432 --> 00:03:12,330 the cursor reappears in the lower right. 58 00:03:12,330 --> 00:03:16,330 Now I type q and press enter and vi will quit, returning us to the shell. 59 00:03:17,390 --> 00:03:22,090 We can take a look at the contents of our new file with cat myfile.txt. 60 00:03:22,090 --> 00:03:25,020 And you can see the text I typed has been written out to the file. 61 00:03:26,340 --> 00:03:30,300 VI can be a powerful editor, but it's not very friendly to beginners. 62 00:03:30,300 --> 00:03:33,300 Now let's look at an alternative editor. 63 00:03:33,300 --> 00:03:39,150 The nano editor is installed by default on some, but not all, Unix-like systems. 64 00:03:39,150 --> 00:03:42,300 If you have administrative privileges on a Unix-like system, 65 00:03:42,300 --> 00:03:43,750 you can install it yourself. 66 00:03:43,750 --> 00:03:46,360 See the teacher's notes for more info. 67 00:03:46,360 --> 00:03:50,590 But it's already available on the Linux OS used by workspaces. 68 00:03:50,590 --> 00:03:52,980 The command is similar to the vi command. 69 00:03:52,980 --> 00:03:55,890 You just type nano and the name of the file you want to edit.. 70 00:03:55,890 --> 00:03:59,890 So I'll edit nano file2.txt. 71 00:03:59,890 --> 00:04:03,590 Editing in nano is pretty straightforward, you just type. 72 00:04:03,590 --> 00:04:06,310 You can use the commands at the bottom of the screen when you're ready to 73 00:04:06,310 --> 00:04:07,780 save and exit. 74 00:04:07,780 --> 00:04:11,660 The caret symbol before each one stands for the Ctrl key. 75 00:04:11,660 --> 00:04:14,810 So to write out your file, you would press Ctrl+O. 76 00:04:14,810 --> 00:04:17,355 To exit Nano, you'd press Ctrl+X. 77 00:04:19,020 --> 00:04:22,110 So let me press Ctrl+O to write out the file. 78 00:04:22,110 --> 00:04:23,780 It'll ask me what file name to write to. 79 00:04:23,780 --> 00:04:26,820 I'll just keep the one I entered on the command line as the default. 80 00:04:26,820 --> 00:04:27,630 So I'll press Enter. 81 00:04:28,800 --> 00:04:31,446 And then I can hold down Ctrl and press X to exit. 82 00:04:33,229 --> 00:04:37,533 Again, if I run the cat command on the file that I specified for nano to edit, 83 00:04:37,533 --> 00:04:41,723 we can see that nano has written out what I typed in the editor to that file. 84 00:04:43,190 --> 00:04:46,890 Again, the goal of this video is just to let you know that these commands exist and 85 00:04:46,890 --> 00:04:48,360 what their basic function is. 86 00:04:48,360 --> 00:04:50,470 There's lots more to learn about each of them. 87 00:04:50,470 --> 00:04:53,030 For more info, be sure to check the teacher's notes.