Difference between revisions of "BASH/C3/More-on-Redirection/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with "{| Border=1 |'''Timee''' |'''Narration''' |- | 00:01 | Dear friends, Welcome to the spoken tutorial on '''More on redirection''' |- | 00:07 | In this tutorial, we will lea...")
 
Line 5: Line 5:
 
|-
 
|-
 
| 00:01
 
| 00:01
| Dear friends, Welcome to the spoken tutorial on '''More on redirection'''
+
| Dear friends, welcome to the '''spoken tutorial''' on '''More on redirection'''.
  
 
|-
 
|-
 
| 00:07
 
| 00:07
| In this tutorial, we will learn  '''Redirection''' of both '''standard error''' and '''output '''
+
| In this tutorial, we will learn:  
 +
* '''Redirection''' of both '''standard error''' and '''output ''';
  
 
|-
 
|-
 
| 00:13
 
| 00:13
| Appending '''redirected output'''  
+
|* Appending '''redirected output'''  
 
   
 
   
 
|-
 
|-
 
| 00:15
 
| 00:15
| With the help of some examples  
+
| with the help of some examples.
  
 
|-
 
|-
 
| 00:19
 
| 00:19
| To follow this tutorial you should have knowledge of '''Shell Scripting''' in''' BASH.'''
+
| To follow this tutorial, you should have knowledge of '''Shell Scripting''' in''' BASH.'''
  
 
|-
 
|-
 
| 00:25
 
| 00:25
| If not, for relevant tutorials please visit our website which is as shown '''http://www.spoken-tutorial.org'''
+
| If not, for relevant tutorials, please visit our website which is as shown. '''http://www.spoken-tutorial.org'''
  
 
|-
 
|-
 
| 00:30
 
| 00:30
| For this tutorial I am using '''Ubuntu Linux''' '''12.04''' '''Operating System'''  
+
| For this tutorial, I am using:
 +
* '''Ubuntu Linux''' '''12.04''' '''Operating System'''  
  
 
|-
 
|-
 
|00:35
 
|00:35
| '''GNU BASH''' version 4.2
+
|* '''GNU BASH''' version 4.2.
  
 
|-
 
|-
Line 45: Line 47:
 
|-
 
|-
 
| 00:52
 
| 00:52
| '''Both stderr''' as well as the '''stdout''' can be redirected to the same file.
+
| Both '''stderr''' as well as the '''stdout''' can be redirected to the same file.
  
 
|-
 
|-
Line 53: Line 55:
 
|-
 
|-
 
|01:01
 
|01:01
|We will cover two of the most important methods of redirections in this tutorial.
+
|We will cover two of the most important methods of '''redirection''' in this tutorial.
  
 
|-
 
|-
 
| 01:08
 
| 01:08
| The first method to redirect both the '''standard output '''and ''' error''' is by using  '''&>'''(ampersand) followed by greater-than sign
+
| The first method to redirect both the '''standard output '''and ''' error''' is by using  '''&>'''(ampersand) followed by greater-than sign.
  
 
|-
 
|-
 
|01:18
 
|01:18
|The syntax is '''Command space ampersand greater than''' space '''filename'''
+
|The syntax is '''command space ampersand greater than''' space '''filename'''.
  
 
|-
 
|-
Line 69: Line 71:
 
|-
 
|-
 
|01:30
 
|01:30
|I have typed some code in this file.
+
|I have typed some '''code''' in this file.
  
 
|-
 
|-
Line 77: Line 79:
 
|-
 
|-
 
| 01:36
 
| 01:36
| '''ls''' lists the directory content of 2 directories namely '''/usr''' and '''/user'''
+
| '''ls''' lists the directory content of 2 directories namely '''/usr''' and '''/user'''.
  
 
|-
 
|-
Line 89: Line 91:
 
|-
 
|-
 
|01:52
 
|01:52
|'''&'''(ampersand) followed by '''greater than '''will redirect '''stdout ''' and '''stderr''' to '''out_(underscore)file.txt'''
+
|'''&'''(ampersand) followed by '''greater than '''will redirect '''stdout ''' and '''stderr''' to '''out_(underscore)file.txt'''.
  
 
|-
 
|-
 
| 02:03
 
| 02:03
| Now Save the file.
+
| Now '''save''' the file.
  
 
|-
 
|-
 
| 02:05
 
| 02:05
| Let us run the file''' redirect.sh.'''  
+
| Let us '''run''' the file''' redirect.sh.'''  
  
 
|-
 
|-
 
|02:07
 
|02:07
|Open the terminal using '''CTRL+ALT+T keys''' simultaneously on your keyboard
+
|Open the '''terminal''' using '''CTRL + ALT + T''' keys simultaneously on your keyboard.
  
 
|-
 
|-
 
| 02:15
 
| 02:15
| Type '''chmod space plus x space redirect dot sh'''
+
| Type: '''chmod space plus x space redirect dot sh'''
  
 
|-
 
|-
 
|02:23
 
|02:23
|Press '''Enter'''  
+
|Press '''Enter'''.
  
 
|-
 
|-
 
|02:25
 
|02:25
|Type '''dot slash redirect dot sh'''
+
|Type: '''dot slash redirect dot sh'''
  
 
|-
 
|-
Line 121: Line 123:
 
|-
 
|-
 
| 02:30
 
| 02:30
| We can see the output by '''opening out_(underscore)file.(dot)txt'''
+
| We can see the '''output''' by '''opening out_(underscore)file.(dot)txt'''.
  
 
|-
 
|-
 
|02:36
 
|02:36
|Type '''cat space out_(underscore)file.(dot)txt'''
+
|Type: '''cat space out_(underscore)file.(dot)txt'''.
  
 
|-
 
|-
Line 137: Line 139:
 
|-
 
|-
 
|02:51
 
|02:51
|It says that there was no ''''/user'''' directory found.
+
|It says that there was no ''''/user'''' '''directory''' found.
  
 
|-
 
|-
Line 145: Line 147:
 
|-
 
|-
 
|03:00
 
|03:00
|Please note that the content for ''''/usr' directory''' may vary on your system.
+
|Please note that the content for ''' '/usr' directory''' may vary on your system.
  
 
|-
 
|-
 
| 03:06
 
| 03:06
| Now let us delete this file. So, on the '''terminal ''' Type '''rm space out_(underscore)file. (dot)txt'''
+
| Now, let us delete this file. So, on the '''terminal, ''' type: '''rm space out_(underscore)file. (dot)txt'''.
  
 
|-
 
|-
 
| 03:15
 
| 03:15
| Another method is to use '''2 greater than ampersand 1 '''after the filename
+
| Another method is to use '''2 greater than ampersand 1 '''after the filename.
  
 
|-
 
|-
 
|03:24
 
|03:24
|The syntax is '''command space greater than''' '''filename space 2 greater than ampersand 1'''
+
|The syntax is '''command space greater than''' '''filename space 2 greater than ampersand 1'''.
  
 
|-
 
|-
Line 169: Line 171:
 
|-
 
|-
 
| 03:45
 
| 03:45
| It is a special kind of file
+
| It is a special kind of file.
  
 
|-
 
|-
 
|03:48
 
|03:48
|It is a null file or a place where we can dump anything.  
+
|It is a '''null file''' or a place where we can dump anything.  
  
 
|-
 
|-
 
|03:52
 
|03:52
|It includes the output and error messages  
+
|It includes the '''output''' and '''error''' messages.
  
 
|-
 
|-
Line 185: Line 187:
 
|-
 
|-
 
| 04:00
 
| 04:00
| Let us now come back to our code in '''gedit'''.
+
| Let us now come back to our '''code''' in '''gedit'''.
  
 
|-
 
|-
 
| 04:04
 
| 04:04
| Let us redirect both standard output and error to the '''null file. '''
+
| Let us '''redirect''' both '''standard output''' and '''error''' to the '''null file. '''
  
 
|-
 
|-
Line 197: Line 199:
 
|-
 
|-
 
| 04:16
 
| 04:16
| I want both the output and error messages to be discarded.  
+
| I want both the '''output''' and '''error''' messages to be discarded.  
  
 
|-
 
|-
 
|04:21
 
|04:21
|So I will change this part of the copied code.'''> (greater than) '''means '''truncate''' or '''write'''.
+
|So I will change this part of the copied code. '''> (greater than) '''means '''truncate''' or '''write'''.
  
 
|-
 
|-
 
|04:30
 
|04:30
|'''slash dev slash null '''is the null file '''2>&1''' '''(2 greater than ampersand 1)'''
+
|'''slash dev slash null '''is the null file '''2>&1''' (2 greater than ampersand 1).
  
 
|-
 
|-
Line 213: Line 215:
 
|-
 
|-
 
| 04:45
 
| 04:45
| Now click on '''Save'''. Save the code.
+
| Now click on '''Save'''. '''Save''' the '''code'''.
  
 
|-
 
|-
 
|04:48
 
|04:48
| Let us run the file''' redirect.sh.'''  
+
| Let us '''run''' the file''' redirect.sh.'''  
  
 
|-
 
|-
Line 225: Line 227:
 
|-
 
|-
 
| 04:54
 
| 04:54
| Recall the previous command with the up-arrow key. '''dot slash redirect.sh''' and press '''Enter.'''
+
| Recall the previous '''command''' with the up-arrow key. '''dot slash redirect.sh''' and press '''Enter.'''
  
 
|-
 
|-
 
| 05:03
 
| 05:03
| We can see the output by typing '''cat out_(underscore)file.(dot)txt'''
+
| We can see the output by typing '''cat out_(underscore)file.(dot)txt'''.
  
 
|-
 
|-
 
|05:11
 
|05:11
| Come back to our slides.
+
| Come back to our '''slides'''.
  
 
|-
 
|-
 
|05:15
 
|05:15
|* We can capture as well as append '''standard output''' or '''error''' to a file.
+
| We can capture as well as append '''standard output''' or '''error''' to a file.
  
 
|-
 
|-
 
|05:21
 
|05:21
|The output or the error will be appended at the end of the file.
+
|The '''output''' or the '''error''' will be appended at the end of the file.
  
 
|-
 
|-
Line 249: Line 251:
 
|-
 
|-
 
|05:31
 
|05:31
|The syntax is '''command''' '''space greater than greater than space '''followed by '''filename '''
+
|The syntax is '''command''' '''space greater than greater than space '''followed by '''filename '''.
  
 
|-
 
|-
Line 257: Line 259:
 
|-
 
|-
 
|05:45
 
|05:45
|Let me open the file '''redirect.(dot)sh'''
+
|Let me open the file '''redirect.(dot)sh'''.
  
 
|-
 
|-
 
| 05:49
 
| 05:49
| Now, here let's Type '''date space greater than greater than space out_(underscore)file.(dot)txt'''
+
| Now, here let's type: '''date space greater than greater than space out_(underscore)file.(dot)txt'''.
  
 
|-
 
|-
 
| 06:00
 
| 06:00
| The ''''date'''' command will simply display the '''system date '''as output.  
+
| The ''''date'''' command will simply display the '''system date '''as '''output'''.  
  
 
|-
 
|-
 
|06:06
 
|06:06
|We can check this command on the '''terminal''' by typing ''''date.''''
+
|We can check this '''command''' on the '''terminal''' by typing ''''date.''''
  
 
|-
 
|-
 
|06:11
 
|06:11
|Come back to the terminal.Type '''date''' You can see that the '''system date '''i.e. the '''current date '''is displayed.
+
|Come back to the '''terminal'''. Type '''date'''. You can see that the '''system date '''i.e. the '''current date '''is displayed.
  
 
|-
 
|-
 
|06:23
 
|06:23
|The output of '''date command''' will be appended to the '''out_(underscore)file.(dot)txt '''file.
+
|The '''output''' of '''date''' command will be appended to the '''out_(underscore)file.(dot)txt '''file.
  
 
|-
 
|-
 
|06:31
 
|06:31
|We are using this file to capture '''standard output''' and error of '''ls''' command.
+
|We are using this file to capture '''standard output''' and '''error''' of '''ls''' command.
  
 
|-
 
|-
Line 293: Line 295:
 
|-
 
|-
 
|06:43
 
|06:43
| Now press the '''uparrow''' key.Recall the previous command ''' dot slash redirect dot sh'''
+
| Now press the '''up-arrow''' key. Recall the previous command ''' dot slash redirect dot sh'''.
  
 
|-
 
|-
Line 301: Line 303:
 
|-
 
|-
 
| 06:52
 
| 06:52
| Let us check the output by opening '''out_(underscore) file.(dot)txt'''
+
| Let us check the output by opening '''out_(underscore) file.(dot)txt'''.
  
 
|-
 
|-
 
|06:59
 
|06:59
|Type '''cat space out_(underscore)file.(dot)txt'''
+
|Type: '''cat space out_(underscore)file.(dot)txt'''
  
 
|-
 
|-
 
| 07:05
 
| 07:05
| Observe that the output of ''''date'''' command is appended to the end of the file.
+
| Observe that the output of''' 'date' ''' command is appended to the end of the file.
  
 
|-
 
|-
Line 317: Line 319:
 
|-
 
|-
 
| 07:15
 
| 07:15
|Let us summarise.  
+
|Let us summarize.  
  
 
|-
 
|-
 
|07:17
 
|07:17
|In this tutorial we learnt
+
|In this tutorial, we learnt:
  
 
|-
 
|-
 
|07:19
 
|07:19
|Redirection of both '''standard error''' and '''output''' And to append the '''redirected output''' '''
+
|Redirection of both '''standard error''' and '''output''';
 +
And to append the '''redirected output'''. '''
  
 
|-
 
|-
 
|07:27
 
|07:27
| As an assignment,
+
| As an assignment:
  
 
|-
 
|-
 
|07:29
 
|07:29
|Create '''X_(underscore)file.(dot)txt''' file with some content.
+
| Create '''X_(underscore)file.(dot)txt''' file with some content.
  
 
|-
 
|-
 
|07:34
 
|07:34
|Redirect the content of both '''out_(underscore)file.(dot)txt''' and '''X_(underscore)file.(dot)txt''' to a new file.
+
| Redirect the content of both '''out_(underscore)file.(dot)txt''' and '''X_(underscore)file.(dot)txt''' to a new file.
  
 
|-
 
|-
Line 345: Line 348:
 
|-
 
|-
 
|07:47
 
|07:47
|It summarises the Spoken Tutorial project.
+
|It summarizes the Spoken-Tutorial project.
  
 
|-
 
|-
Line 353: Line 356:
 
|-
 
|-
 
| 07:56
 
| 07:56
| The Spoken Tutorial Project Team Conducts workshops using spoken tutorials Gives certificates to those who pass an online test
+
| The Spoken Tutorial Project team:
 +
* Conducts workshops using spoken tutorials.
 +
* Gives certificates to those who pass an online test.
  
 
|-
 
|-
Line 361: Line 366:
 
|-
 
|-
 
| 08:13
 
| 08:13
| Spoken Tutorial Project is a part of the Talk to a Teacher project.
+
| '''Spoken Tutorial''' project is a part of the '''Talk to a Teacher''' project.
  
 
|-
 
|-
 
| 08:17
 
| 08:17
 
|It is supported by the National Mission on Education through ICT, MHRD, Government of India.
 
|It is supported by the National Mission on Education through ICT, MHRD, Government of India.
More information on this Mission is available at http://spoken-tutorial.org/NMEICT-Intro
+
More information on this mission is available at http://spoken-tutorial.org/NMEICT-Intro
  
 
|-
 
|-
Line 374: Line 379:
 
|-
 
|-
 
|08:37
 
|08:37
|This is Ashwini from IIT Bombay.Thank you for joining.
+
|This is Ashwini from IIT Bombay. Thank you for joining.
  
 
|}
 
|}

Revision as of 23:34, 6 July 2015

Timee Narration
00:01 Dear friends, welcome to the spoken tutorial on More on redirection.
00:07 In this tutorial, we will learn:
  • Redirection of both standard error and output ;
00:13 * Appending redirected output
00:15 with the help of some examples.
00:19 To follow this tutorial, you should have knowledge of Shell Scripting in BASH.
00:25 If not, for relevant tutorials, please visit our website which is as shown. http://www.spoken-tutorial.org
00:30 For this tutorial, I am using:
  • Ubuntu Linux 12.04 Operating System
00:35 * GNU BASH version 4.2.
00:39 Please note, GNU Bash version 4 or above is recommended for practice.
00:46 In an earlier tutorial, we learned about standard output and standard errors.
00:52 Both stderr as well as the stdout can be redirected to the same file.
00:58 This can be done in multiple ways.
01:01 We will cover two of the most important methods of redirection in this tutorial.
01:08 The first method to redirect both the standard output and error is by using &>(ampersand) followed by greater-than sign.
01:18 The syntax is command space ampersand greater than space filename.
01:25 Let me open a file named redirect.sh.
01:30 I have typed some code in this file.
01:32 This is the shebang line.
01:36 ls lists the directory content of 2 directories namely /usr and /user.
01:44 Note that /user directory does not exist.
01:48 Hence the command ls will throw an error.
01:52 &(ampersand) followed by greater than will redirect stdout and stderr to out_(underscore)file.txt.
02:03 Now save the file.
02:05 Let us run the file redirect.sh.
02:07 Open the terminal using CTRL + ALT + T keys simultaneously on your keyboard.
02:15 Type: chmod space plus x space redirect dot sh
02:23 Press Enter.
02:25 Type: dot slash redirect dot sh
02:28 Press Enter.
02:30 We can see the output by opening out_(underscore)file.(dot)txt.
02:36 Type: cat space out_(underscore)file.(dot)txt.
02:42 We can see both the error and output.
02:48 The error for directory /user is recorded in this file.
02:51 It says that there was no '/user' directory found.
02:56 The directory content for /usr is displayed.
03:00 Please note that the content for '/usr' directory may vary on your system.
03:06 Now, let us delete this file. So, on the terminal, type: rm space out_(underscore)file. (dot)txt.
03:15 Another method is to use 2 greater than ampersand 1 after the filename.
03:24 The syntax is command space greater than filename space 2 greater than ampersand 1.
03:33 We can also redirect to slash dev slash null (/dev/null) file.
03:39 Let us learn a little more about slash dev slash null (/dev/null) file.
03:45 It is a special kind of file.
03:48 It is a null file or a place where we can dump anything.
03:52 It includes the output and error messages.
03:57 It is also called as bit bucket.
04:00 Let us now come back to our code in gedit.
04:04 Let us redirect both standard output and error to the null file.
04:11 I will copy this line of code and paste it below over here.
04:16 I want both the output and error messages to be discarded.
04:21 So I will change this part of the copied code. > (greater than) means truncate or write.
04:30 slash dev slash null is the null file 2>&1 (2 greater than ampersand 1).
04:37 Number “2” will redirect standard error to standard output, denoted by number “1”.
04:45 Now click on Save. Save the code.
04:48 Let us run the file redirect.sh.
04:52 Go to the terminal.
04:54 Recall the previous command with the up-arrow key. dot slash redirect.sh and press Enter.
05:03 We can see the output by typing cat out_(underscore)file.(dot)txt.
05:11 Come back to our slides.
05:15 We can capture as well as append standard output or error to a file.
05:21 The output or the error will be appended at the end of the file.
05:26 If the file does not exist, it will create a new file.
05:31 The syntax is command space greater than greater than space followed by filename .
05:41 Let us understand this using an example.
05:45 Let me open the file redirect.(dot)sh.
05:49 Now, here let's type: date space greater than greater than space out_(underscore)file.(dot)txt.
06:00 The 'date' command will simply display the system date as output.
06:06 We can check this command on the terminal by typing 'date.'
06:11 Come back to the terminal. Type date. You can see that the system date i.e. the current date is displayed.
06:23 The output of date command will be appended to the out_(underscore)file.(dot)txt file.
06:31 We are using this file to capture standard output and error of ls command.
06:39 Click on Save
06:40 Switch to the terminal.
06:43 Now press the up-arrow key. Recall the previous command dot slash redirect dot sh.
06:50 and press Enter.
06:52 Let us check the output by opening out_(underscore) file.(dot)txt.
06:59 Type: cat space out_(underscore)file.(dot)txt
07:05 Observe that the output of 'date' command is appended to the end of the file.
07:12 This brings us to the end of this tutorial.
07:15 Let us summarize.
07:17 In this tutorial, we learnt:
07:19 Redirection of both standard error and output;

And to append the redirected output.

07:27 As an assignment:
07:29 Create X_(underscore)file.(dot)txt file with some content.
07:34 Redirect the content of both out_(underscore)file.(dot)txt and X_(underscore)file.(dot)txt to a new file.
07:44 Watch the video available at the link shown below.
07:47 It summarizes the Spoken-Tutorial project.
07:51 If you do not have good bandwidth, you can download and watch it.
07:56 The Spoken Tutorial Project team:
  • Conducts workshops using spoken tutorials.
  • Gives certificates to those who pass an online test.
08:06 For more details, please write to contact@spoken-tutorial.org
08:13 Spoken Tutorial project is a part of the Talk to a Teacher project.
08:17 It is supported by the National Mission on Education through ICT, MHRD, Government of India.

More information on this mission is available at http://spoken-tutorial.org/NMEICT-Intro

08:30 The script has been contributed by FOSSEE and Spoken-Tutorial teams.
08:37 This is Ashwini from IIT Bombay. Thank you for joining.

Contributors and Content Editors

Pratik kamble, Sandhya.np14