BOSS-Linux/C2/The-Linux-Environment/English-timed

From Script | Spoken-Tutorial
Revision as of 11:51, 4 December 2014 by Gaurav (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Time Narration
00:01 Welcome to this spoken tutorial on the Linux environment and ways to manupulate 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 also 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 behaviour 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 subshells 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 subshells 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 pipelined to more in order to display a more systematic multipage output of the variable list.
02:31 To see only the environment variables run the command env
02:38 Type at the terminalenv 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 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 Lets 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 sbin 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 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 want 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 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 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 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 iwill 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 Anugrath Parashah from MIT university signing off.

Contributors and Content Editors

Gaurav, PoojaMoolya, Pratik kamble, Sandhya.np14