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

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with "Pending")
 
 
Line 1: Line 1:
Pending
+
'''Title of script''': The Linux Environment
 +
 
 +
'''Author : Anirban Roy Choudhury'''
 +
 
 +
'''Keywords:  '''Environment variables, local variables, PATH,HOME, profile, history, alias
 +
 
 +
 
 +
 
 +
Resources for the tutorial: [[File:Resources.zip]]
 +
{| style="border-spacing:0;"
 +
| style="border-top:0.035cm solid #000000;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| <center>'''Visual Cue'''</center>
 +
| style="border:0.035cm solid #000000;padding:0.097cm;"|
 +
<center>'''Narration'''</center>
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| Display Slide 1
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| Welcome to this spoken tutorial on the Linux environment and ways to manupulate it.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| Display Slide 2
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| A working linux system, preferably Ubuntu will be required to try out the examples illsutrated in this tutorial.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| 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 .
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| 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.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| Please note that Ubuntu 10.10 was used for recording this tutorial.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| Please also note that Linux is case sensitive and all the commands used in this tutorial are in lower case unless otherwise mentioned.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| Display Slide 3
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| 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.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| Linux can be highly customized by changing the settings of the shell.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| Let us understand how all this can be done.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| Slide 3 (continued)
 +
 
 +
 
 +
 
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| The behaviour of the shell is generally determined by the shell variables.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| There are two main kinds of shell variables:
 +
 
 +
Environment Variables
 +
 
 +
Local Variables
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| Slide 4
 +
 
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| Environment variables, named so because they are available entirely in the user's total environment. These are also available in subshells spawned by the shell like for running shell scripts.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| Local Variables , which as the name suggests have a more restricted or limited availability. These are not available to the subshells created by the shell.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| While in this tutorial, we will mainly talk about environment variables, let us first see how the value of these variables can be seen.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| Open a terminal
 +
 
 +
'''Type at the command prompt'''
 +
 
 +
"set | more"
 +
 
 +
press enter
 +
 
 +
 
 +
 
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| To see all the variables available in the current shell , we run the command set. '''Type at the terminal'''
 +
 
 +
"set 'pipeline character' more" and press enter.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| We can see all the current shell variables ,
 +
 
 +
|-
 +
Find the HOME variable from the list and hover mouse over variable and the value after the '=' sign respectively]
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| For example : take a look at the HOME environment variable also notice the value assigned to it.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| press  enter
 +
 
 +
press q
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| press Enter to move through the list , to come out press q
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| Use up arrow key to move back through history and highlight the pipeline character
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| Here the output from set was pipelined to more in order to show a more systematic multipage output of the variable list.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| '''->Environment Variables'''
 +
 
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| To see only the environment variables run the command env
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| '''Type at the command prompt'''
 +
 
 +
"env | more"
 +
 
 +
press enter
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| '''Type at the terminal'''
 +
 
 +
"env space 'vertical-bar' more"
 +
 
 +
|-
 +
point the mouse to
 +
 
 +
SHELL=/bin/bash ]
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| For example,
 +
 
 +
Notice the SHELL variable whose value is /bin/bash .
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| press q
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| Again, you may press q to come out of the list.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
 
 +
 
 +
 
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| Now let us discuss some of the more important environment variables in linux.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| We would be using the bash shell for all our demonstrations here.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| Different shells are customized in slightly different ways.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| 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.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| '''Type at the command prompt'''
 +
 
 +
"echo $SHELL"
 +
 
 +
press enter
 +
 
 +
 
 +
 
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| The first environment variable that we would see is the SHELL variable.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| It stores the name of the current shell.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| To see what is the value of the SHELL variable, type at the terminal "echo space dollar SHELL in capital"and press enter.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| Here /bin/bash is the shell where we are currently operating.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| '''Type at the command prompt'''
 +
 
 +
"echo $HOME"
 +
 
 +
press  enter
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| The next variable is the HOME.
 +
 
 +
 
 +
 
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| When we login into Linux, it normally places us in a directory named after our user name.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| This directory is called the home directory and this is exactly what is available in HOME variable.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| To see the value, type at the terminal "echo space dollar HOME in capital"and press enter
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| '''-The Path Variable'''
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| The next environment variable is the PATH.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| '''Type at the command prompt'''
 +
 
 +
 
 +
"echo $PATH"
 +
 
 +
press enter
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| The PATH variable contains the absolute paths of the directories that the shell is supposed to search for locating any executabe command.
 +
 
 +
Lets see the value of the path variable.
 +
 
 +
Again, type at the terminal "echo space dollar PATH [in capitals]"
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| On my computer it shows the directories
 +
 
 +
/usr/local/bin:/usr/bin: etc.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| This may slightly vary from one system to other.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| 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.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| We can add our own directory to this list so that our directory is also searched by the shell.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| '''Type at the command prompt'''
 +
 
 +
"PATH=$PATH:/home/the_name_of_your_home_directory"
 +
 
 +
press enter
 +
 
 +
 
 +
 
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| In order to add our own directory type at the terminal "PATH [in capital] 'equal-to' dollar PATH again  [in capital] colon /home/ the_name_of_my_own_home_directory” and press enter.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| '''Type at the command prompt'''
 +
 
 +
"echo $PATH"
 +
 
 +
press enter
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| Now if we echo the value of PATH,
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| our added directory will also be a part of the PATH variable.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| select and hover over the change in value of path variable
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| See the directory is now present here.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| '''Type at the command prompt'''
 +
 
 +
"echo $LOGNAME"
 +
 
 +
press  enter
 +
 
 +
 
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| Another interesting variable is the LOGNAME.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| It stores the username of the currently active user.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| In order to see the value type "echo space dollar LOGNAME" and press enter.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| '''Type at the command prompt'''
 +
 
 +
" echo $PS2 "
 +
 
 +
press enter
 +
 
 +
 
 +
press enter a few times to highlight the change
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| When we open the terminal we can see the dollar sign, which is the prompt at which we enter all our commands.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| '''Type at the command prompt'''
 +
 
 +
" PS1="@" "
 +
 
 +
press enter
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| This is the primary prompt string represented by the environment variable PS1.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| press enter few times to highlight the change
 +
 
 +
 
 +
 
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| 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
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| This is the secondary prompt string represented by the environment variable PS2.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| To see the secondary command prompt, type at the terminal "echo space dollar PS2 [in capital]" and press enter.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| We may change our primary prompt string to say “at the rate” <@> at the prompt.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| '''Type at the command prompt'''
 +
 
 +
"PS1=$"
 +
 
 +
press enter
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| In order to get this done
 +
 
 +
Type "PS1 [in capital] 'equal-to' now withing quotes 'at the rate' “ and press enter.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| Now instead of the dollar sign we see an at the rate sign.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| We may do something more interesting. Like we may display our username as the prompt.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| '''Type at the command prompt'''
 +
 
 +
"PS1=$LOGNAME"
 +
 
 +
press enter
 +
 
 +
 
 +
 
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| Just type "PS1 in capital'equal-to' within quotes dollar LOGNAME " and press enter
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| Now my username is my prompt.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| To revert back type "PS1 'equal-to' dollar within quotes and press enter."
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| Open another tab in the terminal ctrl+shift+t
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| We have assigned values to many of the environment variables.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| But, remember one thing that these modifications are only applicable for the current session.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| '''Type at the command prompt'''
 +
 
 +
"echo $PATH"
 +
 
 +
press enter
 +
 
 +
 
 +
 
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| Like we had just added our directory to the PATH variable.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| If we close the terminal and open it again or open a new terminal altogether and check the path variable by echo-ing its value
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| we will be surprised to see that our modificaitons are no longer present.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| The way by which we can make these modifications permanent will be covered in some advanced tutorial.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| Display slide 4
 +
 
 +
 
 +
 
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| Often we want to re-execute a command we had executed in the recent past. What do we do? Do we have to type the entire command again? No, there are a number of solutions.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| Press up direction key
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| First, normally if you press the up direction key in your keyboard then it will show the last command that you typed.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| Keep pressing and it will keep scrolling through the previous commands.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| Press down direction key
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| To go back press the down direction key.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| 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.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| '''Type at the command prompt'''
 +
 
 +
"history"
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| Type at the prompt "history"
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| press enter
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| and press enter, see a list of previously executed commands appears
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| If instead of the large list you want to see, only the last ten
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| '''Type at the command prompt'''
 +
 
 +
"history 10"
 +
 
 +
press enter
 +
 
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| Type "history space 10" and press enter
 +
 
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| Notice, in this list, there is a number assigned to each of the previously executed commands.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| In order to repeat a particular command.
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| Take a random example
 +
 
 +
'''Type at the command prompt'''
 +
 
 +
"![number]"
 +
 
 +
type any number that you are getting in the list given by "history 10" command
 +
 
 +
press enter
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| Just type exclamation mark followed by the number of the command for example 442 in my case would execute echo space dollar path
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| '''Type at the command prompt'''
 +
 
 +
"!!"
 +
 
 +
press enter
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| If you need to execute the last command simply type exclamation mark twice and press enter.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| '''Tilde character Substitution'''
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| The next thing we would see is called tilde substitution
 +
 
 +
The tilde(~) charactar is a shorthand for the home directory.
 +
 
 +
|-
 +
create a directory named testtree in the home directory
 +
 
 +
 
 +
 
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| 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".
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| '''Type at the command prompt'''
 +
 
 +
"cd ~/testtree "
 +
 
 +
press enter
 +
 
 +
'''Run pwd to illustrate the change'''
 +
 
 +
 
 +
 
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| One may also toggle between the current working directory and the last directory used by giving the command
 +
 
 +
cd ~- [narration - cd space 'tilde' minus] or only cd - [ narration - cd space minus]
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| '''Type at the command prompt'''
 +
 
 +
"cd -"
 +
 
 +
press enter
 +
 
 +
 
 +
 
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| Like now that we are in the testtree directory, the last directory we visited was the home directory. 
 +
 
 +
So if we run "cd space minus" . It will go to the home directory.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| Press the up key and enter to re-execute the previous command.
 +
 
 +
 
 +
 
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| Run it again and you are back to the testtree directory.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| (Before the video create such a long directory hierarchy)
 +
 
 +
 
 +
 
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| The last but quite important command we will see is the alias command. It may happen that you have a large command that needs to be run again and again. In this case we can give it a short alias name and use the alias name instead ,to invoke it.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| Assuming that you have such a long directory hierarchy that you frequently visit for music, you may create an alias for it like this: \
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| '''Type at the command prompt'''
 +
 
 +
" alias cdMusic = "cd /home/arc/files/entertainment/music" "
 +
 
 +
press enter
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| Type " alias space cdMusic 'equal-to' within double quotoes cd space /home/arc/files/entertainment/music " and press enter
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| '''Type at the command prompt'''
 +
 
 +
"cdMusic"
 +
 
 +
press enter
 +
 
 +
Quickly run '''pwd''' to illustrate the effect of the previous command
 +
 
 +
 
 +
 
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| Now every time you need to switch to this directory simply write cdMusic and press enter. See, we are in the music directory now.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| '''Type at the command prompt'''
 +
 
 +
'''"cd -"'''
 +
 
 +
 
 +
 
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| Now, you may type at the prompt "cd space minus" to go back to the previous working directory.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| '''Type at the command prompt'''
 +
 
 +
"unalias cdMUsic"
 +
 
 +
press enter
 +
 
 +
 
 +
 
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| To unset this alias simply write unalias space cdMusic
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| '''Type at the command prompt'''
 +
 
 +
"cdMusic"
 +
 
 +
press  enter
 +
 
 +
 
 +
 
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| Now again if you fire cdMusic from the terminal, you will get an error stating that the command was not found.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| quickly run
 +
 
 +
'''touch test1 test2'''
 +
 
 +
to create test1 and test2 in the present working directory. Then run '''ls '''illustrate the change.
 +
 
 +
 
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| Suppose we have two files, test1 and test2 in our present working directory
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| '''Type at the command prompt '''
 +
 
 +
"rm test1"
 +
 
 +
press enter
 +
 
 +
 
 +
 
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| and if we fire rm test1, test1 is silently deleted.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| We know that the “hyphen i” option of the rm command can make the removal process interactive.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| '''Type at the command prompt'''
 +
 
 +
" alias rm ="rm -i" "
 +
 
 +
press  enter
 +
 
 +
 
 +
 
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| So we may set an alias like, alias rm equal-to, now within quotes “rm space -i”
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| '''Type at the command prompt'''
 +
 
 +
"rm test2"
 +
 
 +
press  enter
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| Now when we run “rm” ,” rm-i” will actually be run.\
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| So we saw that while test1 was silently deleted, system asked before deleting test2.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| '''Display Slide 5'''
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| So, in this tutorial, you have learned about environment variables, history and aliasing.
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"| '''Display Slide 6'''
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| This brings me to the end of this tutorial.
 +
 
 +
 
 +
 
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| Spoken Tutorials are a part of the Talk to a Teacher project, supported by the
 +
 
 +
National Mission on Education through ICT.
 +
 
 +
 
 +
 
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| More information on the same is available from our website.
 +
 
 +
 
 +
 
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| The Script for this tutorial was created by Anirban
 +
 
 +
 
 +
 
 +
 
 +
|-
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:none;padding:0.0382in;"|
 +
| style="border-top:none;border-bottom:0.0139in solid #000000;border-left:0.0139in solid #000000;border-right:0.0139in solid #000000;padding:0.0382in;"| And this is Anuvrat Parashar from Amity University signing off. Thanks for joining.
 +
 
 +
|}

Latest revision as of 17:21, 17 November 2014

Title of script: The Linux Environment

Author : Anirban Roy Choudhury

Keywords: Environment variables, local variables, PATH,HOME, profile, history, alias


Resources for the tutorial: File:Resources.zip

Find the HOME variable from the list and hover mouse over variable and the value after the '=' sign respectively] point the mouse to SHELL=/bin/bash ] create a directory named testtree in the home directory
Visual Cue
Narration
Display Slide 1 Welcome to this spoken tutorial on the Linux environment and ways to manupulate it.
Display Slide 2 A working linux system, preferably Ubuntu will be required to try out the examples illsutrated in this tutorial.
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 .
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.
Please note that Ubuntu 10.10 was used for recording this tutorial.
Please also note that Linux is case sensitive and all the commands used in this tutorial are in lower case unless otherwise mentioned.
Display Slide 3 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.
Linux can be highly customized by changing the settings of the shell.
Let us understand how all this can be done.
Slide 3 (continued)


The behaviour of the shell is generally determined by the shell variables.
There are two main kinds of shell variables:

Environment Variables

Local Variables

Slide 4 Environment variables, named so because they are available entirely in the user's total environment. These are also available in subshells spawned by the shell like for running shell scripts.
Local Variables , which as the name suggests have a more restricted or limited availability. These are not available to the subshells created by the shell.
While in this tutorial, we will mainly talk about environment variables, let us first see how the value of these variables can be seen.
Open a terminal

Type at the command prompt

"set | more"

press enter


To see all the variables available in the current shell , we run the command set. Type at the terminal

"set 'pipeline character' more" and press enter.

We can see all the current shell variables ,
For example : take a look at the HOME environment variable also notice the value assigned to it.
press enter

press q

press Enter to move through the list , to come out press q
Use up arrow key to move back through history and highlight the pipeline character Here the output from set was pipelined to more in order to show a more systematic multipage output of the variable list.
->Environment Variables To see only the environment variables run the command env
Type at the command prompt

"env | more"

press enter

Type at the terminal

"env space 'vertical-bar' more"

For example,

Notice the SHELL variable whose value is /bin/bash .

press q Again, you may press q to come out of the list.


Now let us discuss some of the more important environment variables in linux.
We would be using the bash shell for all our demonstrations here.
Different shells are customized in slightly different ways.
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.
Type at the command prompt

"echo $SHELL"

press enter


The first environment variable that we would see is the SHELL variable.
It stores the name of the current shell.
To see what is the value of the SHELL variable, type at the terminal "echo space dollar SHELL in capital"and press enter.
Here /bin/bash is the shell where we are currently operating.
Type at the command prompt

"echo $HOME"

press enter

The next variable is the HOME.



When we login into Linux, it normally places us in a directory named after our user name.
This directory is called the home directory and this is exactly what is available in HOME variable.
To see the value, type at the terminal "echo space dollar HOME in capital"and press enter
-The Path Variable The next environment variable is the PATH.
Type at the command prompt


"echo $PATH"

press enter

The PATH variable contains the absolute paths of the directories that the shell is supposed to search for locating any executabe command.

Lets see the value of the path variable.

Again, type at the terminal "echo space dollar PATH [in capitals]"

On my computer it shows the directories

/usr/local/bin:/usr/bin: etc.

This may slightly vary from one system to other.
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.
We can add our own directory to this list so that our directory is also searched by the shell.
Type at the command prompt

"PATH=$PATH:/home/the_name_of_your_home_directory"

press enter


In order to add our own directory type at the terminal "PATH [in capital] 'equal-to' dollar PATH again [in capital] colon /home/ the_name_of_my_own_home_directory” and press enter.
Type at the command prompt

"echo $PATH"

press enter

Now if we echo the value of PATH,
our added directory will also be a part of the PATH variable.
select and hover over the change in value of path variable See the directory is now present here.
Type at the command prompt

"echo $LOGNAME"

press enter


Another interesting variable is the LOGNAME.
It stores the username of the currently active user.
In order to see the value type "echo space dollar LOGNAME" and press enter.
Type at the command prompt

" echo $PS2 "

press enter


press enter a few times to highlight the change

When we open the terminal we can see the dollar sign, which is the prompt at which we enter all our commands.
Type at the command prompt

" PS1="@" "

press enter

This is the primary prompt string represented by the environment variable PS1.
press enter few times to highlight the change


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
This is the secondary prompt string represented by the environment variable PS2.
To see the secondary command prompt, type at the terminal "echo space dollar PS2 [in capital]" and press enter.
We may change our primary prompt string to say “at the rate” <@> at the prompt.
Type at the command prompt

"PS1=$"

press enter

In order to get this done

Type "PS1 [in capital] 'equal-to' now withing quotes 'at the rate' “ and press enter.

Now instead of the dollar sign we see an at the rate sign.
We may do something more interesting. Like we may display our username as the prompt.
Type at the command prompt

"PS1=$LOGNAME"

press enter


Just type "PS1 in capital'equal-to' within quotes dollar LOGNAME " and press enter
Now my username is my prompt.
To revert back type "PS1 'equal-to' dollar within quotes and press enter."
Open another tab in the terminal ctrl+shift+t We have assigned values to many of the environment variables.
But, remember one thing that these modifications are only applicable for the current session.
Type at the command prompt

"echo $PATH"

press enter


Like we had just added our directory to the PATH variable.
If we close the terminal and open it again or open a new terminal altogether and check the path variable by echo-ing its value
we will be surprised to see that our modificaitons are no longer present.
The way by which we can make these modifications permanent will be covered in some advanced tutorial.
Display slide 4


Often we want to re-execute a command we had executed in the recent past. What do we do? Do we have to type the entire command again? No, there are a number of solutions.
Press up direction key First, normally if you press the up direction key in your keyboard then it will show the last command that you typed.
Keep pressing and it will keep scrolling through the previous commands.
Press down direction key To go back press the down direction key.
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.
Type at the command prompt

"history"

Type at the prompt "history"
press enter and press enter, see a list of previously executed commands appears
If instead of the large list you want to see, only the last ten
Type at the command prompt

"history 10"

press enter

Type "history space 10" and press enter


Notice, in this list, there is a number assigned to each of the previously executed commands.
In order to repeat a particular command.
Take a random example

Type at the command prompt

"![number]"

type any number that you are getting in the list given by "history 10" command

press enter

Just type exclamation mark followed by the number of the command for example 442 in my case would execute echo space dollar path
Type at the command prompt

"!!"

press enter

If you need to execute the last command simply type exclamation mark twice and press enter.
Tilde character Substitution The next thing we would see is called tilde substitution

The tilde(~) charactar is a shorthand for the home directory.

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".
Type at the command prompt

"cd ~/testtree "

press enter

Run pwd to illustrate the change


One may also toggle between the current working directory and the last directory used by giving the command

cd ~- [narration - cd space 'tilde' minus] or only cd - [ narration - cd space minus]

Type at the command prompt

"cd -"

press enter


Like now that we are in the testtree directory, the last directory we visited was the home directory.

So if we run "cd space minus" . It will go to the home directory.

Press the up key and enter to re-execute the previous command.


Run it again and you are back to the testtree directory.
(Before the video create such a long directory hierarchy)


The last but quite important command we will see is the alias command. It may happen that you have a large command that needs to be run again and again. In this case we can give it a short alias name and use the alias name instead ,to invoke it.
Assuming that you have such a long directory hierarchy that you frequently visit for music, you may create an alias for it like this: \
Type at the command prompt

" alias cdMusic = "cd /home/arc/files/entertainment/music" "

press enter

Type " alias space cdMusic 'equal-to' within double quotoes cd space /home/arc/files/entertainment/music " and press enter
Type at the command prompt

"cdMusic"

press enter

Quickly run pwd to illustrate the effect of the previous command


Now every time you need to switch to this directory simply write cdMusic and press enter. See, we are in the music directory now.
Type at the command prompt

"cd -"


Now, you may type at the prompt "cd space minus" to go back to the previous working directory.
Type at the command prompt

"unalias cdMUsic"

press enter


To unset this alias simply write unalias space cdMusic
Type at the command prompt

"cdMusic"

press enter


Now again if you fire cdMusic from the terminal, you will get an error stating that the command was not found.
quickly run

touch test1 test2

to create test1 and test2 in the present working directory. Then run ls illustrate the change.


Suppose we have two files, test1 and test2 in our present working directory
Type at the command prompt

"rm test1"

press enter


and if we fire rm test1, test1 is silently deleted.
We know that the “hyphen i” option of the rm command can make the removal process interactive.
Type at the command prompt

" alias rm ="rm -i" "

press enter


So we may set an alias like, alias rm equal-to, now within quotes “rm space -i”
Type at the command prompt

"rm test2"

press enter

Now when we run “rm” ,” rm-i” will actually be run.\
So we saw that while test1 was silently deleted, system asked before deleting test2.
Display Slide 5 So, in this tutorial, you have learned about environment variables, history and aliasing.
Display Slide 6 This brings me to the end of this tutorial.



Spoken Tutorials are a part of the Talk to a Teacher project, supported by the

National Mission on Education through ICT.



More information on the same is available from our website.



The Script for this tutorial was created by Anirban



And this is Anuvrat Parashar from Amity University signing off. Thanks for joining.

Contributors and Content Editors

Nancyvarkey, PoojaMoolya