1 00:00:07,080 --> 00:00:07,913 - In this video, 2 00:00:07,913 --> 00:00:10,350 I will tell you about command line completion. 3 00:00:10,350 --> 00:00:13,020 Command line completion is another great feature 4 00:00:13,020 --> 00:00:16,011 that is offered by all the current Linux shells. 5 00:00:16,011 --> 00:00:17,790 So how does it work? 6 00:00:17,790 --> 00:00:19,920 Well by using the tab key. 7 00:00:19,920 --> 00:00:22,680 If you start typing a command and then you press tab, 8 00:00:22,680 --> 00:00:24,720 then tab is going to try 9 00:00:24,720 --> 00:00:26,850 to automatically complete the command. 10 00:00:26,850 --> 00:00:28,200 And that works for commands, 11 00:00:28,200 --> 00:00:30,900 for variables, as well as for file names. 12 00:00:30,900 --> 00:00:32,160 And in case a tab key 13 00:00:32,160 --> 00:00:34,350 doesn't give you anything to complete, 14 00:00:34,350 --> 00:00:37,733 then you might have to press the tab key again 15 00:00:37,733 --> 00:00:40,920 because sometimes there are just multiple options 16 00:00:40,920 --> 00:00:42,900 and the shell doesn't know how to complete, 17 00:00:42,900 --> 00:00:44,040 just do a tab, tab, 18 00:00:44,040 --> 00:00:45,150 and you get an overview 19 00:00:45,150 --> 00:00:47,253 of all the different options that exist. 20 00:00:48,090 --> 00:00:51,570 Now in some cases you may find the best completion 21 00:00:51,570 --> 00:00:52,435 doesn't work. 22 00:00:52,435 --> 00:00:54,600 Then it's really recommended to install 23 00:00:54,600 --> 00:00:56,430 the bash-completion package. 24 00:00:56,430 --> 00:00:58,950 That will give you additional completion features 25 00:00:58,950 --> 00:01:01,920 including completion that works for certain commands. 26 00:01:01,920 --> 00:01:03,033 Let me demonstrate. 27 00:01:05,310 --> 00:01:08,580 So to start with, I want to use user tab. 28 00:01:08,580 --> 00:01:10,140 Oh, nothing is happening. 29 00:01:10,140 --> 00:01:12,390 Well, that is because there are too many commands 30 00:01:12,390 --> 00:01:13,620 starting with user. 31 00:01:13,620 --> 00:01:16,080 So I'm using user tab tab, and there we go, 32 00:01:16,080 --> 00:01:18,120 we have all the different options. 33 00:01:18,120 --> 00:01:22,830 So I'm typing users and it executes the users commands. 34 00:01:22,830 --> 00:01:27,830 Now, what is really amazing is if you use a command like IP. 35 00:01:28,499 --> 00:01:31,320 IP is a pretty complex command, 36 00:01:31,320 --> 00:01:33,810 we will investigate it in a little bit more detail 37 00:01:33,810 --> 00:01:36,060 in the lesson about networking. 38 00:01:36,060 --> 00:01:38,520 The IP command works with different arguments, 39 00:01:38,520 --> 00:01:40,170 like IP address. 40 00:01:40,170 --> 00:01:41,340 And there we go. 41 00:01:41,340 --> 00:01:44,100 I'm completing to ip addr 42 00:01:44,100 --> 00:01:48,510 and tab completion is showing me what I can do with ip addr. 43 00:01:49,350 --> 00:01:52,080 So we have add and change and del and flush 44 00:01:52,080 --> 00:01:54,270 and help and replace and show. 45 00:01:54,270 --> 00:01:56,730 Let me just do a show and there we can see 46 00:01:56,730 --> 00:02:00,630 how this bash completion even helps me 47 00:02:00,630 --> 00:02:03,780 with arguments for some of the more complex commands. 48 00:02:03,780 --> 00:02:05,760 And I would advise if you are going to work 49 00:02:05,760 --> 00:02:07,230 with more complex commands, 50 00:02:07,230 --> 00:02:09,690 give it a try and find out if bash completion 51 00:02:09,690 --> 00:02:12,240 is working for these command arguments as well, 52 00:02:12,240 --> 00:02:15,570 that will really make your life a lot easier. 53 00:02:15,570 --> 00:02:17,970 Now it also works for variables. 54 00:02:17,970 --> 00:02:22,970 So if I use echo $HI to refer to a variable, 55 00:02:24,750 --> 00:02:25,770 I'm printing a dollar 56 00:02:25,770 --> 00:02:27,750 and then the name of the variable. 57 00:02:27,750 --> 00:02:30,030 Here, it's only the start of the variable. 58 00:02:30,030 --> 00:02:30,990 I'm pressing tab. 59 00:02:30,990 --> 00:02:33,180 And there we can see it's making it HIST. 60 00:02:33,180 --> 00:02:35,520 I'm pressing tab twice again 61 00:02:35,520 --> 00:02:39,150 and there we can see that there are different variables 62 00:02:39,150 --> 00:02:41,137 including the HISTFILESIZE, 63 00:02:42,900 --> 00:02:46,560 which is showing me that it's currently set to 1000. 64 00:02:46,560 --> 00:02:49,226 So the actual length of the history file 65 00:02:49,226 --> 00:02:52,110 is defined in a variable. 66 00:02:52,110 --> 00:02:55,920 And of course you can use it on file names as well. 67 00:02:55,920 --> 00:02:59,100 Let me create a ridiculously long file name. 68 00:02:59,100 --> 00:03:00,054 There we go. 69 00:03:00,054 --> 00:03:03,000 And do you really think it's complicated to work with it? 70 00:03:03,000 --> 00:03:04,031 Of course not. 71 00:03:04,031 --> 00:03:06,870 Just first two letters, then you press tab 72 00:03:06,870 --> 00:03:10,380 and you can see the properties of this ridiculous file, 73 00:03:10,380 --> 00:03:12,720 including the option that allows you 74 00:03:12,720 --> 00:03:15,510 to remove this ridiculously long file. 75 00:03:15,510 --> 00:03:17,433 And that's how you work with history.