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

From Script | Spoken-Tutorial
Jump to: navigation, search
(to see)
 
(2 intermediate revisions by the same user not shown)
Line 24: Line 24:
 
* Navigate to directories and use '''tilde '''shortcut
 
* Navigate to directories and use '''tilde '''shortcut
 
* Re-run the commands using history and aliases
 
* Re-run the commands using history and aliases
* Customize prompts and make rm interactive
+
* Customize prompts and make rm interactive.
 
|-
 
|-
 
|| '''Slide 3'''
 
|| '''Slide 3'''
Line 89: Line 89:
  
 
'''Local Variables'''
 
'''Local Variables'''
|| * Local variables have a limited scope
+
||  
 +
* Local variables have a limited scope
 
* They are available only in the current shell session
 
* They are available only in the current shell session
 
* They are not available to subshells created by the shell.
 
* They are not available to subshells created by the shell.
Line 134: Line 135:
 
|| '''Type '''
 
|| '''Type '''
  
'''env | more''' and''' '''press '''Enter'''  
+
'''env | more''' and press '''Enter'''  
|| Type''' e n v space vertical bar space more ''' and press''' Enter'''
+
|| Type ''' e n v space vertical bar space more ''' and press''' Enter'''
 
|-
 
|-
 
|| Highlight '''SHELL=/bin/bash'''
 
|| Highlight '''SHELL=/bin/bash'''
|| Notice the '''SHELL''' variable whose value is '''slash bin slash bash. '''
+
|| Notice the '''SHELL''' variable whose value is '''slash bin slash bash'''.
 
|-
 
|-
 
|| Press '''q''' to exit the list
 
|| Press '''q''' to exit the list
Line 168: Line 169:
 
|| Type '''echo space dollar SHELL''' in capital and press '''Enter'''.  
 
|| Type '''echo space dollar SHELL''' in capital and press '''Enter'''.  
  
The value of the '''SHELL''' variable is as shown .
+
The value of the '''SHELL''' variable is as shown.
 
|-
 
|-
 
|| Highlight '''/bin/bash'''
 
|| Highlight '''/bin/bash'''
Line 229: Line 230:
 
|-
 
|-
 
|| '''Type echo $PATH''' and press '''Enter'''.
 
|| '''Type echo $PATH''' and press '''Enter'''.
|| Now, let’s '''echo''' the value of '''PATH''', to see its current contents.
+
|| Now, let’s '''echo''' the value of '''PATH'''.  
  
Type '''echo space dollar PATH''' in capital and press '''Enter'''.
+
To see its current contents,
 +
type '''echo space dollar PATH''' in capital and press '''Enter'''.
 
|-
 
|-
 
|| Highlight to the added directory
 
|| Highlight to the added directory
Line 258: Line 260:
 
and press  '''Enter'''.  
 
and press  '''Enter'''.  
  
Observe that, in the output''' spoken ''' is displayed.
+
Observe that, in the output ''' spoken ''' is displayed.
 
|-
 
|-
 
|| '''Type PS1="@" '''
 
|| '''Type PS1="@" '''
Line 273: Line 275:
 
This is the primary prompt string represented by the environment variable '''P S 1 '''.
 
This is the primary prompt string represented by the environment variable '''P S 1 '''.
 
|-
 
|-
|| Press Enter few times to highlight the change displaying @
+
|| Press Enter a few times to highlight the change displaying @
 
|| Press '''Enter''' a few times to see the '''at the rate''' prompt.
 
|| Press '''Enter''' a few times to see the '''at the rate''' prompt.
 
|-
 
|-
Line 317: Line 319:
 
|| To just show a dollar prompt type,
 
|| To just show a dollar prompt type,
  
'''P S 1 equals to double quotes dollar double quotes '''and press '''Enter'''.
+
Type this command and press '''Enter'''.
 
|-
 
|-
 
||  
 
||  
Line 376: Line 378:
 
|| However, scrolling through many commands may be clumsy and tedious.  
 
|| However, scrolling through many commands may be clumsy and tedious.  
  
A better way is to use the '''history '''command.
+
A better way is to use the '''history ''' command.
  
 
Type '''history''' and press '''Enter''' to see a list of previously executed commands.
 
Type '''history''' and press '''Enter''' to see a list of previously executed commands.
Line 387: Line 389:
 
|| If you want to see only the last ten commands instead of the full list,  
 
|| If you want to see only the last ten commands instead of the full list,  
  
Type '''history space 10''' and press '''Enter'''  
+
type '''history space 10''' and press '''Enter'''  
 
|-
 
|-
 
|| Point to the assigned numbers.
 
|| Point to the assigned numbers.
Line 406: Line 408:
 
|-
 
|-
 
|| Type '''!! '''Press '''Enter'''.
 
|| Type '''!! '''Press '''Enter'''.
|| To execute the last command, type''' exclamation mark twice''' and press '''Enter'''.  
+
|| To execute the last command, type ''' exclamation mark twice''' and press '''Enter'''.  
 
|-
 
|-
 
|| '''Type clear and press Enter.'''
 
|| '''Type clear and press Enter.'''
Line 412: Line 414:
 
|-
 
|-
 
|| '''Tilde character Substitution''' type '''cd ~''' press '''Enter.'''
 
|| '''Tilde character Substitution''' type '''cd ~''' press '''Enter.'''
|| Next, we will learn about '''tilde''' '''substitution'''.
+
|| Next, we will learn about '''tilde substitution'''.
  
The tilde''' '''character is a shortcut for the home directory.
+
The ''' tilde'''character is a shortcut for the home directory.
  
 
type '''c d space''' '''tilde''' press '''Enter.'''
 
type '''c d space''' '''tilde''' press '''Enter.'''
Line 429: Line 431:
 
Now type '''cd space tilde slash test tree''', press '''Enter'''.
 
Now type '''cd space tilde slash test tree''', press '''Enter'''.
  
Type '''p w d''' and Press '''Enter''' to the current directory.
+
Type '''p w d''', press '''Enter''' to see the directory path.
 
|-
 
|-
 
|| (Before the video create such a long directory hierarchy)  
 
|| (Before the video create such a long directory hierarchy)  
Line 459: Line 461:
  
 
'''/home/spoken/testtree/songs/music'''
 
'''/home/spoken/testtree/songs/music'''
|| Let us create a few directories to show a long path in the '''test''' '''tree '''directory.
+
|| Let us create a few directories to show a long path in the '''test tree '''directory.
  
Type''' m k d i r space songs''' and press '''Enter''' to make the directory.
+
Type ''' m k d i r space songs''' and press '''Enter''' to make the directory.
  
Type '''c d space songs''' and press '''Enter''' to move the '''songs''' directory.
+
Type '''c d space songs''' and press '''Enter''' to go to the '''songs''' directory.
  
 
Now type '''m k d i r space music''' to create the '''music '''directory.
 
Now type '''m k d i r space music''' to create the '''music '''directory.
  
Type''' c d space music''' and press '''Enter''' to move the '''music '''directory.
+
Type ''' c d space music''' and press '''Enter''' to go the '''music '''directory.
  
 
Let us clear the screen.
 
Let us clear the screen.
Line 495: Line 497:
  
 
'''cd -'''  
 
'''cd -'''  
|| Now, type '''c d space hyphen '''to go back to the previous working directory.  
+
|| Now, type '''c d space hyphen ''' to go back to the previous working directory.  
 
|-
 
|-
 
|| Type''' unalias music'''
 
|| Type''' unalias music'''
Line 504: Line 506:
 
|| To remove this alias, type '''unalias space music'''
 
|| To remove this alias, type '''unalias space music'''
  
and press '''Enter'''.Type '''c d '''and press '''Enter''' to go to the home directory.
+
and press '''Enter'''.
 +
 
 +
Type '''c d '''and press '''Enter''' to go to the home directory.
 
|-
 
|-
 
|| Type''' music'''  
 
|| Type''' music'''  
Line 526: Line 530:
  
 
Highlight '''test1''' and '''test2'''.
 
Highlight '''test1''' and '''test2'''.
||  
+
|| To create '''test 1''' and '''test 2 files''' in the current directory, type '''touch test 1 test 2''' and Press '''Enter'''.
 
+
To create '''test 1''' and '''test 2 files''' in the current directory, type '''touch''' '''test 1''' '''test 2''' and Press '''Enter'''.
+
  
 
Command '''touch''' is used to create files in the current directory.
 
Command '''touch''' is used to create files in the current directory.
Line 539: Line 541:
  
 
press '''Enter'''  
 
press '''Enter'''  
|| The '''hyphen i''' option of the '''r m''' command makes deletion interactive. So, we can create an alias for the '''r m''' command.
+
|| The '''hyphen i''' option of the '''r m''' command makes deletion interactive.  
  
Type '''alias space rm equal to within double quotes rm space hyphen i'''..
+
So, we can create an alias for the '''r m''' command.
 +
 
 +
Type this command and press Enter.
 
|-
 
|-
 
|| Type''' rm test1'''
 
|| Type''' rm test1'''
Line 549: Line 553:
 
|-
 
|-
 
||  
 
||  
|| The system asks to remove regular empty file '''test 1.'''Type '''y''' and press '''Enter''' to confirm deletion.Now, if we run '''r m''' '''test 1''' and press '''Enter'''.The file is no longer present and as it is already deleted.
+
|| The system asks to remove regular empty file '''test 1.'''Type '''y''' and press '''Enter''' to confirm deletion.
 +
 
 +
Now, if we run '''r m test 1''' and press '''Enter'''.
 +
 
 +
The file is no longer present and as it is already deleted.
 
|-
 
|-
 
|| '''Slide 10'''
 
|| '''Slide 10'''
Line 579: Line 587:
  
 
'''Thank you'''
 
'''Thank you'''
|| This Spoken Tutorial is brought to you by EduPyramids Educational Services Private Limited, SINE IIT Bombay.Thank you.
+
|| This Spoken Tutorial is brought to you by EduPyramids Educational Services Private Limited, SINE IIT Bombay.  
 +
 
 +
Thank you.
 
|-
 
|-
 
|}
 
|}

Latest revision as of 19:34, 24 January 2026

Title of the Script: The Linux Environment.

Author: EduPyramids

Keywords: Environment variables, local variables, PATH,HOME, profile, history, alias, edupyramids, video tutorial.


Visual Cue Narration
Slide 1

Title Slide

Welcome to this spoken tutorial on The Linux Environment.
Slide 2

Learning Objectives

In this tutorial, we will learn about:
  • Linux environment and shell variables
  • View and modify environment variables
  • Navigate to directories and use tilde shortcut
  • Re-run the commands using history and aliases
  • Customize prompts and make rm interactive.
Slide 3

System Requirements

To record this tutorial, I am using,
  • Ubuntu OS version 24 point 04
Slide 4

Pre-requisites

https://EduPyramids.org

To follow this tutorial,

Learners should have Ubuntu version 24 point 04

For the prerequisite of Linux tutorials please visit this website.

Slide 5

Code Files

The following code file is required to practice this tutorial.

le-commands.txt

This file is provided in the Code Files link of this tutorial page.

The following code file is required to practice this tutorial.

This file is provided in the Code Files link of this tutorial page.

Slide 6

Linux Environment

env-image.png

* The Linux environment controls how the operating system behaves.
  • It determines how commands are processed and actions are interpreted.
  • The environment can be customized to suit user preferences.
Slide 7

Shell Variables

image

The behaviour of the shell is controlled by shell variables

Shell variables influence how commands execute and display results

There are two main types of shell variables:

  • Environment Variables
  • Local Variables
Slide 8

Environment Variables

  • Environment variables are available throughout the user’s working environment.
  • Inherited by subshells, for example, when running shell scripts.
  • Commonly used to store paths, usernames, language settings, etc.
Slide 9

Local Variables

  • Local variables have a limited scope
  • They are available only in the current shell session
  • They are not available to subshells created by the shell.
This tutorial will mainly focus on environment variables.

We will begin by exploring how to display the values of these variables.

Press Ctrl, alt and T keys together.

Type set | more

press enter

Let us open the terminal.

To see all the variables available in the current shell, we use the set command.

Type: set space vertical bar space more

and press Enter.

Point to the output. We can see all the current shell variables,
Press Enter and locate the HOME environment. For example, Take a look at the HOME environment variable and notice the value assigned to it.
Press Enter

Press q

Press Enter to move through the list.

Press q to come out.

Highlight set | more Here, the output of the set command is piped to more.

This allows the list of variables to be displayed in a systematic, multi-page format.

To see only the environment variables, we will run the e n v command.
Type

env | more and press Enter

Type e n v space vertical bar space more and press Enter
Highlight SHELL=/bin/bash Notice the SHELL variable whose value is slash bin slash bash.
Press q to exit the list Again, you may press q to come out of the list.
Type clear and press Enter. Let’s clear the screen.
Now let us discuss some important environment variables in linux.
We will use the bash shell for all our demonstrations.
Different shells are customized in slightly different ways.
Add $ before name To see a variable’s value, add a dollar sign before its name.
The first environment variable that we will see is the SHELL variable.

It stores the name of the current shell.

Type: echo $SHELL

Press Enter

Type echo space dollar SHELL in capital and press Enter.

The value of the SHELL variable is as shown.

Highlight /bin/bash Here slash bin slash bash is the shell where we are currently operating.
The next variable is HOME.
When we log in to Linux, we are placed in a directory named after our username.

This directory is called the home directory, and its path is stored in the HOME variable.

Type at the command prompt

echo $HOME and press Enter

To see the value, type echo space dollar HOME in capital and press Enter

We see the output as slash home slash spoken

The Path Variable The next environment variable is the PATH.
The PATH variable contains the absolute paths of the directories.

The shell searches them to find executable commands.

Type: echo $PATH

press Enter

Highlight the directories.

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin (This path might differ so while recording please copy the path and paste it here in the script.)

Let us now see the value of the PATH variable.

type echo space dollar PATH in capital letters and press Enter.

The output shows the directories present on the system.

This list may vary slightly from one system to another.

Point to the colon (:). It is a list of directories separated by a colon (:).

The shell searches these directories in order to find an executable command.

We can configure the shell to look for commands in our own directory.
Type PATH=$PATH:/home/spoken Highlight spoken from above command

and press Enter.

Type this command and press Enter.

Users can type their home directory's name.

Now, any executable scripts you place in slash home slash spoken can be run without typing the full path.

Type echo $PATH and press Enter. Now, let’s echo the value of PATH.

To see its current contents, type echo space dollar PATH in capital and press Enter.

Highlight to the added directory Our added directory will also be a part of the PATH variable.
select and hover over the change in value of path variable The directory is now available here.

Note that this change is temporary and applies only to this terminal session.

Type clear let us clear the terminal.
Another interesting variable is the LOG NAME.

It stores the username of the currently active user.

Type echo $LOGNAME

press Enter

Highlight spoken

In order to see the value type echo space dollar LOG NAME

and press Enter.

Observe that, in the output spoken is displayed.

Type PS1="@"

and press Enter.

Highlight the @ sign.

Now, let us change the shell prompt.

Type the following command and press Enter.

After pressing Enter, the terminal prompt will change to the at the rate symbol.

This is the primary prompt string represented by the environment variable P S 1 .

Press Enter a few times to highlight the change displaying @ Press Enter a few times to see the at the rate prompt.
Type bash

and press Enter

Highlight the prompt

To get back to the original prompt type

bash and press Enter.

Type echo $PS2 and press Enter.

Highlight greater than prompt

To see the secondary command prompt, type echo space dollar P S 2 in capital.

and press Enter.

Greater than sign is the secondary prompt string represented by the environment variable P S 2.

The greater than sign is seen only once and the original prompt appears.

Now let’s try something more interesting.

Let’s display our username as the shell prompt.

Type at the command prompt

PS1=$LOGNAME

press Enter

Highlight the new prompt

Type P S 1 in capital equals dollar LOGNAME and press Enter.

We can see the username spoken is visible as my prompt.

Type: PS1="$"

and press Enter

To just show a dollar prompt type,

Type this command and press Enter.

We have assigned values of several environment variables.
Click the + icon on the top left corner.

These changes apply only to the current session.

Open a new tab.

Observe that these changes apply only to the current session.

That is why a new tab shows the original prompt.

Let us close the new terminal tab.

Type bash

and press Enter

Highlight the prompt

To get back to the original prompt type

bash and press Enter.

Type: echo $PATH

Press Enter.

For example, we just added our directory to the PATH variable.
Press + to open new terminal tab.

type echo $PATH

and press Enter

Highlight the output

Open a new terminal tab and type echo DOLLAR PATH and press Enter.

The same path variable will not be seen.

let us go back to the previous terminal.

Press up direction key Press the Up arrow key to see the last command we used.
Keep pressing it to move through earlier commands.
Press down direction key Press the Down arrow key to move forward again.
Type at the command prompt

history

and press Enter.

However, scrolling through many commands may be clumsy and tedious.

A better way is to use the history command.

Type history and press Enter to see a list of previously executed commands.

Type at the command prompt

history 10

and press Enter

If you want to see only the last ten commands instead of the full list,

type history space 10 and press Enter

Point to the assigned numbers. Notice, in this list, there is a number assigned to each of the previously executed commands.
Type at the command prompt

!1348 press Enter.

Highlight the output numbers

To repeat a command, type an exclamation mark followed by its number.

For example 1348 in my case would execute echo space dollar path.

Please note the number may not be the same for you.

Type the number that is seen on your terminal and press Enter to execute the command.

Type !! Press Enter. To execute the last command, type exclamation mark twice and press Enter.
Type clear and press Enter. let me clear the terminal
Tilde character Substitution type cd ~ press Enter. Next, we will learn about tilde substitution.

The tildecharacter is a shortcut for the home directory.

type c d space tilde press Enter.

Type mkdir testtree and press Enter

Type cd ~/testtree, Press Enter.

Type: pwd, Press Enter.

Let us create a directory named testtree in the home directory.

Type: m k d i r space test tree and press Enter.

Now type cd space tilde slash test tree, press Enter.

Type p w d, press Enter to see the directory path.

(Before the video create such a long directory hierarchy) The alias command in Linux is used to create shortcuts for longer commands.
Type

mkdir songs

and press Enter

cd songs

and press Enter

mkdir music

and press Enter

cd music

and press Enter

Type

pwd

highlight the long path:

/home/spoken/testtree/songs/music

Let us create a few directories to show a long path in the test tree directory.

Type m k d i r space songs and press Enter to make the directory.

Type c d space songs and press Enter to go to the songs directory.

Now type m k d i r space music to create the music directory.

Type c d space music and press Enter to go the music directory.

Let us clear the screen.

Now type p w d to see the directory path.

This shows that we are now in the music directory.

Type alias music='cd /home/spoken/testtree/songs/music' press Enter

type cd and press Enter

Now type the alias command and press Enter.

Let us now go to the home directory.

Type c d and press Enter.

Type: music press Enter.

Run pwd to illustrate the effect of the previous command

To switch to the music directory, type music and press Enter.

You can see that we are now in the music directory.

Type at the command prompt

cd -

Now, type c d space hyphen to go back to the previous working directory.
Type unalias music

press enter

Type cd and press Enter

To remove this alias, type unalias space music

and press Enter.

Type c d and press Enter to go to the home directory.

Type music

press Enter

Highlight the error

Now again type music and press Enter.

We get an error stating that the command was not found.

Type: cd /home/spoken/testtree/songs/music

press Enter

Let's go back to the music directory.
run touch test1 test2

run ls

Highlight test1 and test2.

To create test 1 and test 2 files in the current directory, type touch test 1 test 2 and Press Enter.

Command touch is used to create files in the current directory.

Then run l s.

This reflects the change on screen.

Type alias rm="rm -i" alias space rm equal to within double quotes rm space hyphen i.

press Enter

The hyphen i option of the r m command makes deletion interactive.

So, we can create an alias for the r m command.

Type this command and press Enter.

Type rm test1

Press Enter

When we run r m test 1, the file is deleted without showing any output.
The system asks to remove regular empty file test 1.Type y and press Enter to confirm deletion.

Now, if we run r m test 1 and press Enter.

The file is no longer present and as it is already deleted.

Slide 10

Summary

In this tutorial, we have learnt about:

  • Linux environment and shell variables
  • View and modify environment variables
  • Navigate to directories and use tilde shortcuts
  • Re-run commands using history and aliases
  • Customize prompts and make rm interactive
With this we come to the end of this tutorial.

Let us summarise.

Slide 11

Assignment

As an assignment

  1. Type env and list all environment variables.
  2. Identify the values of HOME, SHELL, LOGNAME, and PATH.
  3. Temporarily change your PS1 prompt to display your username followed by @Linux:~$.
  4. Try creating an alias for a long command and use it.
As an assignment, please do the following.
Slide 12

Thank you

This Spoken Tutorial is brought to you by EduPyramids Educational Services Private Limited, SINE IIT Bombay.

Thank you.

Contributors and Content Editors

Ketkinaina, Madhurig