Difference between revisions of "BOSS-Linux/C2/The-Linux-Environment/English-timed"
From Script | Spoken-Tutorial
(Created page with "{| border=1 |'''Time''' |'''Narration''' |- |00:01 |Welcome to this spoken tutorial on the Linux environment and ways to manupulate it. |- |00:07 |A working linux system, wil...") |
|||
(7 intermediate revisions by 2 users not shown) | |||
Line 3: | Line 3: | ||
|'''Narration''' | |'''Narration''' | ||
|- | |- | ||
− | |||
|00:01 | |00:01 | ||
− | |Welcome to this spoken tutorial on the Linux environment and ways to | + | |Welcome to this '''spoken tutorial''' on the '''Linux environment''' and ways to manipulate it. |
|- | |- | ||
|00:07 | |00:07 | ||
− | |A working | + | |A working '''Linux system''' will be required to try out the examples illustrated in this tutorial. |
|- | |- | ||
|00:12 | |00:12 | ||
− | |We assume that you know how to get started with the Linux operating system and have some basic idea about commands, file systems and shell . | + | |We assume that you know how to get started with the '''Linux operating system''' and have some basic idea about '''commands, file systems''' and '''shell'''. |
|- | |- | ||
|00:20 | |00:20 | ||
− | |If you are interested | + | |If you are interested or need to brush these concepts up, please feel free to do so through another spoken tutorial available on our website. |
− | + | ||
|- | |- | ||
|00:30 | |00:30 | ||
− | |Please | + | |Please note that Linux is '''case sensitive''' and all the commands used in this tutorial are in lower case unless otherwise mentioned. |
|- | |- | ||
|00:40 | |00:40 | ||
Line 24: | Line 22: | ||
|- | |- | ||
|00:48 | |00:48 | ||
− | |Linux can be highly customized by changing the settings of the shell. | + | |Linux can be highly customized by changing the settings of the '''shell'''. |
|- | |- | ||
|00:51 | |00:51 | ||
Line 30: | Line 28: | ||
|- | |- | ||
|00:54 | |00:54 | ||
− | |The | + | |The behavior of the '''shell''' is generally determined by the '''shell variables'''. |
|- | |- | ||
|00:58 | |00:58 | ||
− | |There are mainly two kinds of shell variables: | + | |There are mainly two kinds of shell variables: '''Environment Variables''' and '''Local Variables'''. |
− | + | ||
− | Environment Variables and | + | |
− | + | ||
− | Local Variables | + | |
|- | |- | ||
|01:06 | |01:06 | ||
− | |Environment variables, named so because they are available entirely in the user's total environment. | + | |'''Environment variables''', named so because they are available entirely in the user's total environment. |
|- | |- | ||
|01:12 | |01:12 | ||
− | |These are also available in | + | |These are also available in sub-shells spawned by the shell like the ones for running '''shell script'''s. |
|- | |- | ||
|01:18 | |01:18 | ||
− | |Local Variables | + | |'''Local Variables''' which as the name suggests have a more restricted or limited availability. |
|- | |- | ||
|01:24 | |01:24 | ||
− | |These are not available in the | + | |These are not available in the sub-shells spawned by the '''shell'''. |
|- | |- | ||
|01:28 | |01:28 | ||
− | |While in this tutorial, we will mainly talk about environment variables | + | |While in this tutorial, we will mainly talk about environment variables. Let us first see how the value of these shell variables can be seen. |
|- | |- | ||
|01:41 | |01:41 | ||
− | |To see all the variables available in the current shell , we run the command set. | + | |To see all the variables available in the current shell, we '''run''' the command''' 'set'.''' |
|- | |- | ||
|01:46 | |01:46 | ||
− | | Type at the terminal '''set''' space pipeline character '''more''' and press | + | | Type at the terminal: '''set''' space pipeline character '''more''' and press Enter. |
|- | |- | ||
|01:53 | |01:53 | ||
− | |We can see all the current shell variables , | + | |We can see all the current shell variables. , |
|- | |- | ||
|01:58 | |01:58 | ||
− | |For example | + | |For example- take a look at the '''HOME''' environment variable; also notice the value assigned to it. |
|- | |- | ||
|02:07 | |02:07 | ||
− | | | + | |Press '''Enter''' to move through the list and in order to come out, press '''q'''. |
|- | |- | ||
|02:14 | |02:14 | ||
− | |Here the output from set was | + | |Here, the output from '''set''' was pipe-lined to '''more''' in order to display a more systematic multi-page output of the variable list. |
|- | |- | ||
|02:31 | |02:31 | ||
− | |To see only the environment variables run the command '''env''' | + | |To see only the environment variables, '''run''' the command ''''env''''. |
|- | |- | ||
|02:38 | |02:38 | ||
− | |Type at the terminal'''env''' space 'vertical-bar' '''more''' and press | + | |Type at the terminal: '''env''' space 'vertical-bar' '''more''' and press Enter. |
|- | |- | ||
|02:46 | |02:46 | ||
− | |For example, | + | |For example, notice the '''SHELL''' variable whose value is '''slash bin slash bash'''. |
|- | |- | ||
|02:53 | |02:53 | ||
Line 85: | Line 79: | ||
|- | |- | ||
|03:00 | |03:00 | ||
− | |Now let us discuss some of the more important environment variables in | + | |Now, let us discuss some of the more important environment variables in Linux. |
|- | |- | ||
|03:05 | |03:05 | ||
− | |We would be using bash shell for all our demonstrations here. | + | |We would be using '''bash shell''' for all our demonstrations here. |
|- | |- | ||
|03:09 | |03:09 | ||
Line 94: | Line 88: | ||
|- | |- | ||
|03:12 | |03:12 | ||
− | |To see what a variable actually stores we have to prefix a dollar sign to the name of that variable and use the '''echo''' command along with it. | + | |To see what a variable actually stores, we have to prefix a dollar sign to the name of that variable and use the '''echo''' command along with it. |
|- | |- | ||
|03:24 | |03:24 | ||
Line 103: | Line 97: | ||
|- | |- | ||
|03:31 | |03:31 | ||
− | |To see what is the value of the '''SHELL''' variable, type at the terminal '''echo''' space '''dollar S-H-E-L-L''' in capitals and press ''' | + | |To see what is the value of the '''SHELL''' variable, type at the terminal: '''echo''' space '''dollar S-H-E-L-L''' in capitals and press '''Enter.''' |
|- | |- | ||
|03:48 | |03:48 | ||
− | |Here '''slash bin slash bash''' is the shell where we are currently operating. | + | |Here, '''slash bin slash bash''' is the shell where we are currently operating. |
|- | |- | ||
|03:56 | |03:56 | ||
Line 115: | Line 109: | ||
|- | |- | ||
|04:04 | |04:04 | ||
− | |This directory is called the home directory and this is exactly what is available in HOME variable. | + | |This directory is called the '''home''' directory and this is exactly what is available in the 'HOME' variable. |
|- | |- | ||
|04:10 | |04:10 | ||
− | |To see the value, type at the terminal '''echo''' space '''dollar H-O-M-E''' in capital and press ''' | + | |To see the value, type at the terminal: '''echo''' space '''dollar H-O-M-E''' in capital and press '''Enter'''. |
|- | |- | ||
|04:22 | |04:22 | ||
Line 124: | Line 118: | ||
|- | |- | ||
|04:26 | |04:26 | ||
− | |The '''PATH''' variable contains the absolute | + | |The '''PATH''' variable contains the '''absolute path'''s of the directories that the shell is supposed to search for locating any executable command. |
|- | |- | ||
|04:33 | |04:33 | ||
− | | | + | |Let's see the value of the '''path''' variable. |
|- | |- | ||
|04:36 | |04:36 | ||
− | |Again, type at the terminal '''echo''' space '''dollar P-A-T-H ''' in capitals and press | + | |Again, type at the terminal: '''echo''' space '''dollar P-A-T-H ''' in capitals and press Enter. |
|- | |- | ||
|04:45 | |04:45 | ||
− | |On my computer it shows '''slash user slash local slash | + | |On my computer, it shows '''slash user slash local slash bin slash user slash bin''' etc. |
|- | |- | ||
|04:57 | |04:57 | ||
|This may slightly vary from one system to another. | |This may slightly vary from one system to another. | ||
− | |||
|- | |- | ||
|05:00 | |05:00 | ||
− | |It is actually a list of directories separated by the :(colon) delimiter, that the shell would search in this order for finding an executable command. | + | |It is actually a list of directories separated by the :(colon) delimiter, that the '''shell''' would search in this order for finding an executable command. |
|- | |- | ||
|05:11 | |05:11 | ||
Line 146: | Line 139: | ||
|- | |- | ||
|05:18 | |05:18 | ||
− | |In order to add our own directory type at the terminal | + | |In order to add our own directory, type at the terminal: |
|- | |- | ||
|05:22 | |05:22 | ||
− | |'''P-A-T-H''' in capitals 'equal-to' '''dollar P-A-T-H''' again in capital '''colon slash home slash''' the name of my own home directory and press | + | |'''P-A-T-H''' in capitals 'equal-to' '''dollar P-A-T-H''' again in capital '''colon slash home slash''' the name of my own home directory and press Enter. |
|- | |- | ||
|05:47 | |05:47 | ||
− | |Now if we '''echo''' the value of '''PATH''', | + | |Now, if we '''echo''' the value of '''PATH''', |
|- | |- | ||
|05:57 | |05:57 | ||
− | | | + | |our added directory will also be a part of the '''PATH''' variable. |
|- | |- | ||
|06:03 | |06:03 | ||
− | |See the directory is now present here. | + | |See, the directory is now present here. |
|- | |- | ||
|06:09 | |06:09 | ||
Line 167: | Line 160: | ||
|- | |- | ||
|06:16 | |06:16 | ||
− | |In order to see the value type '''echo''' space '''dollar LOGNAME''' and press ''' | + | |In order to see the value, type: '''echo''' space '''dollar LOGNAME''' and press '''Enter.''' |
|- | |- | ||
|06:28 | |06:28 | ||
− | |When we open the terminal we can see the dollar sign | + | |When we open the '''terminal''', we can see the dollar sign which is the '''prompt''' at which we enter all our commands. |
|- | |- | ||
|06:35 | |06:35 | ||
− | |This is the primary prompt string represented by the environment variable PS1. | + | |This is the '''primary prompt string''' represented by the environment variable 'PS1'. |
|- | |- | ||
|06:40 | |06:40 | ||
− | |There is a secondary prompt string also | + | |There is a secondary prompt '''string''' also. |
|- | |- | ||
|06:43 | |06:43 | ||
− | |If our command is long and it spans for more than one line then from the second line onwards we can see a greater than sign “>” as the prompt | + | |If our command is long and it spans for more than one line then from the second line onwards we can see a greater than sign “>” as the prompt. |
|- | |- | ||
|06:53 | |06:53 | ||
− | |This is the secondary prompt string represented by the environment variable PS2. | + | |This is the '''secondary prompt string''' represented by the environment variable 'PS2'. |
|- | |- | ||
|06:58 | |06:58 | ||
− | |To see the value of the secondary command prompt, type at the terminal '''echo''' space '''dollar PS2''' and press ''' | + | |To see the value of the 'secondary command prompt', type at the terminal: '''echo''' space '''dollar PS2''' and press '''Enter.''' |
|- | |- | ||
|07:13 | |07:13 | ||
− | |We may change our primary prompt string to say “at the rate” (@) at the prompt. | + | |We may change our 'primary prompt string' to say “at the rate” (@) at the prompt. |
|- | |- | ||
|07:20 | |07:20 | ||
− | |In order to get this done | + | |In order to get this done, type: ''' PS1''' 'equal-to' now within quotes 'at the rate(@)' “ and press Enter. |
|- | |- | ||
|07:34 | |07:34 | ||
− | |Now instead of the '''dollar''' sign we can see the '''at the rate''' sign as the prompt. | + | |Now, instead of the '''dollar''' sign we can see the '''at the rate''' sign as the prompt. |
|- | |- | ||
|07:43 | |07:43 | ||
− | |We may do something more interesting | + | |We may do something more interesting like- we may display our username at the prompt. |
|- | |- | ||
|07:49 | |07:49 | ||
− | |Just type '''PS1''' in capital 'equal-to' within quotes '''dollar LOGNAME''' and press ''' | + | |Just type: '''PS1''' in capital 'equal-to' within quotes '''dollar LOGNAME''' and press '''Enter'''. |
|- | |- | ||
|08:05 | |08:05 | ||
− | |Now my username is my prompt. | + | |Now, my username is my prompt. |
|- | |- | ||
|08:09 | |08:09 | ||
− | |To revert back type '''PS1''' 'equal-to' dollar within quotes and press | + | |To revert back, type: '''PS1''' 'equal-to' dollar ($) within quotes and press Enter. |
|- | |- | ||
|08:21 | |08:21 | ||
Line 212: | Line 205: | ||
|- | |- | ||
|08:25 | |08:25 | ||
− | |But, remember one thing that these modifications are only applicable for the current session | + | |But, remember one thing that these modifications are only applicable for the current session |
|- | |- | ||
|08:30 | |08:30 | ||
− | | | + | |like we had just added our directory to the '''PATH''' variable. |
|- | |- | ||
|08:34 | |08:34 | ||
− | |If we close the terminal and open it again or open a new terminal altogether and check the path variable by echoing its value | + | |If we close the terminal and open it again or open a new terminal altogether and check the 'path' variable by echoing its value, |
|- | |- | ||
|08:53 | |08:53 | ||
− | | | + | |we will be surprised to see that our modifications are no longer present. |
|- | |- | ||
|08:59 | |08:59 | ||
Line 233: | Line 226: | ||
|- | |- | ||
|09:19 | |09:19 | ||
− | |First, normally if you press the up | + | |First, normally if you press the up-key on your keyboard then it will show the last command that you have typed. |
|- | |- | ||
|09:26 | |09:26 | ||
Line 239: | Line 232: | ||
|- | |- | ||
|09:30 | |09:30 | ||
− | |To go back press the down key. | + | |To go back, press the down-key. |
|- | |- | ||
|09:36 | |09:36 | ||
− | |But when you have to scroll through many commands this becomes a little clumsy and tedious. A better way is to use the '''history''' command. | + | |But when you have to scroll through many commands, this becomes a little clumsy and tedious. A better way is to use the '''history''' command. |
|- | |- | ||
|09:45 | |09:45 | ||
Line 248: | Line 241: | ||
|- | |- | ||
|09:51 | |09:51 | ||
− | |and press | + | |and press Enter; see a list of previously executed commands appears. |
|- | |- | ||
|09:57 | |09:57 | ||
− | |If instead of the large list you | + | |If instead of the large list, you wanted to see only the last ten, |
|- | |- | ||
|10:02 | |10:02 | ||
− | | | + | |type: '''history space 10''' and press ''Enter'''. |
|- | |- | ||
|10:13 | |10:13 | ||
Line 260: | Line 253: | ||
|- | |- | ||
|10:20 | |10:20 | ||
− | |In order to repeat a particular command | + | |In order to repeat a particular command, |
|- | |- | ||
|10:24 | |10:24 | ||
− | | | + | |just type an exclamation mark followed by the number of the command. For example- 442 in my case, would execute '''echo space dollar PATH'''. |
|- | |- | ||
|10:44 | |10:44 | ||
− | |If you need to re execute the last command simply type exclamation mark twice and press | + | |If you need to re-execute the last command, simply type exclamation mark twice and press Enter. |
|- | |- | ||
|10:56 | |10:56 | ||
− | |The next thing we would see is called tilde substitution. The tilde(~) character is a shorthand for the home directory. | + | |The next thing we would see is called '''tilde''' substitution. The '''tilde'''(~) character is a shorthand for the '''home directory'''. |
|- | |- | ||
|11:05 | |11:05 | ||
− | |So say you have a directory with name testtree in your home directory. You can move to it by typing '''cd''' space '''~(tilde)''' slash '''testtree'''. | + | |So, say you have a directory with the name 'testtree' in your home directory. You can move to it by typing: '''cd''' space '''~(tilde)''' slash '''testtree'''. |
|- | |- | ||
|11:18 | |11:18 | ||
− | |One may also toggle between the current working directory and the last directory used by giving the command | + | |One may also toggle between the current working directory and the last directory used by giving the command: |
'''cd '~(tilde)' minus''' or only '''cd minus''' | '''cd '~(tilde)' minus''' or only '''cd minus''' | ||
|- | |- | ||
|11:28 | |11:28 | ||
− | |Like now that we are in the '''testtree''' directory, the last directory we visited was the home directory. | + | |Like now that we are in the '''testtree''' directory, the last directory we visited was the '''home''' directory. |
|- | |- | ||
|11:34 | |11:34 | ||
− | |So if we run '''cd space minus''' and press | + | |So, if we '''run''' '''cd space minus''' and press Enter, it will go to the '''home''' directory. |
|- | |- | ||
|11:40 | |11:40 | ||
− | |Run it again and it will take us back to the '''testtree''' directory. | + | |'''Run''' it again and it will take us back to the '''testtree''' directory. |
|- | |- | ||
|11:47 | |11:47 | ||
Line 291: | Line 284: | ||
|- | |- | ||
|11:51 | |11:51 | ||
− | |It may happen that you have a large command that needs to be run again and again. | + | |It may quite happen that you have a large command that needs to be run again and again. |
|- | |- | ||
|11:57 | |11:57 | ||
− | |In this case we can give it a short '''alias''' name and use the '''alias''' name instead | + | |In this case, we can give it a short '''alias''' name and use the '''alias''' name instead to invoke it. |
|- | |- | ||
|12:03 | |12:03 | ||
− | |Assuming that you have such a long directory hierarchy that you frequently visit for music, you may create an alias for it like this | + | |Assuming that you have such a long directory hierarchy that you frequently visit for music, you may create an alias for it like this. |
|- | |- | ||
|12:13 | |12:13 | ||
− | |Type '''alias''' space '''cdMusic''' 'equal-to' within double quotes '''cd''' space '''slash home slash the name of my own home directory slash music ''' and press | + | |Type: '''alias''' space '''cdMusic''' 'equal-to' within double quotes '''cd''' space '''slash home slash the name of my own home directory slash music ''' and press Enter. |
|- | |- | ||
|12:39 | |12:39 | ||
− | |Now every time you need to switch to this directory simply write '''cdMusic''' and press | + | |Now, every time you need to switch to this directory, simply write '''cdMusic''' and press Enter. |
|- | |- | ||
|12:47 | |12:47 | ||
Line 309: | Line 302: | ||
|- | |- | ||
|12:52 | |12:52 | ||
− | |Now, you may type '''cd space minus | + | |Now, you may type '''cd space minus ''' and the prompt to go back to the previous working directory. |
− | ''' and the prompt to go back to the previous working directory. | + | |
|- | |- | ||
|13:01 | |13:01 | ||
− | |To unset an '''alias''' simply write '''unalias space cdMusic''' and press | + | |To unset an '''alias''', simply write '''unalias space cdMusic''' and press Enter. |
|- | |- | ||
|13:13 | |13:13 | ||
− | |Now again if you fire '''cdMusic''' from the terminal, you will get an error stating that the command was not found. | + | |Now again if you fire '''cdMusic''' from the terminal, you will get an '''error''' stating that the command was not found. |
|- | |- | ||
|13:22 | |13:22 | ||
− | |Suppose we have two files | + | |Suppose, we have two files- '''test1''' and '''test2''' in our present working directory |
|- | |- | ||
|13:31 | |13:31 | ||
Line 328: | Line 320: | ||
|- | |- | ||
|13:45 | |13:45 | ||
− | |So we may set an '''alias''' like, '''alias rm''' equal-to, now within quotes '''rm space hyphen i''' | + | |So, we may set an '''alias''' like, '''alias rm''' equal-to, now within quotes '''rm space hyphen i'''. |
|- | |- | ||
|13:56 | |13:56 | ||
− | |Now when we run '''rm''' ,''' rm hyphen i'''will actually be run. | + | |Now, when we run '''rm''', '''rm hyphen i''' will actually be '''run'''. |
|- | |- | ||
|14:05 | |14:05 | ||
− | |So we saw that while '''test1''' was silently deleted, system asked before deleting '''test2.''' | + | |So, we saw that while '''test1''' was silently deleted, system asked before deleting '''test2.''' |
|- | |- | ||
|14:13 | |14:13 | ||
− | |So, in this tutorial, we have learned about environment variables, history and aliasing. | + | |So, in this tutorial, we have learned about '''environment variables, history''' and '''aliasing'''. |
|- | |- | ||
|14:18 | |14:18 | ||
Line 343: | Line 335: | ||
|- | |- | ||
|14:21 | |14:21 | ||
− | |Spoken Tutorials are a part of the Talk to a Teacher project, supported by the National Mission on Education through ICT. | + | |'''Spoken Tutorials''' are a part of the '''Talk to a Teacher''' project, supported by the National Mission on Education through ICT. |
|- | |- | ||
|14:29 | |14:29 | ||
Line 349: | Line 341: | ||
|- | |- | ||
|14:32 | |14:32 | ||
− | |The Script for this tutorial was created by Anirban | + | |The Script for this tutorial was created by Anirban. |
|- | |- | ||
|14:36 | |14:36 | ||
− | |This | + | |This Anuvrath Parashar from MIT university, signing off. |
|} | |} |
Latest revision as of 12:27, 24 March 2017
Time | Narration |
00:01 | Welcome to this spoken tutorial on the Linux environment and ways to manipulate it. |
00:07 | A working Linux system will be required to try out the examples illustrated in this tutorial. |
00:12 | We assume that you know how to get started with the Linux operating system and have some basic idea about commands, file systems and shell. |
00:20 | If you are interested or need to brush these concepts up, please feel free to do so through another spoken tutorial available on our website. |
00:30 | Please note that Linux is case sensitive and all the commands used in this tutorial are in lower case unless otherwise mentioned. |
00:40 | The Linux environment determines how the operating system behaves with you, how it responds to your commands, how it interprets your actions and so on. |
00:48 | Linux can be highly customized by changing the settings of the shell. |
00:51 | Let us understand how all this can be done. |
00:54 | The behavior of the shell is generally determined by the shell variables. |
00:58 | There are mainly two kinds of shell variables: Environment Variables and Local Variables. |
01:06 | Environment variables, named so because they are available entirely in the user's total environment. |
01:12 | These are also available in sub-shells spawned by the shell like the ones for running shell scripts. |
01:18 | Local Variables which as the name suggests have a more restricted or limited availability. |
01:24 | These are not available in the sub-shells spawned by the shell. |
01:28 | While in this tutorial, we will mainly talk about environment variables. Let us first see how the value of these shell variables can be seen. |
01:41 | To see all the variables available in the current shell, we run the command 'set'. |
01:46 | Type at the terminal: set space pipeline character more and press Enter. |
01:53 | We can see all the current shell variables. , |
01:58 | For example- take a look at the HOME environment variable; also notice the value assigned to it. |
02:07 | Press Enter to move through the list and in order to come out, press q. |
02:14 | Here, the output from set was pipe-lined to more in order to display a more systematic multi-page output of the variable list. |
02:31 | To see only the environment variables, run the command 'env'. |
02:38 | Type at the terminal: env space 'vertical-bar' more and press Enter. |
02:46 | For example, notice the SHELL variable whose value is slash bin slash bash. |
02:53 | Again, you may press q to come out of the list. |
03:00 | Now, let us discuss some of the more important environment variables in Linux. |
03:05 | We would be using bash shell for all our demonstrations here. |
03:09 | Different shells are customized in slightly different ways. |
03:12 | To see what a variable actually stores, we have to prefix a dollar sign to the name of that variable and use the echo command along with it. |
03:24 | The first environment variable that we would see is the SHELL variable. |
03:28 | It stores the name of the current shell. |
03:31 | To see what is the value of the SHELL variable, type at the terminal: echo space dollar S-H-E-L-L in capitals and press Enter. |
03:48 | Here, slash bin slash bash is the shell where we are currently operating. |
03:56 | The next variable is HOME. |
03:58 | When we login into Linux, it normally places us in a directory named after our user name. |
04:04 | This directory is called the home directory and this is exactly what is available in the 'HOME' variable. |
04:10 | To see the value, type at the terminal: echo space dollar H-O-M-E in capital and press Enter. |
04:22 | The next environment variable is PATH. |
04:26 | The PATH variable contains the absolute paths of the directories that the shell is supposed to search for locating any executable command. |
04:33 | Let's see the value of the path variable. |
04:36 | Again, type at the terminal: echo space dollar P-A-T-H in capitals and press Enter. |
04:45 | On my computer, it shows slash user slash local slash bin slash user slash bin etc. |
04:57 | This may slightly vary from one system to another. |
05:00 | It is actually a list of directories separated by the :(colon) delimiter, that the shell would search in this order for finding an executable command. |
05:11 | We can also add our own directory to this list so that our directory is also searched by the shell. |
05:18 | In order to add our own directory, type at the terminal: |
05:22 | P-A-T-H in capitals 'equal-to' dollar P-A-T-H again in capital colon slash home slash the name of my own home directory and press Enter. |
05:47 | Now, if we echo the value of PATH, |
05:57 | our added directory will also be a part of the PATH variable. |
06:03 | See, the directory is now present here. |
06:09 | Another interesting variable is the LOGNAME. |
06:12 | It stores the username of the currently active user. |
06:16 | In order to see the value, type: echo space dollar LOGNAME and press Enter. |
06:28 | When we open the terminal, we can see the dollar sign which is the prompt at which we enter all our commands. |
06:35 | This is the primary prompt string represented by the environment variable 'PS1'. |
06:40 | There is a secondary prompt string also. |
06:43 | If our command is long and it spans for more than one line then from the second line onwards we can see a greater than sign “>” as the prompt. |
06:53 | This is the secondary prompt string represented by the environment variable 'PS2'. |
06:58 | To see the value of the 'secondary command prompt', type at the terminal: echo space dollar PS2 and press Enter. |
07:13 | We may change our 'primary prompt string' to say “at the rate” (@) at the prompt. |
07:20 | In order to get this done, type: PS1 'equal-to' now within quotes 'at the rate(@)' “ and press Enter. |
07:34 | Now, instead of the dollar sign we can see the at the rate sign as the prompt. |
07:43 | We may do something more interesting like- we may display our username at the prompt. |
07:49 | Just type: PS1 in capital 'equal-to' within quotes dollar LOGNAME and press Enter. |
08:05 | Now, my username is my prompt. |
08:09 | To revert back, type: PS1 'equal-to' dollar ($) within quotes and press Enter. |
08:21 | We have assigned values to many of the environment variables. |
08:25 | But, remember one thing that these modifications are only applicable for the current session |
08:30 | like we had just added our directory to the PATH variable. |
08:34 | If we close the terminal and open it again or open a new terminal altogether and check the 'path' variable by echoing its value, |
08:53 | we will be surprised to see that our modifications are no longer present. |
08:59 | The way by which we can make these modifications permanent will be covered in some advanced tutorial. |
09:06 | Often we want to re-execute a command that we had executed in the recent past. What do we do? Do we have to type the entire command again? |
09:15 | No, there are a number of solutions. |
09:19 | First, normally if you press the up-key on your keyboard then it will show the last command that you have typed. |
09:26 | Keep pressing it and it will keep scrolling through the previous commands. |
09:30 | To go back, press the down-key. |
09:36 | But when you have to scroll through many commands, this becomes a little clumsy and tedious. A better way is to use the history command. |
09:45 | Type at the prompt history |
09:51 | and press Enter; see a list of previously executed commands appears. |
09:57 | If instead of the large list, you wanted to see only the last ten, |
10:02 | type: history space 10' and press Enter. |
10:13 | Notice, in this list, there is a number assigned to each of the previously executed commands. |
10:20 | In order to repeat a particular command, |
10:24 | just type an exclamation mark followed by the number of the command. For example- 442 in my case, would execute echo space dollar PATH. |
10:44 | If you need to re-execute the last command, simply type exclamation mark twice and press Enter. |
10:56 | The next thing we would see is called tilde substitution. The tilde(~) character is a shorthand for the home directory. |
11:05 | So, say you have a directory with the name 'testtree' in your home directory. You can move to it by typing: cd space ~(tilde) slash testtree. |
11:18 | One may also toggle between the current working directory and the last directory used by giving the command:
cd '~(tilde)' minus or only cd minus |
11:28 | Like now that we are in the testtree directory, the last directory we visited was the home directory. |
11:34 | So, if we run cd space minus and press Enter, it will go to the home directory. |
11:40 | Run it again and it will take us back to the testtree directory. |
11:47 | The last but quite important command we will see is the alias command. |
11:51 | It may quite happen that you have a large command that needs to be run again and again. |
11:57 | In this case, we can give it a short alias name and use the alias name instead to invoke it. |
12:03 | Assuming that you have such a long directory hierarchy that you frequently visit for music, you may create an alias for it like this. |
12:13 | Type: alias space cdMusic 'equal-to' within double quotes cd space slash home slash the name of my own home directory slash music and press Enter. |
12:39 | Now, every time you need to switch to this directory, simply write cdMusic and press Enter. |
12:47 | See, we are in the music directory now. |
12:52 | Now, you may type cd space minus and the prompt to go back to the previous working directory. |
13:01 | To unset an alias, simply write unalias space cdMusic and press Enter. |
13:13 | Now again if you fire cdMusic from the terminal, you will get an error stating that the command was not found. |
13:22 | Suppose, we have two files- test1 and test2 in our present working directory |
13:31 | and if we fire rm test1, test1 is silently deleted. |
13:38 | We know that hyphen i option of the rm command makes the removal process interactive. |
13:45 | So, we may set an alias like, alias rm equal-to, now within quotes rm space hyphen i. |
13:56 | Now, when we run rm, rm hyphen i will actually be run. |
14:05 | So, we saw that while test1 was silently deleted, system asked before deleting test2. |
14:13 | So, in this tutorial, we have learned about environment variables, history and aliasing. |
14:18 | This brings me to the end of this tutorial. |
14:21 | Spoken Tutorials are a part of the Talk to a Teacher project, supported by the National Mission on Education through ICT. |
14:29 | More information on the same is available from our website. |
14:32 | The Script for this tutorial was created by Anirban. |
14:36 | This Anuvrath Parashar from MIT university, signing off. |