Difference between revisions of "Linux/C2/The-Linux-Environment/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
Line 176: Line 176:
 
|-
 
|-
 
|06:47
 
|06:47
|There is a secondary prompt string also
+
|There is a secondary prompt string also.
 
|-
 
|-
 
|06:50
 
|06:50
Line 206: Line 206:
 
|-
 
|-
 
|08:16
 
|08:16
|To revert back, type: '''PS1''' 'equal-to' dollar within quotes and press Enter."
+
|To revert back, type: '''PS1''' 'equal-to' dollar within quotes and press Enter.
 
|-
 
|-
 
|08:28
 
|08:28
Line 251: Line 251:
 
|-
 
|-
 
|10:04  
 
|10:04  
|If instead of the large list you want to see, only the last ten  
+
|If instead of the large list you want to see only the last ten,
 
|-
 
|-
 
|10:08  
 
|10:08  
|Type '''history space 10''' and press ''Enter'''.
+
|type '''history space 10''' and press ''Enter'''.
 
|-
 
|-
 
|10:20  
 
|10:20  
Line 260: Line 260:
 
|-
 
|-
 
|10:27
 
|10:27
|In order to repeat a particular command.
+
|In order to repeat a particular command,
 
|-
 
|-
 
|10:32
 
|10:32
|Just type exclamation mark followed by the number of the command for example 442 in my case would execute '''echo space dollar PATH'''  
+
|just type exclamation mark followed by the number of the command for example 442 in my case would execute '''echo space dollar PATH'''  
 
|-
 
|-
 
|10:51  
 
|10:51  
Line 300: Line 300:
 
|-
 
|-
 
|12:20
 
|12:20
|Type: '''alias''' space '''cdMusic''' 'equal-to' within double quotes '''cd''' space '''slash home slash arc slash files slash entertainment slash music ''' and press Enter.
+
|Type: '''alias''' space '''cdMusic''' 'equal-to' within double quotes '''cd space slash home slash arc slash files slash entertainment slash music''' and press Enter.
 
|-
 
|-
 
|12:47  
 
|12:47  
Line 331: Line 331:
 
|-
 
|-
 
|14:03
 
|14:03
|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:13  
 
|14:13  

Revision as of 16:06, 12 March 2015

Time Narration
00:00 Welcome to this spoken tutorial on The Linux Environment and ways to manipulate it.
00:07 A working Linux system, preferably Ubuntu will be required to try out the examples illustrated in this tutorial.
00:13 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:22 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:32 Please note that Ubuntu 10.10 was used for recording this tutorial.
00:36 Please also note that Linux is case sensitive and all the commands used in this tutorial are in lower case unless otherwise mentioned.
00:46 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:55 Linux can be highly customized by changing the settings of the shell.
00:58 Let us understand how all this can be done.
00:59 The behavior of the shell is generally determined by the shell variables.
01:04 There are mainly two kinds of shell variables:

Environment Variables and Local Variables.

01:12 Environment variables, named so because they are available entirely in the user's total environment.
01:19 These are also available in sub-shells spawned by the shell like the ones for running shell scripts.
01:24 Local Variables, which as the name suggests, have a more restricted or limited availability.
01:31 These are not available in the sub-shells spawned by the shell.
01:36 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:48 To see all the variables available in the current shell, we run the command set.
01:53 Type at the terminal: set space pipeline character more and press Enter.
02:00 We can see all the current shell variables.
02:04 For example: take a look at the HOME environment variable, also notice the value assigned to it.
02:15 Press Enter to move through the list and in order to come out press q.
02:21 Here, the output from set was pipelined to more in order to display a more systematic multipage output of the variable list.
02:38 To see only the environment variables, run the command env.
02:45 Type at the terminal:env space 'vertical-bar' more and press Enter.
02:52 For example,

notice the SHELL variable whose value is slash bin slash bash.

03:00 Again, you may press q to come out of the list.
03:07 Now let us discuss some of the more important environment variables in Linux.
03:11 We would be using the bash shell for all our demonstrations here.
03:15 Different shells are customized in slightly different ways.
03:19 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:30 The first environment variable that we would see is the SHELL variable.
03:35 It stores the name of the current shell.
03:37 To see what is the value of the SHELL variable, type at the terminal: echo space dollar S-H-E-L-L in capital and press Enter.
03:55 Here, slash bin slash bash is the shell where we are currently operating.
04:02 The next variable is HOME.
04:05 When we login into Linux, it normally places us in a directory named after our user name.
04:11 This directory is called the 'home directory' and this is exactly what is available in 'HOME' variable.
04:17 To see the value, type at the terminal: echo space dollar H-O-M-E in capital and press Enter.
04:29 The next environment variable is PATH.
04:32 The PATH variable contains the absolute paths of the directories that the shell is supposed to search for locating any executable command.
04:40 Let's see the value of the path variable.
04:43 Again, type at the terminal: echo space dollar P-A-T-H in capitals and press Enter.
04:51 On my computer it shows slash user slash local slash sbin slash user slash local slash bin slash user slash sbin slash user slash bin etc.
05:04 This may slightly vary from one system to another.
05:07 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:18 We can also add our own directory to this list so that our directory is also searched by the shell.
05:25 In order to add our own directory type at the terminal:
05:29 P-A-T-H in capital '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:54 Now if we echo the value of PATH,
06:04 our added directory will also be a part of the PATH variable.
06:10 See the directory is now present here.
06:16 Another interesting variable is the LOGNAME.
06:20 It stores the username of the currently active user.
06:24 In order to see the value, type: echo space dollar LOGNAME and press Enter.
06:35 When we open the terminal we can see the dollar sign which is the prompt at which we enter all our commands.
06:42 This is the primary prompt string represented by the environment variable 'PS1'.
06:47 There is a secondary prompt string also.
06:50 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.
07:00 This is the secondary prompt string represented by the environment variable 'PS2'.
07:05 To see the value of the secondary command prompt, type at the terminal: echo space dollar PS2 and press Enter.
07:20 We may change our primary prompt string to say “at the rate” <@> at the prompt.
07:28 In order to get this done, type PS1 'equal-to' now within quotes 'at the rate' “@"and press Enter.
07:41 Now instead of the dollar sign we can see the at the rate sign as the prompt.
07:50 We may do something more interesting. Like we may display our username at the prompt.
07:56 Just type: PS1 in capital 'equal-to' within quotes dollar LOGNAME and press Enter.
08:12 Now my username is my prompt.
08:16 To revert back, type: PS1 'equal-to' dollar within quotes and press Enter.
08:28 We have assigned values to many of the environment variables.
08:32 But, remember one thing that these modifications are only applicable for the current session.
08:37 Like we had just added our directory to the PATH variable.
08:40 If we close the terminal and open it again or open a new terminal altogether and check the path variable by echoing its value,
09:00 we will be surprised to see that our modifications are no longer present.
09:05 The way by which we can make these modifications permanent will be covered in some advanced tutorial.
09:13 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?
9:22 No, there are a number of solutions.
09:26 First, normally if you press the 'up key' on your keyboard then it will show the last command that you typed.
09:33 Keep pressing and it will keep scrolling through the previous commands.
09:37 To go back press the down key.
09:42 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:52 Type at the prompt history.
09:58 and press Enter, see a list of previously executed commands appear.
10:04 If instead of the large list you want to see only the last ten,
10:08 type history space 10' and press Enter.
10:20 Notice, in this list there is a number assigned to each of the previously executed commands.
10:27 In order to repeat a particular command,
10:32 just type exclamation mark followed by the number of the command for example 442 in my case would execute echo space dollar PATH
10:51 If you need to re-execute the last command simply type exclamation mark twice and press Enter.
11:03 The next thing we would see is called 'tilde' substitution. The tilde(~) character is a shorthand for the home directory.
11:12 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:25 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:35 Like now that we are in the testtree directory, the last directory we visited was the home directory.
11:41 So if we run cd space minus and press Enter, it will go to the home directory.
11:47 Run it again and it will take us back to the testtree directory.
11:55 The last but quite important command we will see is the alias command.
11:59 It may happen that you have a large command that needs to be run again and again.
12:04 In this case we can give it a short alias name and use the alias name instead, to invoke it.
12:11 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:20 Type: alias space cdMusic 'equal-to' within double quotes cd space slash home slash arc slash files slash entertainment slash music and press Enter.
12:47 Now every time you need to switch to this directory simply write cdMusic and press Enter.
12:55 See, we are in the music directory now.
12:58 Now, you may type cd space minus

at the prompt to go back to the previous working directory.

13:08 To unset an alias, simply write unalias space cdMusic and press Enter.
13:20 Now again if you fire cdMusic from the terminal, you will get an error stating that the command was not found.
13:30 Suppose we have two files, test1 and test2 in our present working directory
13:38 and if we fire rm test1, test1 is silently deleted.
13:45 We know that hyphen i option of the rm command makes the removal process interactive.
13:52 So we may set an alias like, alias rm equal-to, now within quotes rm space hyphen i
14:03 Now when we run rm ,rm hyphen iwill actually be run.
14:13 So we saw that while test1 was silently deleted, system asked before deleting test2.
14:20 So, in this tutorial, you have learned about environment variables, history and aliasing.
14:25 This brings me to the end of this tutorial.
14:28 Spoken Tutorials are a part of the Talk to a Teacher project, supported by the National Mission on Education through ICT.
14:36 More information on the same is available from our website.
14:39 The Script for this tutorial was created by Anirban.
14:42 This script has been contributed by ----------------------(name of the translator) and this is -----------------------(name of the recorder) from --------------------------(name of the place)signing off.

Contributors and Content Editors

Minal, PoojaMoolya, Pratik kamble, Sandhya.np14