1 00:00:00,000 --> 00:00:01,930 [No audio] 2 00:00:01,930 --> 00:00:03,178 Terminal commands. 3 00:00:03,334 --> 00:00:06,234 There are some terminal commands that are used 4 00:00:06,392 --> 00:00:09,862 to help you manage your terminal more efficiently. 5 00:00:10,006 --> 00:00:11,814 Now number one command that I have 6 00:00:11,852 --> 00:00:14,638 listed here is a clear command. So clear command, 7 00:00:14,674 --> 00:00:15,798 when you log into your 8 00:00:15,824 --> 00:00:17,566 terminal, you run certain commands. 9 00:00:17,638 --> 00:00:20,840 You could just simply type clear to clear your screen. 10 00:00:21,350 --> 00:00:24,442 The next command we have is the exit command. 11 00:00:24,586 --> 00:00:26,494 exit command allows you to exit 12 00:00:26,542 --> 00:00:29,830 out of session, a shell session. 13 00:00:29,950 --> 00:00:33,497 If you have gone into different shell terminals, you can 14 00:00:33,524 --> 00:00:36,082 exit out to come back to your original session. 15 00:00:36,226 --> 00:00:38,754 Or you could exit out of the terminal that you have 16 00:00:38,792 --> 00:00:41,734 opened up, or you could exit out of a user session. 17 00:00:41,782 --> 00:00:44,842 So if you have become a different user by switching 18 00:00:44,866 --> 00:00:47,398 it to, su to a different user, you can simply 19 00:00:47,434 --> 00:00:52,590 type exit to come back to your own session. 20 00:00:52,970 --> 00:00:54,982 Then the last one is the script. 21 00:00:55,066 --> 00:00:57,286 script is very helpful command. 22 00:00:57,418 --> 00:01:00,642 It's a command that stores terminal activities in a 23 00:01:00,656 --> 00:01:03,990 log file that can be named by a user. 24 00:01:04,310 --> 00:01:05,382 You could run it and you 25 00:01:05,396 --> 00:01:06,941 can name anything that you want. 26 00:01:07,016 --> 00:01:09,574 When a name is not provided by the user, 27 00:01:09,682 --> 00:01:12,330 then the default file name is used, and that 28 00:01:12,380 --> 00:01:15,502 is typescript, the name of the file. 29 00:01:15,646 --> 00:01:17,698 So let's try all these three commands 30 00:01:17,734 --> 00:01:20,370 one by one in our Linux machine. 31 00:01:20,370 --> 00:01:26,190 [No audio] 32 00:01:26,190 --> 00:01:30,598 Okay, so when you run ls -ltr, whoami, 33 00:01:30,744 --> 00:01:32,182 and bunch of other stuff, 34 00:01:32,256 --> 00:01:34,642 ls -ltr on the tmp directory, all 35 00:01:34,656 --> 00:01:36,034 that stuff that comes up. 36 00:01:36,132 --> 00:01:40,378 So you could hit enter, enter , enter, enter, enter to clear up 37 00:01:40,404 --> 00:01:43,054 your screen, or simply just type clear. 38 00:01:43,212 --> 00:01:45,370 This will clear your screen. 39 00:01:45,480 --> 00:01:48,874 And many times when people run scripts, the first 40 00:01:48,912 --> 00:01:51,202 thing they put it in the script is clear. 41 00:01:51,276 --> 00:01:55,582 So the output will clear up everything on your 42 00:01:55,596 --> 00:01:58,080 screen and then start from a new line. 43 00:01:58,770 --> 00:02:01,226 Then you have the next command is exit. 44 00:02:01,298 --> 00:02:03,134 exit is simply, when you type exit, 45 00:02:03,182 --> 00:02:06,230 it will exit out of your script, 46 00:02:06,290 --> 00:02:08,326 if there is any script it was running before. 47 00:02:08,388 --> 00:02:10,270 So I'm just going to clear that. 48 00:02:10,320 --> 00:02:14,280 So I'm going to type exit again, one more time, 49 00:02:15,570 --> 00:02:16,666 and there you go. 50 00:02:16,728 --> 00:02:18,190 It has exited out. 51 00:02:18,240 --> 00:02:20,590 I had a few scripts commands that were running 52 00:02:20,640 --> 00:02:23,162 previously, that's why I couldn't get it out earlier. 53 00:02:23,246 --> 00:02:25,558 But anyway, the last one got me out. 54 00:02:25,584 --> 00:02:28,114 So I'll open up a terminal again and this time 55 00:02:28,152 --> 00:02:31,214 I'm typing exit again to exit out of the terminal, 56 00:02:31,322 --> 00:02:34,680 because this will explain better how the exit works. 57 00:02:35,310 --> 00:02:38,580 If you become a different user, let's say su 58 00:02:39,150 --> 00:02:44,386 spider, you put in the password, now you see, 59 00:02:44,448 --> 00:02:46,142 you are logged in as spider. 60 00:02:46,226 --> 00:02:50,066 What if you want to go back into your original 61 00:02:50,138 --> 00:02:53,450 session, which is iafzal, you just type simply exit, 62 00:02:53,570 --> 00:02:56,446 and you could become back again to yourself. 63 00:02:56,628 --> 00:02:59,338 So this is what the exit command is mostly used for. 64 00:02:59,424 --> 00:03:03,106 And the last command, which I personally like, because 65 00:03:03,168 --> 00:03:06,962 it records everything that you do on your session. 66 00:03:07,106 --> 00:03:10,390 So what it does is when you run script, 67 00:03:10,390 --> 00:03:12,510 [Author typing] 68 00:03:12,510 --> 00:03:14,854 you have to specify the name I will put 69 00:03:14,892 --> 00:03:21,430 in transaction or, you know what, logfile-activity. 70 00:03:22,615 --> 00:03:23,716 .log. 71 00:03:24,550 --> 00:03:26,234 When I hit enter, it says 72 00:03:26,332 --> 00:03:30,410 Script started, file is logfile-activity.log. 73 00:03:30,520 --> 00:03:32,726 And that log file is created within 74 00:03:32,788 --> 00:03:35,438 the same directory that you are in. 75 00:03:35,464 --> 00:03:37,898 So when you run ls -ltr, you'll see at the 76 00:03:37,924 --> 00:03:42,290 end, it has created a file called logfile-activity. 77 00:03:42,730 --> 00:03:45,474 I just ran this command ls -ltr. 78 00:03:45,582 --> 00:03:49,094 This output of this command will be recorded in that. 79 00:03:49,192 --> 00:03:54,526 So if I go into another directory, let's say etc slash, 80 00:03:55,457 --> 00:04:03,090 cd /etc, run ls -ltr, clear my screen, type history command, 81 00:04:03,270 --> 00:04:07,958 or type pwd, and whatever that I am doing in 82 00:04:07,984 --> 00:04:11,754 my session, everything is recorded in my log file. 83 00:04:11,862 --> 00:04:15,842 Right now, you'll see, if I do cd, and if you go back 84 00:04:15,856 --> 00:04:21,060 to my home directory, type pwd, and I do ls -ltr, 85 00:04:21,060 --> 00:04:24,926 you see the logfile-activity, the sizes keep 86 00:04:24,988 --> 00:04:29,318 increasing because it does keep recording all the commands, and all 87 00:04:29,344 --> 00:04:31,302 the output that's coming from those commands. 88 00:04:31,386 --> 00:04:33,566 So now if I want it to be done 89 00:04:33,688 --> 00:04:37,506 with this script command, I'll just simply type exit. 90 00:04:37,638 --> 00:04:40,730 Once I do exit, it will tell me Script done, 91 00:04:40,900 --> 00:04:43,934 file is logfile-activity.log. 92 00:04:44,032 --> 00:04:46,706 It means now it is not recording anything. 93 00:04:46,828 --> 00:04:50,538 It has finished capturing the output of your session. 94 00:04:50,634 --> 00:04:54,242 Now you could view, let's clear the screen, and you 95 00:04:54,256 --> 00:04:57,314 could view the log activity, which is right here, 96 00:04:57,352 --> 00:05:00,798 when I do more on the file, 97 00:05:00,954 --> 00:05:03,254 I hit enter, and you will see, 98 00:05:03,412 --> 00:05:06,650 the first command when I ran after running 99 00:05:06,700 --> 00:05:09,398 the script command was the ls -ltr. 100 00:05:09,484 --> 00:05:11,342 It recorded the command, recorded 101 00:05:11,416 --> 00:05:12,858 the output of the command, 102 00:05:12,954 --> 00:05:13,922 keep going, 103 00:05:14,116 --> 00:05:17,706 and then I went to etc directory 104 00:05:17,838 --> 00:05:22,166 and I did ls -ltr, it recorded everythingI did. 105 00:05:23,918 --> 00:05:27,050 See all the commands, everything that I did 106 00:05:27,100 --> 00:05:30,290 while I was running the commands after the script. 107 00:05:30,790 --> 00:05:34,946 The reason that I use the script command most of 108 00:05:34,948 --> 00:05:38,558 the time is because when I am troubleshooting an issue 109 00:05:38,704 --> 00:05:44,294 or if I am creating some tools or creating some 110 00:05:44,332 --> 00:05:47,378 scripts, this would record everything for me. 111 00:05:47,464 --> 00:05:51,470 So in case a month from now or a year from now, 112 00:05:51,580 --> 00:05:54,734 and I wanted to perform the same tasks, I don't have to 113 00:05:54,772 --> 00:05:58,842 look up the commands to execute that on the terminal. 114 00:05:58,866 --> 00:06:01,366 I could just simply go into my logfile-activity, 115 00:06:01,366 --> 00:06:03,854 and I will view that and remember, oh 116 00:06:03,892 --> 00:06:06,566 yeah, these are the commands I ran, awesome. 117 00:06:06,628 --> 00:06:11,222 It's like a log book, a recording way, 118 00:06:11,356 --> 00:06:14,486 it records all your commands in a log file. 119 00:06:14,486 --> 00:06:18,539 [No audio]