diff options
46 files changed, 3216 insertions, 3066 deletions
diff --git a/Version_Control/images/fossee-logo.png b/Version_Control/images/fossee-logo.png Binary files differdeleted file mode 100644 index 49d1797..0000000 --- a/Version_Control/images/fossee-logo.png +++ /dev/null diff --git a/Version_Control/images/iitb-logo.jpg b/Version_Control/images/iitb-logo.jpg Binary files differdeleted file mode 100644 index 2a63fae..0000000 --- a/Version_Control/images/iitb-logo.jpg +++ /dev/null diff --git a/Version_Control/images/folder.png b/Version_Control/vcs1/folder.png Binary files differindex 42d01a2..42d01a2 100644 --- a/Version_Control/images/folder.png +++ b/Version_Control/vcs1/folder.png diff --git a/Version_Control/images/mercurial_logo.png b/Version_Control/vcs1/mercurial_logo.png Binary files differindex 4cd736e..4cd736e 100644 --- a/Version_Control/images/mercurial_logo.png +++ b/Version_Control/vcs1/mercurial_logo.png diff --git a/Version_Control/vcs1/vcs1.rst b/Version_Control/vcs1/vcs1.rst index 4442553..ff99b18 100644 --- a/Version_Control/vcs1/vcs1.rst +++ b/Version_Control/vcs1/vcs1.rst @@ -5,7 +5,11 @@ .. Author : Primal Pappachan Internal Reviewer : Kiran Isukapatla +<<<<<<< HEAD Date: May 10 , 2012 +======= + Date: May 10 2012 +>>>>>>> d0c0139c362aa0d04073fbb901ee81b3c47bf158 -------- Script @@ -16,7 +20,7 @@ Script {{{ Show the first slide containing title, name of the production team along with the logo of MHRD}}} -i.. R1 +.. R1 Hello friends and welcome to the tutorial on 'Version Control with Hg' @@ -41,46 +45,84 @@ At the end of this tutorial you will be able to .. R3 +<<<<<<< HEAD First, let's understand what 'Version Control' is. 'Version control' is a way to track files over time and share them. This allows access to earlier versions of a file(s) if and when required. It therefore enables us to make changes to the content of a file, view it's change log and collaborate on a single piece of work with a team of people. - +======= +First, let's understand what 'Version Control' is. +>>>>>>> d0c0139c362aa0d04073fbb901ee81b3c47bf158 + +'Version control' is a way to track files over time and share them. +This allows access to earlier versions of a file(s) if and when required. +It therefore enables us to make changes to the content of a file, view it's +change log and collaborate on a single piece of work with a team of people. + .. L4 {{{Show the slide 'Home-brewed'}}} .. R4 +<<<<<<< HEAD Let's look at an example of home-brewed Version Control system. Version control is a way of backing up files, before making changes. Most people would have cooked up their own version control system, without realizing, there were tools built by others, that performs the task in a more organized and systematic way. +======= +Lets look at an example of home-brewed Version Control system.Version control +is a way of backing up files, before making changes. Most people would have +cooked up their own version control system. +>>>>>>> d0c0139c362aa0d04073fbb901ee81b3c47bf158 .. L5 -{{{Show the slide 'Problems'}}} +{{{Show the next slide 'Home-brewed'}}} .. R5 +Listing the files in the folder we observe that after a point of time it +becomes difficult to maintain proper names for different versions of a file. + +.. L6 + +{{{Show the slide 'Problems'}}} + +.. R6 + Let's look at the various problems associated with this set-up. 1. Name and changes made are not related or linked. +<<<<<<< HEAD #. Can’t track sequence of changes made to a file. #. Does not scale. .. L6 +======= + +#. Can't track sequence of changes made to a file. + +#. Does not scale. + +To overcome this problems there are more general purpose tools which can +do this task in an organized way. + + +.. L7 +>>>>>>> d0c0139c362aa0d04073fbb901ee81b3c47bf158 {{{Show the slide 'The need for Version Control'}}} -.. R6 +.. R7 Now, let's move to identifying the needs for a 'Version Control System'. +<<<<<<< HEAD We have seen that one of the main motivations to use a Version Control system is the ability to go back to a working version of a file, when something goes wrong. @@ -88,35 +130,64 @@ Below are a few more advantages of using an automated version control system. 1. By tracking the history of a project, any person may see the evolution of a project. +======= +We have seen that one of the main motivations to use a Version Control system +is the ability to go back to a working version of a file, when something +goes wrong. Below are a few more advantages of using an automated version +control system. -#. Allows for effective collaboration on a project, as everything is shared. +1. By tracking the history of a project, any person may see the evolution +of a project. +>>>>>>> d0c0139c362aa0d04073fbb901ee81b3c47bf158 +2. Allows for effective collaboration on a project, as everything is shared. + +<<<<<<< HEAD #. Helps to identify which additions have broken down a project and thus aids in efficient tracking down of the bugs. #. It is good for a one man show as it is for a big group of people working on a project. +======= +3. Helps to identify which additions have broken down a project and thus +aids in efficient tracking down of the bugs. +4. It is good for a one man show as it is for a big group of people working +on a project. +>>>>>>> d0c0139c362aa0d04073fbb901ee81b3c47bf158 -.. L7 + +.. L8 {{{Show the slide 'How does it work? - Analogy}}} -.. R7 +.. R8 It is, in some ways, similar to playing a video game. We generally play games +<<<<<<< HEAD in stages. While playing, we save the game at some instances as per our choice. We continue playing, but we could, if necessary, choose to go back to one of the saved states and start over. In this manner, we could change the state of +======= +in stages. While playing, we save the game at some instances as per our choice. +We continue playing, but we could, if necessary, choose to go back to one of the +saved states and start over. In this manner, we could change the state of +>>>>>>> d0c0139c362aa0d04073fbb901ee81b3c47bf158 the game. -.. L8 +.. L9 {{{Show the slide 'Mercurial or hg'}}} -.. R8 +.. R9 + +Some of the Version Control tools available and used widely are: cvs, svn, +git and so on. -mercurial or hg is: +Each of these tools have their own merits and demerits. In this tutorial we +shall learn how to use mercurial or hg. + +Mercurial or hg is: 1. Easy to learn and use @@ -126,35 +197,55 @@ mercurial or hg is: #. Written in Python -Some of the Version Control tools available and used widely are: +.. L10 -cvs, svn, git and so on. +{{{Show the slide 'Installation'}}} +<<<<<<< HEAD Each of these tools have their own merits and demerits. In this tutorial we shall learn how to use mercurial or hg. +======= +.. R10 +>>>>>>> d0c0139c362aa0d04073fbb901ee81b3c47bf158 -.. L9 +Let's now get into Installation -{{{Show the slide 'Installation'}}} +.. L10 -.. R9 +{{{Switch to terminal}}} +:: + + $sudo apt-get install mercurial -Let's now get into Installation +.. R10 -sudo apt-get install mercurial +Type sudo apt-get install mercurial -$hg +Type hg -and 'hg version' which gives the version number. +.. L12 +:: -$hg version + $hg +.. R12 -.. L10 +It will give you the list of basic commands. + +.. L13 +:: + + $hg version + +.. R13 + +and 'hg version' gives the version number of mercurial you are presently using. + +.. L14 {{{Show the 'summary' slide'}}} -.. R10 +.. R14 This brings us to the end of the tutorial. In this tutorial, we have learnt: @@ -165,28 +256,24 @@ learnt: #. Install Mercurial. -.. L11 +.. L15 {{{Show self assessment questions slide}}} -.. R11 +.. R15 Here are some self assessment questions for you to solve -1. Is Mercurial a Centralized VCS or Distributed -VCS? Justify your reasoning. +1. Is Mercurial a Centralized VCS or Distributed Version Control System? -#. How can you verify whether Mercurial has been -installed properly? +#. How can you retrive the version of Mercurial installed? -#. What is the command for accessing built-in help -system of Mercurial? -.. L12 +.. L16 {{{Show the solutions slide to self assessment questions }}} -.. R12 +.. R16 And the answers, @@ -194,14 +281,56 @@ And the answers, #. hg version -#. hg help command +.. L17 +{{{ Show the SDES & FOSSEE slide }}} -.. L13 +.. R17 + +Software Development techniques for Engineers and Scientists - SDES, is an +initiative by FOSSEE. For more information, please visit the given link. + +Free and Open-source Software for Science and Engineering Education - FOSSEE, is +based at IIT Bombay which is funded by MHRD as part of National Mission on +Education through ICT. + +.. L18 + +{{{ Show the ``About the Spoken Tutorial Project'' slide }}} + +.. R18 + +Watch the video available at the following link. It summarises the Spoken +Tutorial project.If you do not have good bandwidth, you can download and +watch it. + +.. L19 + +{{{ Show the `` Spoken Tutorial Workshops'' slide }}} + +.. R19 + +The Spoken Tutorial Project Team conducts workshops using spoken tutorials, +gives certificates to those who pass an online test. + +For more details, contact contact@spoken-tutorial.org + +.. L20 + +{{{ Show the ``Acknowledgements'' slide }}} + +.. R20 + +Spoken Tutorial Project is a part of the "Talk to a Teacher" project. +It is supported by the National Mission on Education through ICT, MHRD, +Government of India. More information on this mission is available at the +given link. + +.. L21 {{{Show the thank you slide}}} -.. R13 +.. R21 Hope you have enjoyed this tutorial and found it useful. Thank you diff --git a/Version_Control/vcs1/vcs1_rec.rst b/Version_Control/vcs1/vcs1_2col.rst index 01e264e..8e88b2b 100644 --- a/Version_Control/vcs1/vcs1_rec.rst +++ b/Version_Control/vcs1/vcs1_2col.rst @@ -1,7 +1,3 @@ ---------------------------------- -Version Control using Hg Part I ---------------------------------- - .. Prerequisites .. ------------- @@ -9,137 +5,148 @@ Version Control using Hg Part I .. Author : Primal Pappachan Internal Reviewer : Kiran Isukapatla - Date: Jan 27, 2012 + Date: May 10 2012 ----------------------- -Spoken Tutorial Script ----------------------- +-------- +Script +-------- +----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| *{{{ Show the first slide containing title, name of the production team along | Hello friends and welcome to the first part of tutorial on 'Version Control | -| with the logo of MHRD}}}* | using Hg' | +| {{{ Show the first slide containing title, name of the production team along | Hello friends and welcome to the tutorial on 'Version Control with Hg' | +| with the logo of MHRD}}} | | +----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| *{{{Show the slide containing the objectives}}}* | At the end of this tutorial you will be able to | +| {{{Show the slide containing the objectives}}} | At the end of this tutorial you will be able to | | | | -| | 1. Understand what is Version Control | -| | #. Identify the need for using Version Control | -| | #. Install Mercurial and intialize a repository | +| | 1. Understand what is Version Control. | | | | +| | #. Identify the need for using Version Control. | | | | -| | First, let's understand what 'Version Control' is. | +| | #. Install Mercurial. | +----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| *{{{Show the slide 'what is version control'}}*} | 'Version control' is a way to track files over time and share them. This allows | -| | access to earlier versions of a file(s) if and when required. It therefore | -| | enables us to make changes to the content of a file, view it's change log and | -| | collaborate on a single piece of work with a team of people. | +| {{{Show the slide 'what is version control'}}} | First, let's understand what 'Version Control' is. | | | | -| | As the quote from the famous blog post 'Version Control for masses' says | +| | 'Version control' is a way to track files over time and share them. | +| | This allows access to earlier versions of a file(s) if and when required. | +| | It therefore enables us to make changes to the content of a file, view it's | +| | change log and collaborate on a single piece of work with a team of people. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{Show the slide 'Home-brewed'}}} | Lets look at an example of home-brewed Version Control system.Version control | +| | is a way of backing up files, before making changes. Most people would have | +| | cooked up their own version control system. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{Show the next slide 'Home-brewed'}}} | Listing the files in the folder we observe that after a point of time it | +| | becomes difficult to maintain proper names for different versions of a file. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{Show the slide 'Problems'}}} | Let's look at the various problems associated with this set-up. | | | | -| | "Version control is one of those weird, geeky things that never really gained | -| | much ground in non-geek fields, despite the fact that it’s blindingly useful." | +| | 1. Name and changes made are not related or linked. | | | | -| | Over the course of these 3 spoken tutorials, we are going to see a handful of | -| | such things, which are widely used in the programmer world, but not so much in | -| | the scientific computing world, even when if they would be very useful. | -+----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| *{{{Show the slide 'Home-brewed'}}}* | Let's look at an example of home-brewed Version Control system | +| | #. Can't track sequence of changes made to a file. | | | | -| | Version control is a way of backing up files, before making changes. Most | -| | people would have cooked up their own version control system, without | -| | realizing, there were tools built by others, that performs the task in a more | -| | organized and systematic way. | -+----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| *{{{Show the slide 'Problems'}}}* | Let's look at the various problems associated with this set-up. | +| | #. Does not scale. | | | | -| | 1. Name and changes made are not related or linked. | -| | #. Can't track sequence of changes made to a file | -| | #. Does not scale | +| | To overcome this problems there are more general purpose tools which can | +| | do this task in an organized way. | +----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| *{{{Show the slide 'The need for Version Control'}}}* | Having seen the problems of a home brewed setup, let's now move onto | -| | identifying the needs for a 'Version Control System'. | +| {{{Show the slide 'The need for Version Control'}}} | Now, let's move to identifying the needs for a 'Version Control System'. | | | | -| | 1. To err is Human . . . | -| | #. Tracking the history and evolution of a project | -| | #. To collaborate effectively on a project | -| | #. To efficiently track down bugs and pin-point the | -| | #. changes that caused it | -+----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| *{{{Show the slide 'The need for Version Control'}}}* | We have seen that one of the main motivations to use a Version Control system | -| | is the ability to go back to a working version of a file, when something goes | -| | wrong. Below are a few more advantages of using an automated version control | -| | system. | +| | We have seen that one of the main motivations to use a Version Control system | +| | is the ability to go back to a working version of a file, when something | +| | goes wrong. Below are a few more advantages of using an automated version | +| | control system. | +| | | +| | 1. By tracking the history of a project, any person may see the evolution | +| | of a project. | | | | -| | 1. By tracking the history of a project, any person may see the evolution of a p | | | 2. Allows for effective collaboration on a project, as everything is shared. | -| | 3. Helps to identify which additions have broken down a project and thus aids in | -| | 4. It is good for a one man show as it is for a big group of people working on a | | | | -| | Keeping your stuff version controlled will help avoid accidental deletion of | -| | individual files etc. Hosting it on a remote server will protect your sanity | -| | from a hard disk crash. | +| | 3. Helps to identify which additions have broken down a project and thus | +| | aids in efficient tracking down of the bugs. | +| | | +| | 4. It is good for a one man show as it is for a big group of people working | +| | on a project. | +----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| *{{{Show the slide 'How does it work? - Analogy}}}* | It is, in some ways, similar to playing a video game. We generally play games | +| {{{Show the slide 'How does it work? - Analogy}}} | It is, in some ways, similar to playing a video game. We generally play games | | | in stages. While playing, we save the game at some instances as per our choice. | -| | We continue playing, but we could, if necessary, choose to go back to one of | -| | the saved states and start over. In this manner, we could change the course of | +| | We continue playing, but we could, if necessary, choose to go back to one of the | +| | saved states and start over. In this manner, we could change the state of | | | the game. | +----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| *{{{Show the slide 'Mercurial or hg'}}}* | Some of the Version Control tools available and used widely are: | +| {{{Show the slide 'Mercurial or hg'}}} | Some of the Version Control tools available and used widely are: cvs, svn, | +| | git and so on. | | | | -| | 1. cvs(Concurrent Version Systems) | -| | #. svn(subversion) | -| | #. hg(mercurial) | -| | #. git | +| | Each of these tools have their own merits and demerits. In this tutorial we | +| | shall learn how to use mercurial or hg. | | | | +| | Mercurial or hg is: | | | | -| | Each of these tools have their own merits and demerits. In this tutorial we | -| | shall learn how to use mercurial or hg which is easy to learn and use and | -| | comparatively light weight. Once you learn how to use hg, you can easily try | -| | other tools and switch to one that you feel most comfortable with. | +| | 1. Easy to learn and use | +| | | +| | #. Lightweight | | | | -| | Let's now get into Installation. For Linux distributions, Ubuntu and Debian | -| | type the following in command line terminal | +| | #. Scales excellently | +| | | +| | #. Written in Python | +----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| ``sudo apt-get install mercurial`` | For Windows, | +| {{{Switch to terminal}}} | Type sudo apt-get install mercurial | +| :: | | +| | Type hg | +| $sudo apt-get install mercurial | | +----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| ``http://mercurial.selenic.com/downloads/`` | | -| | | -| ``http://hgbook.red-bean.com/read/a-tour-of-mercurial-the-basics.html`` | | | | | -| .. R 11 | | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| :: | It will give you the list of basic commands. | | | | -| For any other Operating system, please refer the hg book for installation | | -| instruction - | | +| $hg | | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| :: | and 'hg version' gives the version number of mercurial you are presently using. | | | | -| Type 'hg' which lists out all the commands | | +| $hg version | | +----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| ``$hg`` | and 'hg version' which gives the version number. | +| {{{Show the 'summary' slide'}}} | This brings us to the end of the tutorial. In this tutorial, we have | +| | learnt: | +| | | +| | 1. What is Version Control. | +| | | +| | #. Identify the need for using Version Control | +| | | +| | #. Install Mercurial. | +----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| ``$hg version`` | This brings us to the end of the tutorial. In this tutorial, we have | -| | seen, | +| {{{Show self assessment questions slide}}} | Here are some self assessment questions for you to solve | +| | | +| | 1. Is Mercurial a Centralized VCS or Distributed Version Control System? | | | | -| *{{{Show the 'summary' slide'}}}* | 1. the motivation to use version control | -| | #. an analogy of version control with playing a video game | -| | #. how to check if mercurial is installed, and it's version using hg version | +| | #. How can you retrive the version of Mercurial installed? | +----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| *{{{Show self assessment questions slide}}}* | Here are some self assessment questions for you to solve | +| {{{Show the solutions slide to self assessment questions }}} | And the answers, | +| | | +| | 1. Mercurial is a Distributed Version Control system. | | | | -| | 1. Is Mercurial a Centralized VCS or Distributed VCS? Justify your reasoning. | -| | #. How can you verify whether Mercurial has been installed properly? | -| | #. What is the command for accessing built-in help system of Mercurial? | +| | #. hg version | +----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| *{{{Show the solutions slide to self assessment questions }}}* | And the answers, | +| {{{ Show the SDES & FOSSEE slide }}} | Software Development techniques for Engineers and Scientists - SDES, is an | +| | initiative by FOSSEE. For more information, please visit the given link. | | | | -| | 1. Mercurial is a Centralized Version Control system. To read more go here, htt | -| | #. $hg version | -| | #. $hg help command | +| | Free and Open-source Software for Science and Engineering Education - FOSSEE, is | +| | based at IIT Bombay which is funded by MHRD as part of National Mission on | +| | Education through ICT. | +----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| *{{{Show the thank you slide}}}* | Hope you have enjoyed this tutorial and found it useful. Feel free to play | -| | around with Mercurial and read the documentation given by hg help command. When | -| | you are ready to move on, please proceed to the second tutorial on 'Version | -| | Control using Hg' | +| {{{ Show the ``About the Spoken Tutorial Project'' slide }}} | Watch the video available at the following link. It summarises the Spoken | +| | Tutorial project.If you do not have good bandwidth, you can download and | +| | watch it. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ Show the `` Spoken Tutorial Workshops'' slide }}} | The Spoken Tutorial Project Team conducts workshops using spoken tutorials, | +| | gives certificates to those who pass an online test. | | | | +| | For more details, contact contact@spoken-tutorial.org | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ Show the ``Acknowledgements'' slide }}} | Spoken Tutorial Project is a part of the "Talk to a Teacher" project. | +| | It is supported by the National Mission on Education through ICT, MHRD, | +| | Government of India. More information on this mission is available at the | +| | given link. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{Show the thank you slide}}} | Hope you have enjoyed this tutorial and found it useful. | | | Thank you | +----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ diff --git a/Version_Control/vcs1/vcs1_slide.tex b/Version_Control/vcs1/vcs1_slide.tex new file mode 100644 index 0000000..24f8ee4 --- /dev/null +++ b/Version_Control/vcs1/vcs1_slide.tex @@ -0,0 +1,270 @@ +\documentclass[17pt,compress]{beamer} +\usepackage{beamerthemesplit} +\mode<presentation> +{ + \usetheme{Warsaw} + \useoutertheme{infolines} + \setbeamercovered{transparent} + \setbeamertemplate{navigation symbols}{} +} +% Taken from Fernando's slides. +\usepackage{ae,aecompl} +\usepackage[scaled=.95]{helvet} + +\usepackage[english]{babel} +\usepackage[latin1]{inputenc} +\usepackage[T1]{fontenc} + +% change the alerted colour to LimeGreen +\definecolor{LimeGreen}{RGB}{50,205,50} +\setbeamercolor{structure}{fg=LimeGreen} +\author[FOSSEE]{} +\institute[IIT Bombay]{} +\date[]{} +% \setbeamercovered{transparent} + +% theme split +\usepackage{verbatim} +\newenvironment{colorverbatim}[1][]% +{% +\color{blue} +\verbatim +}% +{% +\endverbatim +}% + +\usepackage{mathpazo,courier,euler} +\usepackage{listings} +\lstset{language=sh, + basicstyle=\ttfamily\bfseries, + showstringspaces=false, + keywordstyle=\color{black}\bfseries} + +% logo +\logo{\includegraphics[height=1.30 cm]{3t-logo.pdf}} +\logo{\includegraphics[height=1.30 cm]{fossee-logo.pdf} + +\hspace{7.5cm} +\includegraphics[scale=0.99]{../images/fossee-logo.pdf}\\ +\hspace{281pt} +\includegraphics[scale=0.80]{../images/3t-logo.pdf}} + +%%%from primal's doc +\newcommand{\typ}[1]{\lstinline{#1}} +\newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}} +%%% + +\begin{document} + +\sffamily \bfseries +\title +[Version Control with hg] +{Version Control with hg} +\author +[FOSSEE] +{\small Talk to a Teacher\\{\color{blue}\url{http://spoken-tutorial.org}}\\\vspace{0.25cm}National Mission on Education + through ICT\\{\color{blue}\url{ http://sakshat.ac.in}} \\ [1.65cm] + Contributed by FOSSEE Team \\IIT Bombay \\[0.3cm] +} + +% slide 1 +\begin{frame} + \titlepage +\end{frame} + +\begin{frame} +\frametitle{Objectives} +\label{sec-2} + +At the end of this tutorial, you will be able to, +\begin{itemize} + \item Understand what is Version Control + \item Identify the need for using Version Control + \item Install Mercurial +\end{itemize} +\end{frame} + +% Introduction to course-need of version control, history, options available. +\section{Introduction} + +\begin{frame}[fragile] + \begin{block}{What is Version Control?} + + A way to track changes made to files over time, by keeping copies + of files as we change them. + + \end{block} +\end{frame} + +%% Home made version control system? +\begin{frame}[fragile] + \frametitle{Home-brewed} + \begin{center} + An example of a \typ{home-brew} Version Control system + \includegraphics[height=1.7in,width=4in]{folder.png} + %%a screen-shot of folder with all crazy names. + \end{center} +\end{frame} + +\begin{frame}[fragile] + \frametitle{Home-brewed contd.} + \begin{itemize} + \item Listing the files in the folder: + \end{itemize} + \begin{lstlisting} + $ ls + a.out id1.txt id2.txt string.txt + identifier.cpp id.txt pda1.cpp + pda2.cpp pda.cpp pda.txt + \end{lstlisting} %%$ + %% listing out the crazy names +\end{frame} + +\begin{frame}[fragile] + \frametitle{Problems} + \begin{block}{} + \begin{itemize} + \item Name and changes made are not related or linked. + \item Can't track sequence of changes made to a file. + \item Does not scale. + \end{itemize} + \end{block} +\end{frame} + +\begin{frame}[fragile] + \frametitle{The need for Version Control} + \begin{itemize} + \item Tracking the history and evolution of a project + \item To collaborate effectively on a project + \item To efficiently track down bugs and pin-point the changes that + caused it + \item Useful for an individual and a group of people + \end{itemize} +\end{frame} + +%% Introduction to how logs are managed in VCS. +%% A analogy in logs and day-to-day life? +\begin{frame}[fragile] + \frametitle{How does it work? --- Analogy} + It is similar to playing an Video game. + \begin{itemize} + \item We play games in stages + \item Once we finish a stage -- \alert{we SAVE} + \item We continue playing + \item But, if necessary, we could choose from one of the saved + states and start from there + %%\item We could alter the course of the game + \end{itemize} +\end{frame} + +\begin{frame}[fragile] + \frametitle{Mercurial or \typ{hg}} + \centering + \includegraphics[height=.70in,interpolate=true]{mercurial_logo} + \begin{itemize} + \item Easy to learn and use + \item Lightweight + \item Scales excellently + \item Written in Python + \end{itemize} +\end{frame} + + +\begin{frame} + \frametitle{Installation} + \begin{itemize} + \item \$ sudo apt-get install mercurial + \item \$ hg + \item \$ hg version + \end{itemize} +\end{frame} + +\begin{frame}[fragile] + \frametitle{Summary...} + In this tutorial, we have learnt about, + \begin{itemize} + \item What is Version Control + \item The need for using Version Control + \item Installing Mercurial or hg + \end{itemize} +\end{frame} + +\begin{frame}[fragile] + \frametitle{Evaluation} + \begin{enumerate} + \item Is Mercurial a Centralized VCS or Distributed VCS? + \item How can you retrive the version of Mercurial installed? + \end{enumerate} +\end{frame} + +\begin{frame} + \frametitle{Solutions} + \begin{enumerate} + \item Mercurial is a Distributed Version Control system. + \item hg version + \end{enumerate} +\end{frame} + +%%% 5 concluding slides %%% +\begin{frame} +\frametitle{SDES \& FOSSEE} +\begin{center} +\begin{itemize} +\item \small{SDES}\\ +\small{\color{LimeGreen}Software Development techniques for Engineers and Scientists} \\ +\scriptsize An initiative by FOSSEE. \\ +\vspace{3pt} +\scriptsize For more information on SDES, please visit {\color{blue}\url{http://fossee.in/sdes}}\\ +\vspace{12pt} +\item \small{FOSSEE}\\ +\small {\color{LimeGreen}Free and Open-source Software for \\Science and Engineering Education} \\ +\scriptsize Based at IIT Bombay, Funded by MHRD.\\ +\vspace{3pt} +\scriptsize Part of National Mission on Education through ICT (NME-ICT). \\ +\end{itemize} +\end{center} +\end{frame} + +\begin{frame} +\frametitle{About the Spoken Tutorial Project} +\begin{itemize} +\item Watch the video available at {\color{blue}\url{http://spoken-tutorial.org /What\_is\_a\_Spoken\_Tutorial}} +\item It summarises the Spoken Tutorial project +\item If you do not have good bandwidth, you can download and watch it +\end{itemize} +\end{frame} + +\begin{frame} +\frametitle{Spoken Tutorial Workshops}The Spoken Tutorial Project Team +\begin{itemize} +\item Conducts workshops using spoken tutorials +\item Gives certificates to those who pass an online test +\item For more details, please write to \\ \hspace {0.5cm}{\color{blue}contact@spoken-tutorial.org} +\end{itemize} +\end{frame} + +\begin{frame} +\frametitle{Acknowledgements} +\begin{itemize} +\item Spoken Tutorial Project is a part of the Talk to a Teacher project +\item It is supported by the National Mission on Education through ICT, MHRD, Government of India +\item More information on this Mission is available at: \\{\color{blue}\url{http://spoken-tutorial.org/NMEICT-Intro}} +\end{itemize} +\end{frame} + +\begin{frame} + \begin{block}{} + \begin{center} + {\Large THANK YOU!} + \end{center} + \end{block} +\begin{block}{} + \begin{center} + For more Information, visit our website\\ + {\color{blue}\url{http://fossee.in/}} + \end{center} + \end{block} +\end{frame} + +\end{document} diff --git a/Version_Control/vcs1/vcslide1.tex b/Version_Control/vcs1/vcslide1.tex deleted file mode 100644 index 1a5d262..0000000 --- a/Version_Control/vcs1/vcslide1.tex +++ /dev/null @@ -1,205 +0,0 @@ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Version Control Systems -% -% Author: FOSSEE -% Copyright (c) 2012, FOSSEE, IIT Bombay -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -\documentclass[14pt,compress]{beamer} - -\mode<presentation> -{ - \usetheme{Warsaw} - \useoutertheme{infolines} - \setbeamercovered{transparent} -} - -\usepackage[english]{babel} -\usepackage[latin1]{inputenc} -%\usepackage{times} -\usepackage[T1]{fontenc} - -% Taken from Fernando's slides. -\usepackage{ae,aecompl} -\usepackage{mathpazo,courier,euler} -\usepackage[scaled=.95]{helvet} - -\definecolor{darkgreen}{rgb}{0,0.5,0} - -\usepackage{listings} -\lstset{language=bash, - basicstyle=\ttfamily\bfseries, - commentstyle=\color{red}\itshape, - stringstyle=\color{darkgreen}, - showstringspaces=false, - keywordstyle=\color{blue}\bfseries} - -\newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}} - -\newcommand{\typ}[1]{\lstinline{#1}} - -\newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}} } - -\setbeamercolor{emphbar}{bg=blue!20, fg=black} -\newcommand{\emphbar}[1] - -\begin{document} - -\begin{frame} -\begin{center} -\vspace{12pt} -\textcolor{blue}{\huge Version Control with Hg} -\end{center} -\vspace{18pt} -\begin{center} -\vspace{10pt} -\includegraphics[scale=0.95]{../images/fossee-logo.png}\\ -\vspace{5pt} -\scriptsize Developed by FOSSEE Team, IIT-Bombay. \\ -\scriptsize Funded by National Mission on Education through ICT\\ -\scriptsize MHRD,Govt. of India\\ -\includegraphics[scale=0.15]{../images/iitb-logo.jpg}\\ -\end{center} -\end{frame} - -\begin{frame} - \frametitle{Objectives} - At the end of this tutorial, you will be able to: - \begin{itemize} - \item Understand what is Version Control - \item Identify the need for using Version Control - \item Install Mercurial - \end{itemize} -\end{frame} - -%% There are some %$ used just to minimise the effect of $ sign used -%% in lstlisting. In emacs it looks dirty. - -% Introduction to course-need of version control, history, options available. -\section{Introduction} - -\begin{frame} - \frametitle{What is Version Control?} - \begin{block}{} - A way to track changes made to files over time, by keeping copies - of files as we change them. - \end{block} -\end{frame} - -%% Home made version control system? -\begin{frame}[fragile] - \frametitle{Home-brewed} - \begin{center} - An example of a \typ{home-brew} Version Control system - \includegraphics[height=1.8in,width=4.2in]{../images/folder.png} - \end{center} - \begin{lstlisting} -$ ls -a.out id1.txt id2.txt identifier.cpp id.txt lex pda1.cpp pda2.cpp pda.cpp pda.txt string.txt - \end{lstlisting} %%$ - %%a screen-shot of folder with all crazy names. -\end{frame} - -\begin{frame}[fragile] - \frametitle{Problems} - \begin{block}{} - \begin{itemize} - \item Name and changes made are not related or linked. - \item Can't track sequence of changes made to a file. - \item Does not scale. - \end{itemize} - \end{block} -\end{frame} - -\begin{frame}[fragile] - \frametitle{The need for Version Control} - \begin{itemize} - \item \alert{To err is Human} \ldots - \item Tracking the history and evolution of a project - \item To collaborate effectively on a project - \item To efficiently track down bugs and pin-point the changes that - caused it - \end{itemize} -\end{frame} - -%% Introduction to how logs are managed in VCS. -%% A analogy in logs and day-to-day life? -\begin{frame}[fragile] - \frametitle{How does it work? --- Analogy} - It is, in some ways, similar to playing an Video game. - \begin{itemize} - \item We play games in stages - \item Once we finish a stage or a task -- \alert{we SAVE} - \item We continue playing - \item But, if necessary, we could choose from one of the saved - states and start from there - \item We could alter the course of the game - \end{itemize} -\end{frame} - - -\begin{frame} - \frametitle{Mercurial or \typ{hg}} - \begin{center} - \includegraphics[height=.75in,interpolate=true]{../images/mercurial_logo} - \end{center} - \begin{itemize} - \item Easy to learn and use - \item Lightweight - \item Scales excellently - \item Written in Python - \end{itemize} -\end{frame} - -\begin{frame} - \frametitle{Installation} - \begin{itemize} - \item \typ{sudo apt-get install mercurial} - \item TortoiseHg - \item \typ{\$ hg} - \item \typ{\$ hg version} - \end{itemize} -\end{frame} - -\begin{frame}[fragile] -\frametitle{Summary...} -\begin{itemize} -\item Understand what is Version Control -\item Identify the need for using Version Control -\item Install Mercurial or hg -\end{itemize} -\end{frame} - -\begin{frame}[fragile] -\frametitle{Evaluation} -\begin{enumerate} -\item Is Mercurial a Centralized VCS or Distributed VCS? Justify your reasoning. -\item How can you verify whether Mercurial has been installed properly? -\item What is the command for accessing built-in help system of Mercurial? -\end{enumerate} -\end{frame} - -\begin{frame} -\frametitle{Solutions} -\begin{enumerate} -\item Mercurial is a Distributed Version Control system. -\item hg version -\item hg help command -\end{enumerate} -\end{frame} -\begin{frame} - -\begin{block}{} - \begin{center} - \textcolor{blue}{\Large THANK YOU!} - \end{center} - \end{block} -\begin{block}{} - \begin{center} - For more Information, visit our website\\ - \url{http://fossee.in/} - \end{center} - \end{block} -\end{frame} - -\end{document} diff --git a/Version_Control/vcs2/vcs2.rst b/Version_Control/vcs2/vcs2.rst index 57d40bf..5e4b9d0 100644 --- a/Version_Control/vcs2/vcs2.rst +++ b/Version_Control/vcs2/vcs2.rst @@ -22,8 +22,8 @@ with the logo of MHRD}}}* .. R1 -Hello friends and welcome to the second part of tutorial on 'Version Control -using Hg' +Hello friends and welcome to the tutorial on 'Version Control +using Mercurial: Let there a Repo!' .. L2 @@ -40,14 +40,14 @@ continue on this tutorial: .. R3 -At the end of this tutorial you will be able to +At the end of this tutorial you will be able to do the following to a repository - 1. initialize a new repository, + 1. initialize it, #. obtain the status of a repository, - #. add new files to a repository, - #. take snapshots of a repository, - #. view the history of a repository, - #. and set your user information for hg + #. add new files to it, + #. take snapshots, + #. view the history, + #. and also set your user information for hg .. L4 @@ -69,15 +69,21 @@ to the files. .. R5 -A repository can either be started using an init command or an existing -repository could be cloned. Let us look at creating our own repository, now. We -can look at obtaining already existing repositories, at a later stage. +A fresh repository can either be started using an init command or an existing +repository could be cloned. It adds a .hg directory to our working directory. + +Let us look at creating our own repository, now. We can look at obtaining +already existing repositories, at a later stage. + +Switch to your terminal Let's say we have a folder called book, which has all the chapters of a book as text files. Let us convert that folder, into a hg repository. .. L6 +*{{{Switch to terminal}}} + ``$ cd book/`` ``$ ls -a`` @@ -100,6 +106,7 @@ repository using the hg init command .. R7 The .hg directory indicates that our book directory is now a hg repository. + Mercurial keeps all the history of the changes made, and a few other config files, etc. in this directory. The directory, book is called our working directory. @@ -112,54 +119,70 @@ directory. We now have a fresh repository, but all our files are not being tracked or watched by mercurial, yet. We need to explicitly ask it to watch the files, -that we want it to. +that we want it to. Let's first see the status of our repo using the command. .. L9 +*{{{Switch to Terminal}}} + ``$hg status`` +*{{{Show the slides 'Status Report'}}} + .. R9 -Gives the status of our repo. As a beginner, use it often. +It gives the status of our repo. As a beginner, use it often. You can use +'hg help commandname' which gives the details about the command. For example, .. L10 +*{{{Switch to terminal}}}* + ``$hg help 'status'`` .. R10 -You can use 'hg help commandname' which gives the details about the command. -For example. +You can see the status codes listed in the help for status command. .. L11 -``$hg help status`` *{{{Show the slides for 'Status Codes'}}}* .. R11 -Let's now to try to discern what each of the status code associated with the -files mean. By looking at the codes, it is clear that our files are not being -tracked by hg yet. Now let's move onto 'Adding Files'. +Let's now to try to understand what each of the status code associated with the +files in our repository mean. .. L12 *{{{Show the slides for 'Adding files'}}}* +.. R12 + +By looking at the codes, it is clear that our files are not being tracked by +hg yet. Now let's move onto 'Adding Files'. + +.. L13 + +*{{{Switch to terminal}}}* + ``$hg add`` -.. R12 + +.. R13 This simply adds all the files in the (working) directory, to the repository. -As expected, the status command shows an A before he file names. We could also +As expected, the status command shows an A before the file names. We could also specify files individually, for example -.. L13 +.. L14 ``$ hg add chapter1.txt`` -.. R13 +*{{{Show the slides for 'Adding files'}}}* + +.. R14 If you have deleted files, hg status will show you the status code !. You can, then, tell hg to stop tracking these files, using the hg remove command. Look @@ -177,6 +200,8 @@ time. We do this by using the commit command. .. L15 +*{{{Switch to Terminal}}}* + ``$ hg commit -u "Primal Pappachan <primal@fossee.in>" -m "Initial Commit."`` .. R15 @@ -218,7 +243,7 @@ the change that we just made to our repository. hg log gives the log of the changes made in the form of changesets. A changeset is a set of changes made to the repository between two consecutive commits. It also shows the date at which the commit was made. Please have a look of the -various aspects of the changeset. +various aspects of the changeset mentioned in the slide. .. L19 @@ -240,6 +265,7 @@ add the username details and our editor preferences. .. L20 +*{{{Switch to terminal}}}* ``vim ~/.hgrc`` @@ -265,7 +291,7 @@ Some Recommended Practices for commit messages #. Single line summary, 60 to 65 characters long #. Followed by paragraphs of detailed description - * Why the change? + * Why the change? * What does it effect? * Known bugs/issues? * etc. @@ -280,7 +306,7 @@ This brings us to the end of the tutorial. In this tutorial, we have seen, 1. how to initialize a new repository using hg init, - #. get the status of a repository using hg status and meaning of it's status codes + #. get the status of a repository using hg status and meaning of status codes #. make commits of changes to files, using hg commit #. view the history of the repository using the hg log command, #. set our user information in the global hgrc file. @@ -294,16 +320,17 @@ seen, Here are some self assessment questions for you to solve 1. How can you tell hg to stop tracking deleted files? - 2. What happens when 'hg commit' command is run first time without specifying u + 2. What happens when 'hg commit' command is run first time without specifying + -u paramter? 3. Here's a part of the output that is printed in 'hg log': changeset: 1:2278160e78d4 tag: tip user: Primal Pappachan <primal@fossee.in> date: Sat Jan 26 22:16:53 2012 +0530 - summary: Added Readme - Try to identify each component of this changeset and it’s - meaning. In the changeset, what is the significance of the - number as well as hexadecimal string? + summary: Added Readme + Try to identify each component of this changeset and it’s meaning. In the + changeset, what is the significance of the number as well as hexadecimal + string in the first line? .. L24 @@ -313,12 +340,20 @@ Here are some self assessment questions for you to solve And the answers, - 1. If you have deleted files, hg status will show you the status code ! - 2. The revision number is a handy notation that is only valid in that repository. The hexadecimal string is the permanent, unchanging identifier that will always identify that exact changeset in every copy of the repository. - 3. If you have set the EMAIL environment variable, this will be used. Next, Mercurial will query your system to find out your - local user name and host name, and construct a username from these components. Since this often results in a username that is not very useful, it will print a warning if it has to do this. If all of these mechanisms fail, Mercurial will - fail, printing an error message. In this case, it will not let you commit until you set up a username. - + 1. If you have deleted files, hg status will show you the status code !. You + can use hg remove command to tell mercurial to stop tracking files. + + 2. If you have set the EMAIL environment variable, this will be used. Next, + Mercurial will query your system to find out your local user name and host + name, and construct a username from these components. Since this often results + in a username that is not very useful, it will print a warning if it has to do + this. If all of these mechanisms fail, Mercurial will fail, printing an error + message. In this case, it will not let you commit until you set up a username. + + 3. The revision number is a handy notation that is only valid in that + repository. The hexadecimal string is the permanent, unchanging identifier + that will always identify that exact changeset in every copy of the repository. + .. L25 *{{{Show the thank you slide}}}* @@ -326,9 +361,7 @@ And the answers, .. R25 Hope you have enjoyed this tutorial and found it useful. Feel free to play -around with Mercurial and read the documentation given by hg help command. When -you are ready to move on, please proceed to the third tutorial on 'Version -Control using Hg' +around with Mercurial and read the documentation given by hg help command. Thank you diff --git a/Version_Control/vcs2/vcs2_rec.rst b/Version_Control/vcs2/vcs2twocol.rst index 158725d..f3c0556 100644 --- a/Version_Control/vcs2/vcs2_rec.rst +++ b/Version_Control/vcs2/vcs2twocol.rst @@ -18,20 +18,20 @@ Spoken Tutorial Script +----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| *{{{ Show the first slide containing title, name of the production team along | Hello friends and welcome to the second part of tutorial on 'Version Control | -| with the logo of MHRD}}}* | using Hg' | +| *{{{ Show the first slide containing title, name of the production team along | Hello friends and welcome to the tutorial on 'Version Control | +| with the logo of MHRD}}}* | using Mercurial: Let there a Repo!' | +----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ | *{{{Show the slide 'Prerequisite'}}}* | Please make sure that you have gone through the following tutorials before you | | | continue on this tutorial: | +----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| *{{{Show the slide 'Objectives'}}}* | At the end of this tutorial you will be able to | +| *{{{Show the slide 'Objectives'}}}* | At the end of this tutorial you will be able to do the following to a repository | | | | -| | 1. initialize a new repository, | +| | 1. initialize it, | | | #. obtain the status of a repository, | -| | #. add new files to a repository, | -| | #. take snapshots of a repository, | -| | #. view the history of a repository, | -| | #. and set your user information for hg | +| | #. add new files to it, | +| | #. take snapshots, | +| | #. view the history, | +| | #. and also set your user information for hg | +----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ | *{{{Show the slide for 'We need a repo!'}}}* | To start using Mercurial (or hg) and get the benefits of using a version | | | control system, we should first have a repository. | @@ -41,54 +41,62 @@ Spoken Tutorial Script | | space, hg doesn't save all files, but only saves only a series of changes made | | | to the files. | +----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| *{{{Show the slide 'Initializing a Repo'}}}* | A repository can either be started using an init command or an existing | -| | repository could be cloned. Let us look at creating our own repository, now. We | -| | can look at obtaining already existing repositories, at a later stage. | +| *{{{Show the slide 'Initializing a Repo'}}}* | A fresh repository can either be started using an init command or an existing | +| | repository could be cloned. It adds a .hg directory to our working directory. | +| | | +| | Let us look at creating our own repository, now. We can look at obtaining | +| | already existing repositories, at a later stage. | +| | | +| | Switch to your terminal | | | | | | Let's say we have a folder called book, which has all the chapters of a book as | | | text files. Let us convert that folder, into a hg repository. | +----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| ``$ cd book/`` | We have three chapters in the folder. We convert this folder into a mercurial | +| *{{{Switch to terminal}}} | We have three chapters in the folder. We convert this folder into a mercurial | | | repository using the hg init command | +| ``$ cd book/`` | | +| | | | ``$ ls -a`` | | | | | | ``. .. chapter1.txt chapter2.txt chapter3.txt`` | | +----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ | ``$ hg init`` | The .hg directory indicates that our book directory is now a hg repository. | -| | Mercurial keeps all the history of the changes made, and a few other config | -| ``$ ls -a`` | files, etc. in this directory. The directory, book is called our working | -| | directory. | -| ``. .. .hg chapter1.txt chapter2.txt chapter3.txt`` | | +| | | +| ``$ ls -a`` | Mercurial keeps all the history of the changes made, and a few other config | +| | files, etc. in this directory. The directory, book is called our working | +| ``. .. .hg chapter1.txt chapter2.txt chapter3.txt`` | directory. | +----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ | *{{{Show the slides 'Status Report'}}}* | We now have a fresh repository, but all our files are not being tracked or | | | watched by mercurial, yet. We need to explicitly ask it to watch the files, | -| | that we want it to. | +| | that we want it to. Let's first see the status of our repo using the command. | +----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| ``$hg status`` | Gives the status of our repo. As a beginner, use it often. | +| *{{{Switch to Terminal}}} | It gives the status of our repo. As a beginner, use it often. You can use | +| | 'hg help commandname' which gives the details about the command. For example, | +| ``$hg status`` | | +| | | +| *{{{Show the slides 'Status Report'}}} | | +----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| ``$hg help 'status'`` | You can use 'hg help commandname' which gives the details about the command. | -| | For example. | +| *{{{Switch to terminal}}}* | You can see the status codes listed in the help for status command. | +| | | +| ``$hg help 'status'`` | | +----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| ``$hg help status`` | Let's now to try to discern what each of the status code associated with the | -| | files mean. By looking at the codes, it is clear that our files are not being | -| | tracked by hg yet. Now let's move onto 'Adding Files'. | -| *{{{Show the slides for 'Status Codes'}}}* | | +| *{{{Show the slides for 'Status Codes'}}}* | Let's now to try to understand what each of the status code associated with the | +| | files in our repository mean. | +----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| ``$hg add`` | This simply adds all the files in the (working) directory, to the repository. | -| | As expected, the status command shows an A before he file names. We could also | -| | specify files individually, for example | +| *{{{Show the slides for 'Adding files'}}}* | By looking at the codes, it is clear that our files are not being tracked by | +| | hg yet. Now let's move onto 'Adding Files'. | +----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| ``$ hg add chapter1.txt`` | If you have deleted files, hg status will show you the status code !. You can, | -| | then, tell hg to stop tracking these files, using the hg remove command. Look | -| | at hg help remove for more details. | +| *{{{Switch to terminal}}}* | This simply adds all the files in the (working) directory, to the repository. | +| | As expected, the status command shows an A before the file names. We could also | +| ``$hg add`` | specify files individually, for example | +----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ | *{{{Show the slides 'Taking Snapshots'}}}* | We have added a set of new files to the repository, but we haven't told | | | mercurial to remember these changes, i.e., to take a snapshot at this point in | | | time. We do this by using the commit command. | +----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| ``$ hg commit -u "Primal Pappachan <primal@fossee.in>" -m "Initial Commit."`` | The -u parameter allows us to specify the user details. It is a general good | +| *{{{Switch to Terminal}}}* | The -u parameter allows us to specify the user details. It is a general good | | | practice to use full name followed by the email id. The -m parameter allows us | -| | to give the commit message --- a message describing the changes that are being | +| ``$ hg commit -u "Primal Pappachan <primal@fossee.in>" -m "Initial Commit."`` | to give the commit message --- a message describing the changes that are being | | | committed. | | | | | | Mercurial has now taken a snapshot of our repository and has attached our | @@ -105,7 +113,7 @@ Spoken Tutorial Script | ``$ hg log`` | hg log gives the log of the changes made in the form of changesets. A changeset | | | is a set of changes made to the repository between two consecutive commits. It | | | also shows the date at which the commit was made. Please have a look of the | -| | various aspects of the changeset. | +| | various aspects of the changeset mentioned in the slide. | +----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ | *{{{Show the slide 'User Information'}}}* | There are two aspects which can be improved upon. Firstly, it is unnecessary to | | | keep typing the user information each and every time we make a commit. | @@ -119,7 +127,9 @@ Spoken Tutorial Script | | For linux systems, we open the configuration file in our favorite editor and | | | add the username details and our editor preferences. | +----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| ``vim ~/.hgrc`` | We have now set the user-name details for mercurial to use. | +| *{{{Switch to terminal}}}* | We have now set the user-name details for mercurial to use. | +| | | +| ``vim ~/.hgrc`` | | | | | | ``[ui]`` | | | | | @@ -133,16 +143,16 @@ Spoken Tutorial Script | | #. Single line summary, 60 to 65 characters long | | | #. Followed by paragraphs of detailed description | | | | -| | * Why the change? | +| | * Why the change? | | | * What does it effect? | | | * Known bugs/issues? | | | * etc. | +----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| *{{{Show the 'summary' slide'}}}* | This brings us to the end of the tutorial. In this tutorial, we have | +| *{{{Show the 'Summary' slide}}}* | This brings us to the end of the tutorial. In this tutorial, we have | | | seen, | | | | | | 1. how to initialize a new repository using hg init, | -| | #. get the status of a repository using hg status and meaning of it's status co | +| | #. get the status of a repository using hg status and meaning of status codes | | | #. make commits of changes to files, using hg commit | | | #. view the history of the repository using the hg log command, | | | #. set our user information in the global hgrc file. | @@ -150,24 +160,36 @@ Spoken Tutorial Script | {{{Show self assessment questions slide}}} | Here are some self assessment questions for you to solve | | | | | | 1. How can you tell hg to stop tracking deleted files? | -| | 2. Here's a part of the output that is printed in 'hg log'.Try to identify each | +| | 2. What happens when 'hg commit' command is run first time without specifying | +| | -u paramter? | +| | 3. Here's a part of the output that is printed in 'hg log': | | | changeset: 1:2278160e78d4 | | | tag: tip | | | user: Primal Pappachan <primal@fossee.in> | | | date: Sat Jan 26 22:16:53 2012 +0530 | | | summary: Added Readme | -| | 3. What happens when 'hg commit' command is run first time without specifying u | +| | Try to identify each component of this changeset and it’s meaning. In the | +| | changeset, what is the significance of the number as well as hexadecimal | +| | string in the first line? | +----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ | *{{{Show the solutions slide to self assessment questions }}}* | And the answers, | | | | -| | 1. If you have deleted files, hg status will show you the status code !. You ca | -| | 2. The revision number is a handy notation that is only valid in that repositor | -| | 3. If you have set the EMAIL environment variable, this will be used. Next, Mer | +| | 1. If you have deleted files, hg status will show you the status code !. You | +| | can use hg remove command to tell mercurial to stop tracking files. | +| | | +| | 2. If you have set the EMAIL environment variable, this will be used. Next, | +| | Mercurial will query your system to find out your local user name and host | +| | name, and construct a username from these components. Since this often results | +| | in a username that is not very useful, it will print a warning if it has to do | +| | this. If all of these mechanisms fail, Mercurial will fail, printing an error | +| | message. In this case, it will not let you commit until you set up a username. | +| | | +| | 3. The revision number is a handy notation that is only valid in that | +| | repository. The hexadecimal string is the permanent, unchanging identifier | +| | that will always identify that exact changeset in every copy of the repository. | +----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ | *{{{Show the thank you slide}}}* | Hope you have enjoyed this tutorial and found it useful. Feel free to play | -| | around with Mercurial and read the documentation given by hg help command. When | -| | you are ready to move on, please proceed to the third tutorial on 'Version | -| | Control using Hg' | +| | around with Mercurial and read the documentation given by hg help command. | | | | | | Thank you | +----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ diff --git a/Version_Control/vcs2/vcslide2.tex b/Version_Control/vcs2/vcslide2.tex index 4ab4ecf..c17c7fc 100644 --- a/Version_Control/vcs2/vcslide2.tex +++ b/Version_Control/vcs2/vcslide2.tex @@ -43,45 +43,49 @@ \setbeamercolor{emphbar}{bg=blue!20, fg=black} \newcommand{\emphbar}[1] +\author[Primal Pappachan] {} +\institute[FOSSEE group] {} + +\date[IIT Bombay] {} + \begin{document} \begin{frame} \begin{center} -\vspace{12pt} -\textcolor{blue}{\huge Version Control Using Hg - Part 2} +\vspace{15pt} +\textcolor{blue}{\large Version Control Using Mercurial} \\ +\textcolor{blue}{\huge Let there be a Repo!} \end{center} -\vspace{18pt} +\vspace{15pt} \begin{center} -\vspace{10pt} \includegraphics[scale=0.95]{../images/fossee-logo.png}\\ \vspace{5pt} \scriptsize Developed by FOSSEE Team, IIT-Bombay. \\ \scriptsize Funded by National Mission on Education through ICT\\ -\scriptsize MHRD,Govt. of India\\ +\scriptsize MHRD, Govt. of India\\ \includegraphics[scale=0.15]{../images/iitb-logo.jpg}\\ \end{center} \end{frame} \begin{frame} \frametitle{Prerequisite} - \textbf{Version Control Using Hg} \begin{itemize} - \item Part I + \item \textbf{Version Control Using Mercurial} \end{itemize} \end{frame} \begin{frame} \frametitle{Objectives} - At the end of this tutorial, you will be able to: + At the end of this tutorial, you will be able to do the following to a repository: \begin{itemize} - \item Initialize a new repository, - \item Obtain the status of a repository, - \item Add new files to a repository, - \item Take snapshots of a repository, - \item View the history of a repository, - \item Set your user information for hg + \item Initialize it + \item Obtain the status, + \item Add new files to it, + \item Take snapshots, + \item View the history, + \item \textcolor{blue}{And also} Set your user information for hg \end{itemize} \end{frame} @@ -92,10 +96,8 @@ \frametitle{We need a repo!} \begin{itemize} \item A Repository (repo) is where all the action is! - \item Project files along with a special directory that stores all the - changes - \item We take snapshots of the whole repository; not individual - files. + \item Project files along with a special directory that stores all the changes + \item We take snapshots of the whole repository; not individual files. \end{itemize} \end{frame} @@ -231,8 +233,13 @@ \frametitle{Solutions} \begin{enumerate} \item \small{hg remove} -\item \small{The revision number is a handy notation that is only valid in that repository. The hexadecimal string is the permanent, unchanging identifier that will always identify that exact changeset in every copy of the repository} -\item \small{If you have set the EMAIL environment variable, this will be used. Next, Mercurial will query your system to find out your local user name and host name, and construct a username from these components. Since this often results in a username that is not very useful, it will print a warning if it has to do this. If all of these mechanisms fail, Mercurial will fail, printing an error message. In this case, it will not let you commit until you set up a username.} +\item \small{Initially it looks for the EMAIL environment variable, if it does not exist +it tries to use a combination of local user name and host name. If both +mechanisms fails, an error message will be printed and user will not be +allowed to commit.} +\item \small{The revision number is a handy notation that is only valid in that +repository. The hexadecimal string is the permanent, unchanging identifier that +will always identify that exact changeset in every copy of the repository} \end{enumerate} \end{frame} \begin{frame} @@ -250,4 +257,4 @@ \end{block} \end{frame} -\end{document}
\ No newline at end of file +\end{document} diff --git a/ult/ult_1/script.rst b/ult/ult_1/script.rst index 4708de6..c05f6a4 100644 --- a/ult/ult_1/script.rst +++ b/ult/ult_1/script.rst @@ -25,7 +25,7 @@ team along with the logo of MHRD }}} .. R1 Hello friends and Welcome to the tutorial on -'Using linux tools - Part 1'. +'Getting started with Linux'. .. L2 @@ -55,7 +55,7 @@ principles established in Unix. It consists of an important and central piece called the Linux kernel, which, manages system resources like process control, networking, peripherals and file system access. This is complemented by the application software, written on top of the kernel that -give the higher level functionality that facilitate the user to carry out +gives the higher level functionality that facilitates the user to carry out various tasks. .. L4 @@ -71,7 +71,7 @@ The security model used in Linux is based on the UNIX idea of security, which is known to be robust and of proven quality. Also, there are no viruses in the GNU/Linux world. -Python is used a lot for scientific computing. Why? Beause, +Linux is used a lot for scientific computing. Why? Beause, we can share our operating system and the libraries that we are using with our co-workers, without any headaches of licensing. There are a host of tools and libraries, that are useful in day-to-day @@ -92,52 +92,72 @@ You can log-in once you provide your authentication details. It is a popular misconception that GNU/Linux doesn't have a GUI (Graphical user interface). It does have a fully functional GUI, but for the purpose of this course we shall start with using the CLI (Command line interface). + +.. R6 + Once your system has booted up, hit ``Ctrl + Alt + F1`` to switch to the command line interface. -You can log out using the ``logout`` command. +.. L6 -.. R6 +{{{ Hit ``Ctrl + Alt + F1'' and login as ``fossee'' with it's password }}} -Now hit ``Ctrl + Alt + F7`` and come back to the GUI. For the purpose -of the spoken tutorials, we shall use the terminal on the GUI. +.. R7 -.. L6 +To logout from the CLI, you can use the ``logout`` command. + +.. L7 + + logout + +.. R8 + +Now hit ``Ctrl + Alt + F7`` and come back to the GUI. + +.. L8 + +{{{ Hit ``Ctrl + Alt + F7`` }}} + +.. R9 + +For the purpose of spoken tutorials, we shall use the terminal on the GUI. + +.. L9 {{{ Open the terminal }}} -.. R7 +.. R10 Now that we have logged in, where are we? To find out the present working directory, we use the ``pwd`` command. -.. L7 +.. L10 :: pwd -.. R8 +.. R11 Now, to see what is in the current directory, we use the ``ls`` command. -.. L8 +.. L11 :: ls -.. R9 +.. R12 It gives us a list of all the files in our present working directory. ``ls`` command takes the directory, in which we want to see the list of files present, as an argument. To see all the files present in the ``Music`` directory, we say -.. L9 +.. L12 :: ls Music -.. R10 +.. R13 Note that everything in GNU/Linux and the Unix world is case sensitive. @@ -146,106 +166,110 @@ What if we wanted the files to be more organized? Say, we would like to put all our work during this course in a separate directory. Let us now create a directory ``sdes`` by saying -.. L10 +.. L13 :: mkdir sees -.. R11 +.. R14 Type ``ls`` to see that a new directory has been created. -.. L11 +.. L14 :: ls -.. L12 +.. L15 {{{ Switch to slide, New folders }}} -.. R12 +.. R15 Also, note that special characters need to be escaped. For example if we wanted to create a directory with the name ``software engineering``, we do it either as - mkdir software\ engineering + mkdir software \\ engineering or as - mkdir "software engineering" + mkdir "software engg" But it is generally a practice to use hyphens or underscores instead of spaces in filenames and directory names. Also in modern GNU/Linux filesystems all characters except the forward slash are allowed. -.. R13 +.. R16 Now that we have seen how to create a new empty directory and navigate into it, let us create a new blank file. We use the ``touch`` command for this. -.. L13 +.. L16 -{{{ Switch to the termninal }}} +{{{ Switch to the terminal }}} :: pwd cd sees touch first -.. R14 +.. R17 This creates a file named first in our present working directory. Use the ``ls`` command to see that the file has been created. -.. L14 +.. L17 :: ls -.. R15 +.. R18 To get a quick description of the command, we could use the ``whatis`` command. It gives a short one-line description of the command that is passed as an argument to it. For example, -.. L15 +.. L18 :: whatis touch -.. R16 +.. R19 To get a more detailed description of the command, we use the ``man`` command. -.. L16 +.. L19 :: man touch -.. R17 +.. R20 This page gives a detailed description of the command. We can see that the ``touch`` command has a whole host of options that can be passed to it. Every command in Linux has such a list of options that can be passed to the command to do specific tasks. Hit the ``q`` key to quit the ``man`` page. +.. L20 + + q + To see the manual on man itself do, -.. L17 +.. L21 :: man man -.. L18 +.. L21 {{{ Switch to slide, Using additional options }}} -.. R18 +.. R22 As you may have observed, often the ``man`` page is a bit too much for quickly cross checking what option to use for a specific task. For this @@ -255,21 +279,23 @@ command. Pause the video here, try out the following exercise and resume the video. -.. L19 +.. L22 + +.. L23 {{{ Show slide with exercise 1 }}} -.. R19 +.. R23 Which option should be used with ``ls`` command to list all the directories, sub-directories and files contained in it? Hint: Use ``man`` or ``--help`` -.. R20 +.. R24 Switch to terminal for solution. -.. L20 +.. L24 {{{continue from paused state}}} {{{ Switch to the terminal }}} @@ -277,78 +303,87 @@ Switch to terminal for solution. ls -R -.. R21 +.. R25 This lists out all the files in the sub-tree of the current directory, recursively. -.. L21 +.. L25 -.. R22 +.. R26 When you wish to create a new directory deep inside a directory structure, using a ``-p`` option with the ``mkdir`` command would be useful. For example,if we wish to create a folder ``scripts`` inside the directory ``linux-tools`` inside the directory ``sees``, we could simply say, -.. L22 +.. L26 :: pwd mkdir -p sees/linux-tools/scripts -.. R23 +.. R27 Let's now say, we wish to remove a directory or a file. How do we find out what command to use? We use the ``apropos`` command to search for commands based on their descriptions. To search for the command to remove a file/directory say, -.. L23 +.. L27 :: apropos remove -.. R24 +.. R28 This gives us a whole list of commands that have the word ``remove``, in their description. Looking through the list tells us that ``rm`` or ``rmdir`` is the command to use. -.. L24 +.. L28 -.. L25 +.. L29 {{{ Show summary slide }}} -.. R25 +.. R29 This brings us to the end of the tutorial.In this tutorial, we have learnt to, 1. Understand the basic structure of linux and it's need. - #. Move around in directories and files. + #. Use ``pwd'' command, to check the current working directory. + #. List a directory's contents by using the command ``ls''. + +.. L30 + +{{{ Show the Summary... slide }}} + +.. R30 + #. Use commands like ``mkdir`` and ``rmdir`` to make and remove directories respectively. #. Use commands such as ``man`` and ``whatis`` to get a description of what a particular command does. + #. Search the manual page names and descriptions, using the “ apropos” command. -.. L26 +.. L31 {{{ Show self assessment questions slide }}} -.. R26 +.. R31 Here are some self assessment questions for you to solve -1. Which is the default directory after logging into the terminal? +1. What is the default directory after logging into the terminal? 2. How to view file attributes with ls command? -.. L27 +.. L32 {{{ Solution of self assessment questions on slide }}} -.. R27 +.. R32 And the answers, @@ -361,11 +396,56 @@ And the answers, ls -l <filename> -.. L28 +.. L33 + +{{{ Show the SDES & FOSSEE slide }}} + +.. R33 + +Software Development techniques for Engineers and Scientists - SDES, is an +initiative by FOSSEE. For more information, please visit the given link. + +Free and Open-source Software for Science and Engineering Education - FOSSEE, is +based at IIT Bombay which is funded by MHRD as part of National Mission on +Education through ICT. + +.. L34 + +{{{ Show the ``About the Spoken Tutorial Project'' slide }}} + +.. R34 + +Watch the video available at the following link. It summarises the Spoken +Tutorial project.If you do not have good bandwidth, you can download and +watch it. + +.. L35 + +{{{ Show the `` Spoken Tutorial Workshops'' slide }}} + +.. R35 + +The Spoken Tutorial Project Team conducts workshops using spoken tutorials, +gives certificates to those who pass an online test. + +For more details, contact contact@spoken-tutorial.org + +.. L36 + +{{{ Show the ``Acknowledgements'' slide }}} + +.. R36 + +Spoken Tutorial Project is a part of the "Talk to a Teacher" project. +It is supported by the National Mission on Education through ICT, MHRD, +Government of India. More information on this mission is available at the +given link. + +.. L37 {{{ Show the Thankyou slide }}} -.. R28 +.. R37 Hope you have enjoyed this tutorial and found it useful. Thank you! diff --git a/ult/ult_1/ult1.tex b/ult/ult_1/ult1.tex index 9ad3f03..ca6062b 100644 --- a/ult/ult_1/ult1.tex +++ b/ult/ult_1/ult1.tex @@ -1,59 +1,71 @@ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Using Linux Tools -% -% Author: FOSSEE -% Copyright (c) 2009, FOSSEE, IIT Bombay -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -\documentclass[12pt,compress]{beamer} - +\documentclass[17pt,compress]{beamer} +\usepackage{beamerthemesplit} \mode<presentation> { \usetheme{Warsaw} \useoutertheme{infolines} \setbeamercovered{transparent} + \setbeamertemplate{navigation symbols}{} } +% Taken from Fernando's slides. +\usepackage{ae,aecompl} +\usepackage[scaled=.95]{helvet} \usepackage[english]{babel} \usepackage[latin1]{inputenc} -%\usepackage{times} \usepackage[T1]{fontenc} -% Taken from Fernando's slides. -\usepackage{ae,aecompl} -\usepackage{mathpazo,courier,euler} -\usepackage[scaled=.95]{helvet} +% change the alerted colour to LimeGreen +\definecolor{LimeGreen}{RGB}{50,205,50} +\setbeamercolor{structure}{fg=LimeGreen} +\author[FOSSEE]{} +\institute[IIT Bombay]{} +\date[]{} +% \setbeamercovered{transparent} -\definecolor{darkgreen}{rgb}{0,0.5,0} +% theme split +\usepackage{verbatim} +\newenvironment{colorverbatim}[1][]% +{% +\color{blue} +\verbatim +}% +{% +\endverbatim +}% +\usepackage{mathpazo,courier,euler} \usepackage{listings} \lstset{language=sh, basicstyle=\ttfamily\bfseries, - commentstyle=\color{red}\itshape, - stringstyle=\color{darkgreen}, showstringspaces=false, - keywordstyle=\color{blue}\bfseries} + keywordstyle=\color{black}\bfseries} + +% logo +\logo{\includegraphics[height=1.30 cm]{3t-logo.pdf}} +\logo{\includegraphics[height=1.30 cm]{fossee-logo.pdf} + +\hspace{7.5cm} +\includegraphics[scale=0.99]{../images/fossee-logo.pdf}\\ +\hspace{281pt} +\includegraphics[scale=0.80]{../images/3t-logo.pdf}} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% DOCUMENT STARTS \begin{document} -\begin{frame} +\sffamily \bfseries +\title +[Getting started with Linux] +{Getting started with Linux} +\author +[FOSSEE] +{\small Talk to a Teacher\\{\color{blue}\url{http://spoken-tutorial.org}}\\\vspace{0.25cm}National Mission on Education + through ICT\\{\color{blue}\url{ http://sakshat.ac.in}} \\ [1.65cm] + Contributed by FOSSEE Team \\IIT Bombay \\[0.3cm] +} -\begin{center} -\vspace{12pt} -\textcolor{blue}{\huge Using Linux Tools\\Part I} -\end{center} -\vspace{18pt} -\begin{center} -\vspace{10pt} -\includegraphics[scale=0.95]{../images/fossee-logo.png}\\ -\vspace{5pt} -\scriptsize Developed by FOSSEE Team, IIT-Bombay. \\ -\scriptsize Funded by National Mission on Education through ICT\\ -\scriptsize MHRD,Govt. of India\\ -\includegraphics[scale=0.30]{../images/iitb-logo.png}\\ -\end{center} +% slide 1 +\begin{frame} + \titlepage \end{frame} \begin{frame} @@ -62,26 +74,20 @@ At the end of this tutorial, you will be able to, \begin{itemize} -\item Know what is linux. -\item Understand the need for linux in today's world. -\item Move around in directories and files. -\item Use basic commands of Linux. +\item Know what is Linux +\item Understand the need for Linux in today's world +\item Move around in directories and files +\item Use basic commands of Linux \end{itemize} \end{frame} \begin{frame}[fragile] - \begin{block}{What is the Linux OS?} + \begin{block}{What is \textbf{GNU/Linux} Operating System?} \begin{itemize} - \item Free Open Source Operating System - \begin{description} - \item[Free] - Free as in Free Speech - \item[Open-Source] - Permit modifications and redistribution of source code - \end{description} - \item Also called GNU/Linux - \item Unix-inspired - \item Runs on a variety of hardware + \item Free Open Source Operating System\\ + {\color{LimeGreen}{Free}} Free as in Free Speech\\ + {\color{LimeGreen}{Open-Source}} permits modifications \& redistribution of source code + \item Unix-inspired \& runs on a variety of hardware \item Linux Kernel + Application software \end{itemize} \end{block} @@ -90,14 +96,12 @@ At the end of this tutorial, you will be able to, \begin{frame}[fragile] \frametitle{Why Linux?} \begin{itemize} - \item Free - \item Secure \& versatile + \item Free, secure \& versatile \end{itemize} \begin{block}{Why Linux for Scientific Computing?} \begin{itemize} - \item Free as in Free Speech - \item Can run for \emph{ever} + \item Can run forever \item Libraries \item Parallel Computing \end{itemize} @@ -111,11 +115,12 @@ At the end of this tutorial, you will be able to, \item Command Line for this module \item Hit \texttt{Ctrl + Alt + F1} \item \texttt{logout} command logs you out + \item Hit \texttt{Ctrl + Alt + F7} to come back to GUI \end{itemize} \end{frame} \begin{frame}[fragile] - \frametitle{Creating folders} + \frametitle{New folders} \begin{itemize} \item Special characters need to be escaped OR quoted \end{itemize} @@ -132,20 +137,23 @@ At the end of this tutorial, you will be able to, \frametitle{Using additional options} \begin{itemize} - \item \texttt{-h} or \texttt{--help} gives summary of command usage + \item \texttt{-h} or \texttt{---help} gives summary of command usage \end{itemize} \begin{lstlisting} + $ ls -h $ ls --help \end{lstlisting} % $ \end{frame} \begin{frame} \frametitle{Exercise 1} + Which option should be used with 'ls' command to list all\\ \begin{itemize} - \item Which option should be used with ``ls'' command to list all the directories, - sub-directories and files contained in it? + \item the directories,\\ + \item the sub-directories,\\ + \item the files contained in it \end{itemize} - Hint: Use ``man'' or ``--help'' + Hint: Use \texttt{man} or \texttt{---help} \end{frame} \begin{frame} @@ -156,31 +164,37 @@ At the end of this tutorial, you will be able to, \begin{itemize} -\item Understand the basic structure of linux and it's need. -\item See the current directory in which we are working, using the command ``pwd''. -\item List a directory's contents by using the command ``ls''. -\item Change file timestamps, using the command ``touch''. - \item Use commands like ``mkdir'' and ``rmdir'' to make and remove directories - respectively. -\item Use commands such as ``man'' and ``whatis'' to get a description of - what a particular command does. -\item Search the manual page names and descriptions, using the `` apropos'' command. +\item Understand the basic structure of Linux and it's need +\item Use ``pwd'' command, to check the current working directory +\item List a directory's contents by using the command ``ls'' + +\end{itemize} +\end{frame} + +\begin{frame} +\frametitle{Summary...} +\label{sec-9} +\begin{itemize} +\item Use ``mkdir'' to create, ``rmdir'' to delete directories +\item Use ``man'' and ``whatis'' to get a description of a command +\item Use ``apropos'' to search manual page names and descriptions \end{itemize} \end{frame} + \begin{frame}[fragile] \frametitle{Evaluation} -\label{sec-9} +\label{sec-10} \begin{enumerate} -\item Which is the default directory after logging into the terminal? +\item What is the default directory after logging into the terminal? \vspace{8pt} \item How to view file attributes with ``ls'' command? \end{enumerate} \end{frame} \begin{frame} \frametitle{Solutions} -\label{sec-10} +\label{sec-11} \begin{enumerate} @@ -189,20 +203,65 @@ At the end of this tutorial, you will be able to, \item ls -l <filename> \end{enumerate} \end{frame} + \begin{frame} +\frametitle{SDES \& FOSSEE} +\begin{center} +\begin{itemize} +\item \small{SDES}\\ +\small{\color{LimeGreen}Software Development techniques for Engineers and Scientists} \\ +\scriptsize An initiative by FOSSEE. \\ +\vspace{3pt} +\scriptsize For more information on SDES, please visit {\color{blue}\url{http://fossee.in/sdes}}\\ +\vspace{12pt} +\item \small{FOSSEE}\\ +\small {\color{LimeGreen}Free and Open-source Software for \\Science and Engineering Education} \\ +\scriptsize Based at IIT Bombay, Funded by MHRD.\\ +\vspace{3pt} +\scriptsize Part of National Mission on Education through ICT (NME-ICT). \\ +\end{itemize} +\end{center} +\end{frame} +\begin{frame} +\frametitle{About the Spoken Tutorial Project} +\begin{itemize} +\item Watch the video available at {\color{blue}\url{http://spoken-tutorial.org /What\_is\_a\_Spoken\_Tutorial}} +\item It summarises the Spoken Tutorial project +\item If you do not have good bandwidth, you can download and watch it +\end{itemize} +\end{frame} + +\begin{frame} +\frametitle{Spoken Tutorial Workshops}The Spoken Tutorial Project Team +\begin{itemize} +\item Conducts workshops using spoken tutorials +\item Gives certificates to those who pass an online test +\item For more details, please write to \\ \hspace {0.5cm}{\color{blue}contact@spoken-tutorial.org} +\end{itemize} +\end{frame} + +\begin{frame} +\frametitle{Acknowledgements} +\begin{itemize} +\item Spoken Tutorial Project is a part of the Talk to a Teacher project +\item It is supported by the National Mission on Education through ICT, MHRD, Government of India +\item More information on this Mission is available at: \\{\color{blue}\url{http://spoken-tutorial.org/NMEICT-Intro}} +\end{itemize} +\end{frame} + +\begin{frame} \begin{block}{} \begin{center} - \textcolor{blue}{\Large THANK YOU!} + {\Large THANK YOU!} \end{center} \end{block} \begin{block}{} \begin{center} For more Information, visit our website\\ - \url{http://fossee.in/} + {\color{blue}\url{http://fossee.in/}} \end{center} \end{block} \end{frame} \end{document} - diff --git a/ult/ult_2/script.rst b/ult/ult_2/script.rst index 21db359..6c866da 100644 --- a/ult/ult_2/script.rst +++ b/ult/ult_2/script.rst @@ -3,16 +3,15 @@ .. At the end of this tutorial, you will be able to: - .. 1. Copy files from one location to another. - .. 2. Remove files and directories. - .. 3. Change permissions and ownership of files. - .. 4. Navigate through directories and files. + .. 1. Remove files and directories. + .. 2. Copy files from one location to another. + .. 3. Move files and directories. + .. 4. Know the Linux File Hierarchy .. Prerequisites .. ------------- -.. 1. Using Linux tools - Part 1 - +.. 1. Getting started with Linux Script ------ @@ -25,7 +24,7 @@ team along with the logo of MHRD }}} .. R1 Hello friends and Welcome to the tutorial on -'Using linux tools - Part 2'. +'Basic File handling'. .. L2 @@ -35,10 +34,10 @@ Hello friends and Welcome to the tutorial on At the end of this tutorial, you will be able to, - 1. Copy files from one location to another. - #. Remove files and directories. - #. Change permissions and ownership of files. - #. Navigate through directories and files. + 1. Remove files and directories. + #. Copy files from one location to another. + #. Move files and directories. + #. Know the Linux File Hierarchy .. L3 @@ -47,7 +46,7 @@ At the end of this tutorial, you will be able to, .. R3 Before beginning this tutorial,we would suggest you to complete the -tutorial on "Using Linux tools - Part 1". +tutorial on "Getting started with Linux". .. R4 @@ -59,9 +58,12 @@ Here's example to remove a file named "foo" from the directory "sdes", .. L4 +{{{ Copy the folder /sdes to your home folder }}} +{{{ Open the terminal }}} {{{ Navigate to /home/user/sdes/ }}} :: + ls rm foo ls @@ -101,6 +103,7 @@ how would we do it? pwd cp linux-tools/scripts/foo linux-tools/ + ls linux-tools/ .. R8 @@ -112,10 +115,11 @@ target location,as, :: cp linux-tools/scripts/foo linux-tools/bar + ls linux-tools/ .. R9 -This copies the file ``foo`` to the new location, but with the new name, +A copy the file ``foo`` is created, but with the new name, ``bar``. But, what would have happened if we had a file named ``bar`` already at the @@ -149,7 +153,8 @@ Now, let's try to copy the directory ``sdes`` to a new directory called .. L11 :: - cd /home/user + cd + pwd cp -i sdes course .. R12 @@ -175,22 +180,22 @@ file. Instead, you can make use of only one command which can do this task at one go. The ``mv`` command can move files or directories. It also takes the ``-i`` option to prompt before overwriting. -.. L14 +.. L13 :: cd /home/user mv -i sdes/ course/ -.. R15 +.. R14 Let us understand what exactly happened when we used the ``mv`` command -.. L15 +.. L14 :: ls course -.. R16 +.. R15 We can see that the ``sdes`` directory has been inserted as sub-directory of the ``course`` directory. The move command doesn't over-write @@ -199,12 +204,13 @@ directories, but the ``-i`` option is useful when moving files around. A common way to rename files (or directories), is to copy a file (or a directory) to the same location, with a new name. -.. L16 +.. L15 :: mv sdes/linux-tools sdes/linux + ls sdes -.. R17 +.. R16 It renames the ``linux-tools`` directory to just ``linux`` @@ -213,279 +219,144 @@ within the ``/home/`` directory, but other than that there are many other directories too. Let us take this opportunity to understand a few things about the linux file hierarchy and file permissions. -.. L17 +.. L16 :: cd / {{{ Switch to slide, Linux File Hierarchy }}} -.. R18 +.. R17 The ``/`` directory is called the root directory. All the files and directories, (even if they are on different physical devices) appear as sub-directories of the root directory. -.. L18 +.. L17 {{{ Switch to terminal }}} :: ls -.. R19 +.. R18 You can see the various directories present at the top most level. -.. L19 +.. L18 {{{ Pause for sometime and then continue }}} -.. R20 +.. R19 For more information, it is recommended that you look at the ``man`` page of ``hier``. -.. L20 +.. L19 :: man hier {{{ Pause for sometime and then hit q }}} -.. R21 - -Let us now look at file permissions. Linux is a multi-user environment and -allows users to set permissions to their files to allow only a set of -people to read or write it. Similarly, it is not "safe" to allow system -files to be edited by any user. All this access control is possible in -Linux. -To start, in the root directory, say, +.. L20 .. L21 -:: - - ls -l -.. R22 - -You again get a list of all the sub-directories, but this time with a lot -of additional information. Let us try and understand what this output says -Consider the first line of the output, - -.. L22 - -{{{ Highlight the required portions accordingly while narrating }}} - -.. R23 - -The first column denotes the type and the access permissions of the file. -The second is the number of links. The third and fourth are the owner and -group of the file. The next field is the size of the file in bytes. The -next field is the date and time of modification and the last column is the -file name. -We shall look at the permissions of the file now, ie., the first column of -the output. - -The first character in the first column specifies, whether the item is a -file or a directory. Files have a ``-`` as the first character and -directories have a ``d``. - -The next 9 characters define the access permissions of the file. Before -looking at it, we need to briefly study groups and users and ownership. - -We already know what the first character in the first column (in the output -of ``ls -l``) is for. The rest of the 9 characters are actually sets of 3 -characters of each. The first set of 3 characters defines the permissions -of the user, the next 3 is for the group and the last three is for others. -Based on the values of these characters, access is provided or denied to -files, to each of the users. - -So, what does each of the three characters stand for? Let's suppose we are -looking at the set, corresponding to the permissions of the user. In the -three characters, the first character can either be an ``r`` or a ``-``. -Which means, the user can either have the permissions to read the file or -not. If the character is ``r``, then the user has the permissions to read -the file, else not. Similarly, ``w`` stands for write permissions and -decides whether the user is allowed to write to the file. ``x`` stands for -execute permissions. You cannot execute a file, if you do not have the -permissions to execute it. - -Similarly, the next set of characters decides the same permissions for the -members of the group, that the file is associated with. The last set of -characters defines these permissions for the users, who are neither owners -of the file nor in the group, with which the file is associated. - -Now, it's not as if these permissions cannot be changed. If you are the -owner of a file, you can change the permissions of a file, using the -``chmod`` command. - -.. L23 - -.. R24 - -Let's say, we wish to give the execute permissions for a file, to both the -user and the group, how do we go about doing it? To be more explicit, given -a file ``foo.sh``, with the permissions flags as ``-rw-r--r--``, change it -to ``-rwxr-xr--``. - -The following command does it for us, +{{{ Show summary slide }}} -.. L24 -:: +.. R21 - chmod ug+x foo.sh - ls -l foo.sh +This brings us to the end of the tutorial.In this tutorial, we have learnt to, -.. R25 + 1. Remove files using ``rm`` command. + #. Copy and move files from one location to another, using the ``cp`` + and ``mv`` commands respectively. + #. Learnt the file system hierarchy of Linux. -As you can see, the permissions have been set to the required value. But -what did we exactly do? Let us try and understand. +.. L22 -.. L25 +{{{ Show self assessment questions slide }}} -{{{ Switch to slide,Symbolic modes }}} +.. R22 -.. R26 +Here are some self assessment questions for you to solve -In the command, the parameter ``ug+x`` is the mode parameter to the -``chmod`` command. It specifies the changes that need to be made to the -permissions of the file ``foo.sh``. -The ``u`` and ``g`` stand for the user and group, respectively. The ``x`` -stands for the execute permission and ``+`` stands for adding the -specified permission. So, essentially, we are asking ``chmod`` command to -add the execute permission for the user and group. The permission of others -will remain unchanged. +1. How to copy all the contents of one folder into another? -So, if we wished to add the execute permission to all the users, instead of -adding it to just the user and group, we would have instead said +2. How will you rename the file wonderland.txt to alice.txt using the + commands learnt so far? -.. L26 -:: +.. L23 - chmod a+x foo.sh +{{{ Solution of self assessment questions on slide }}} -.. R27 +.. R23 -or +And the answers, -.. L27 +1. We use the ``cp`` command along with a star sign. The star denotes that + it will copy all the files of folder 1 to folder 2. :: - chmod ugo+x foo.sh - -.. R28 - -Pause the video here, try out the following exercise and resume the video. - -.. L28 - -.. L29 - -{{{ Show slide with exercise 1 }}} - -.. R29 - -Change the permissions of a directory along with all of its -sub-directories and files. - -.. L30 - -{{{ Show slide with solution 1 }}} - -.. R30 - -To change the permissions of a directory along with all of its -sub-directories and files, recursively, we use the ``-R`` option -with the chmod command as shown - - chmod go-r -R <directory name>/ - -.. R31 - -It is important to note that the permissions of a file can only be changed -by a user who is the owner of a file or the superuser. - -What if we wish to change the ownership of a file? The ``chown`` command is -used to change the owner and group. -By default, the owner of a file (or directory) is the user that -created it. The group is a set of users that share the same access -permissions i.e., read, write and execute. -For instance, to change the user and the group of the file -``wonderland.txt`` to ``alice`` and ``users``, respectively, we say. + cp folder1/* folder2 -.. L31 +2. To rename a file, we use the ``mv`` command as, :: - chown fossee:users wonderland.txt - -.. R32 - -We get an error saying, the operation is not permitted. -We have attempted to change the ownership of a file that we own, to a -different user. Logically, this shouldn't be possible, because, this can -lead to problems, in a multi-user system. -Only the superuser is allowed to change the ownership of a file from one -user to another. The superuser or the ``root`` user is the only user -empowered to a certain set of tasks and hence is called the superuser. The -command above would have worked, if you did login as the superuser and -then changed the ownership of the file. - -.. L32 - -.. L33 + mv wonderland.txt alice.txt -{{{ Show summary slide }}} +.. L24 -.. R33 +{{{ Show the SDES & FOSSEE slide }}} -This brings us to the end of the tutorial.In this tutorial, we have learnt to, +.. R24 - 1. Copy and move files from one location to another, using the ``cp`` - and ``mv`` commands respectively. - #. Remove files using ``rm`` command. - #. Understand the Linux file hierarchy. - #. Change permissions and ownership of files, using the ``chmod`` - and ``chown`` commands respectively. +Software Development techniques for Engineers and Scientists - SDES, is an +initiative by FOSSEE. For more information, please visit the given link. -.. L34 +Free and Open-source Software for Science and Engineering Education - FOSSEE, is +based at IIT Bombay which is funded by MHRD as part of National Mission on +Education through ICT. -{{{ Show self assessment questions slide }}} +.. L25 -.. R34 +{{{ Show the ``About the Spoken Tutorial Project'' slide }}} -Here are some self assessment questions for you to solve +.. R25 -1. How to copy all the contents of one folder into another? +Watch the video available at the following link. It summarises the Spoken +Tutorial project.If you do not have good bandwidth, you can download and +watch it. -2. How will you rename the file wonderland.txt to alice.txt using the - commands learnt so far? +.. L26 -.. L35 +{{{ Show the `` Spoken Tutorial Workshops'' slide }}} -{{{ Solution of self assessment questions on slide }}} +.. R26 -.. R35 +The Spoken Tutorial Project Team conducts workshops using spoken tutorials, +gives certificates to those who pass an online test. -And the answers, +For more details, contact contact@spoken-tutorial.org -1. We use the ``cp`` command along with a star sign. The star denotes that - it will copy all the files of folder 1 to folder 2. -:: +.. L27 - cp folder1/* folder2 +{{{ Show the ``Acknowledgements'' slide }}} -2. To rename a file, we use the ``mv`` command as, -:: +.. R27 - mv wonderland.txt alice.txt +Spoken Tutorial Project is a part of the "Talk to a Teacher" project. +It is supported by the National Mission on Education through ICT, MHRD, +Government of India. More information on this mission is available at the +given link. -.. L36 +.. L28 {{{ Show the Thankyou slide }}} -.. R36 +.. R28 Hope you have enjoyed this tutorial and found it useful. Thank you! diff --git a/ult/ult_2/ult2.tex b/ult/ult_2/ult2.tex index 9fb0e7e..6592b34 100644 --- a/ult/ult_2/ult2.tex +++ b/ult/ult_2/ult2.tex @@ -1,70 +1,83 @@ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Using Linux Tools -% -% Author: FOSSEE -% Copyright (c) 2009, FOSSEE, IIT Bombay -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -\documentclass[12pt,compress]{beamer} - +\documentclass[17pt,compress]{beamer} +\usepackage{beamerthemesplit} \mode<presentation> { \usetheme{Warsaw} \useoutertheme{infolines} \setbeamercovered{transparent} + \setbeamertemplate{navigation symbols}{} } +% Taken from Fernando's slides. +\usepackage{ae,aecompl} +\usepackage[scaled=.95]{helvet} \usepackage[english]{babel} \usepackage[latin1]{inputenc} -%\usepackage{times} \usepackage[T1]{fontenc} -% Taken from Fernando's slides. -\usepackage{ae,aecompl} -\usepackage{mathpazo,courier,euler} -\usepackage[scaled=.95]{helvet} - -\definecolor{darkgreen}{rgb}{0,0.5,0} +% change the alerted colour to LimeGreen +\definecolor{LimeGreen}{RGB}{50,205,50} +\setbeamercolor{structure}{fg=LimeGreen} +\author[FOSSEE]{} +\institute[IIT Bombay]{} +\date[]{} +% \setbeamercovered{transparent} + +% theme split +\usepackage{verbatim} +\newenvironment{colorverbatim}[1][]% +{% +\color{blue} +\verbatim +}% +{% +\endverbatim +}% +\usepackage{mathpazo,courier,euler} \usepackage{listings} \lstset{language=sh, basicstyle=\ttfamily\bfseries, - commentstyle=\color{red}\itshape, - stringstyle=\color{darkgreen}, showstringspaces=false, - keywordstyle=\color{blue}\bfseries} + keywordstyle=\color{black}\bfseries} + +% logo +\logo{\includegraphics[height=1.30 cm]{3t-logo.pdf}} +\logo{\includegraphics[height=1.30 cm]{fossee-logo.pdf} + +\hspace{7.5cm} +\includegraphics[scale=0.99]{fossee-logo.pdf}\\ +\hspace{281pt} +\includegraphics[scale=0.80]{3t-logo.pdf}} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% DOCUMENT STARTS \begin{document} -\begin{frame} +\sffamily \bfseries +\title +[Basic File Handling] +{Basic File Handling} +\author +[FOSSEE] +{\small Talk to a Teacher\\{\color{blue}\url{http://spoken-tutorial.org}}\\\vspace{0.25cm}National Mission on Education + through ICT\\{\color{blue}\url{ http://sakshat.ac.in}} \\ [1.65cm] + Contributed by FOSSEE Team \\IIT Bombay \\[0.3cm] +} -\begin{center} -\vspace{12pt} -\textcolor{blue}{\huge Using Linux Tools\\Part II} -\end{center} -\vspace{18pt} -\begin{center} -\vspace{10pt} -\includegraphics[scale=0.95]{../images/fossee-logo.png}\\ -\vspace{5pt} -\scriptsize Developed by FOSSEE Team, IIT-Bombay. \\ -\scriptsize Funded by National Mission on Education through ICT\\ -\scriptsize MHRD,Govt. of India\\ -\includegraphics[scale=0.30]{../images/iitb-logo.png}\\ -\end{center} +% slide 1 +\begin{frame} + \titlepage \end{frame} + \begin{frame} \frametitle{Objectives} \label{sec-2} At the end of this tutorial, you will be able to, \begin{itemize} -\item Copy files from one location to another. -\item Remove files and directories. -\item Change permissions and ownership of files. -\item Navigate through directories and files. +\item Remove files and directories +\item Copy files from one location to another +\item Move files and directories +\item Know the Linux File Hierarchy \end{itemize} \end{frame} @@ -72,9 +85,9 @@ At the end of this tutorial, you will be able to, \frametitle{Pre-requisite} \label{sec-3} -Spoken tutorial on - +Spoken tutorial on, \begin{itemize} -\item Using Linux tools -- Part I +\item Getting started with Linux \end{itemize} \end{frame} @@ -82,63 +95,12 @@ Spoken tutorial on - \begin{frame} \frametitle{Linux File Hierarchy} \begin{itemize} - \item \texttt{/} is called the root directory + \item \texttt{/} is the root directory \item The root directory is the topmost level of the hierarchy - \item For details \texttt{man hier} - \end{itemize} -\end{frame} - -\begin{frame}[fragile] - \frametitle{Symbolic modes} - \begin{small} - \begin{center} - \begin{tabular}{lll} - Reference & Class & Description \\ - \hline - u & user & the owner of the file \\ - g & group & users who are members of the file's group \\ - o & others & users who are not hte owner of the file or members of the group \\ - a & all & all three of the above; is the same as \emph{ugo} \\ - \end{tabular} - \end{center} - - \begin{center} - \begin{tabular}{ll} - Operator & Description \\ - \hline - + & adds the specified modes to the specified classes \\ - - & removes the specified modes from the specified classes \\ - = & the modes specified are to be made the exact modes for the specified classes \\ - \end{tabular} - \end{center} - - \begin{center} - \begin{tabular}{lll} - Mode & Name & Description \\ - \hline - r & read & read a file or list a directory's contents \\ - w & write & write to a file or directory \\ - x & execute & execute a file or recurse a directory tree \\ - \end{tabular} - \end{center} - \end{small} -\end{frame} - - -\begin{frame} - \frametitle{Exercise 1} - \begin{itemize} - \item Change the permissions of a directory along with all of its - sub-directories and files. + \item For details \texttt{\em \$man hier} \end{itemize} \end{frame} -\begin{frame} - \frametitle{Solution 1} - \begin{itemize} - \item chmod go-r -R <directory name>/ - \end{itemize} -\end{frame} \begin{frame} \frametitle{Summary} @@ -148,15 +110,14 @@ Spoken tutorial on - \begin{itemize} +\item Remove files using ``rm'' command \item Copy and move files from one location to another, using the ``cp'' - and ``mv'' commands respectively. -\item Remove files using ``rm`` command. -\item Understand the Linux file hierarchy. -\item Change permissions and ownership of files, using the ``chmod'' - and ``chown'' commands respectively. + and ``mv'' commands respectively +\item Learnt the file system hierarchy of Linux \end{itemize} \end{frame} + \begin{frame}[fragile] \frametitle{Evaluation} \label{sec-9} @@ -165,7 +126,7 @@ Spoken tutorial on - \begin{enumerate} \item How to copy all the contents of one folder into another? \vspace{15pt} -\item How will you rename the file wonderland.txt to alice.txt using the +\item How will you rename the file \texttt{\em wonderland.txt} to \texttt{\em alice.txt} using the commands learnt so far? \end{enumerate} \end{frame} @@ -175,26 +136,71 @@ Spoken tutorial on - \begin{enumerate} -\item cp folder1/* folder2 +\item \$ cp folder1/* folder2 \vspace{15pt} -\item mv wonderland.txt alice.txt +\item \$ mv wonderland.txt alice.txt \end{enumerate} \end{frame} + +\begin{frame} +\frametitle{SDES \& FOSSEE} +\begin{center} +\begin{itemize} +\item \small{SDES}\\ +\small{\color{LimeGreen}Software Development techniques for Engineers and Scientists} \\ +\scriptsize An initiative by FOSSEE. \\ +\vspace{3pt} +\scriptsize For more information on SDES, please visit {\color{blue}\url{http://fossee.in/sdes}}\\ +\vspace{10pt} +\item \small{FOSSEE}\\ +\small {\color{LimeGreen}Free and Open-source Software for \\Science and Engineering Education} \\ +\scriptsize Based at IIT Bombay, Funded by MHRD.\\ +\vspace{3pt} +\scriptsize Part of National Mission on Education through ICT \\(NME-ICT). \\ +\end{itemize} +\end{center} +\end{frame} + +\begin{frame} +\frametitle{About the Spoken Tutorial Project} +\begin{itemize} +\item Watch the video available at {\color{blue}\url{http://spoken-tutorial.org /What\_is\_a\_Spoken\_Tutorial}} +\item It summarises the Spoken Tutorial project +\item If you do not have good bandwidth, you can download and watch it +\end{itemize} +\end{frame} + +\begin{frame} +\frametitle{Spoken Tutorial Workshops}The Spoken Tutorial Project Team +\begin{itemize} +\item Conducts workshops using spoken tutorials +\item Gives certificates to those who pass an online test +\item For more details, please write to \\ \hspace {0.5cm}{\color{blue}contact@spoken-tutorial.org} +\end{itemize} +\end{frame} + +\begin{frame} +\frametitle{Acknowledgements} +\begin{itemize} +\item Spoken Tutorial Project is a part of the Talk to a Teacher project +\item It is supported by the National Mission on Education through ICT, MHRD, Government of India +\item More information on this Mission is available at: \\{\color{blue}\url{http://spoken-tutorial.org/NMEICT-Intro}} +\end{itemize} +\end{frame} + \begin{frame} \begin{block}{} \begin{center} - \textcolor{blue}{\Large THANK YOU!} + {\Large THANK YOU!} \end{center} \end{block} \begin{block}{} \begin{center} For more Information, visit our website\\ - \url{http://fossee.in/} + {\color{blue}\url{http://fossee.in/}} \end{center} \end{block} \end{frame} \end{document} - - diff --git a/ult/ult_3/script.rst b/ult/ult_3/script.rst index adc24b8..089adb9 100644 --- a/ult/ult_3/script.rst +++ b/ult/ult_3/script.rst @@ -3,15 +3,14 @@ .. At the end of this tutorial, you will be able to: - .. 1. Display the contents of files. - .. 2. Read only parts of a file. - .. 3. Look at the statistical information of a file. - + .. 1. Change file permissions + .. 2. Change ownership of files + .. Prerequisites .. ------------- -.. 1. Using Linux tools - Part 1 -.. 2. Using Linux tools - Part 2 +.. 1. Getting started with Linux +.. 2. Basic File Handling Script ------ @@ -23,8 +22,7 @@ team along with the logo of MHRD }}} .. R1 -Hello friends and Welcome to the tutorial on -'Using linux tools - Part 3'. +Hello friends and Welcome to the tutorial on "File permissions and ownership". .. L2 @@ -34,9 +32,8 @@ Hello friends and Welcome to the tutorial on At the end of this tutorial, you will be able to, - 1. Display the contents of files. - #. Read only parts of a file. - #. Look at the statistical information of a file. + 1. Change file permissions + #. Change ownership of files .. L3 @@ -45,174 +42,174 @@ At the end of this tutorial, you will be able to, .. R3 Before beginning this tutorial,we would suggest you to complete the -tutorial on "Using Linux tools - Part 1" and "Using Linux tools - Part 2". - -.. R4 - -Let us begin with how to read a while as a whole. -The ``cat`` command is the most commonly used command to display the -contents of files. To view the contents of a file, say, ``foo.txt``, we -simply say, +former tutorials as being displayed currently. .. L4 -:: - cat foo.txt +.. R4 -.. R5 +Let us now look at file permissions. Linux is a multi-user environment and +allows users to set permissions to their files to allow only a set of +people to read or write it. Similarly, it is not "safe" to allow system +files to be edited by any user. All this access control is possible in +Linux. -You can see the contents of the file on the terminal. +.. R5 -The cat command could also be used to concatenate the text of multiple -files. Say, we have two files,``foo.txt`` and ``bar.txt``, +To start, in the root directory, say, .. L5 + +{{{ Open the terminal }}} :: - cat foo.txt bar.txt + cd / + ls -l .. R6 -It shows the output of both the files concatenated on the standard output. -But if we had a long file,the output of ``cat`` command is not convenient -to read. -Let's look at the ``less`` command which turns out to be more useful in -such a case. - -``less `` allows you to view the contents of a text file one screen at a -time. +You get a list of all the sub-directories, with a lot of additional information. +Let us try and understand the output. .. L6 -:: - - less wonderland.txt - -.. R7 - -This shows us the file, one screen at a time. .. L7 -.. L8 +{{{ Highlight the required portions accordingly while narrating }}} -{{{ Show slide with, less }}} +.. R7 -.. R8 +The first column denotes the type and the access permissions of the file. +The second is the number of links. The third and fourth are the owner and +group of the file. The next field is the size of the file in bytes. The +next field is the date and time of modification and the last column is the +file name. +We shall look at the permissions of the file now, ie., the first column of +the output. + +The first character in the first column specifies, whether the item is a +file or a directory. Files have a ``-`` as the first character and +directories have a ``d``. + +The rest of the 9 characters are actually sets of 3 characters each. The +first set of 3 characters defines the permissions of the user, the next 3 +is for the group and the last three is for others. +Based on the values of these characters, access to files is provided or denied, +to each of the users. + +So, what does each of the three characters stand for? Let's suppose, we are +looking at the set, corresponding to the permissions of the user. In the +three characters, the first character can either be an ``r`` or a ``-``. +Which means, the user can either have the permission to read the file or +not. If the character is ``r``, then the user has the permission to read +the file, else not. Similarly, ``w`` stands for write permissions and +decides whether the user is allowed to write to the file or not. ``x`` stands +for execute permissions. You cannot execute a file, if you do not have the +permission to execute it. + +Similarly, the next set of characters decides the same permissions for the +members of the group, that the file is associated with. The last set of +characters defines these permissions for the users, who are neither owners +of the file nor in the group, with which the file is associated. + +Now, it's not as if these permissions cannot be changed. If you are the +owner of a file, you can change the permissions of a file, using the +``chmod`` command. -``less`` has a list of commands that it allows you to use, once you have -started viewing a file. A few of the common ones have been listed below. - * q: Quit. +.. R8 - * [Arrows]/[Page Up]/[Page Down]/[Home]/[End]: Navigation. +Let's say, we wish to give the execute permissions for a file, to both the +user and the group, how do we go about doing it? To be more explicit, given +a file ``foo.sh``, with the permissions flags as ``-rw-r--r--``, change it +to ``-rwxr-xr--``. - * ng: Jump to line number n. Default is the start of the file. +The following command does it for us, - * /pattern: Search for pattern. Regular expressions can be used. +.. L8 +:: - * h: Help. + chmod ug+x foo.sh + ls -l foo.sh .. R9 -Let us move ahead with the topic. Often we just would like to get some -statistical information about the file, rather than viewing the contents -of the file. The ``wc`` command prints these details for a file. +As you can see, the permissions have been set to the required value. But +what did we exactly do? .. L9 -:: - - wc wonderland.txt .. L10 -{{{ Highlight the required portions accordingly while narrating }}} +{{{ Switch to slide,Symbolic modes }}} .. R10 -As you can see, we get some information about the file. -The first number is the number of lines, the second is the number of words -and the third is the number of characters in the file. - -.. R11 - -Let us now look at a couple of commands that let you see parts of files, -instead of the whole file. The ``head`` and ``tail`` commands let you see -parts of files, as their names suggest, the start and the end of a file, -respectively. +Let us understand these parameters one by one. +The ``u`` is the user who is the owner of the file. +``g`` stands for group which consists of users who are members of the +file’s group. The reference ``o``, which we shall use later in the tutorial, +stands for others who are users of the file but not the owners or members of +a group. .. L11 -:: - head wonderland.txt +{{{ Switch to slide,Symbolic modes... }}} -.. R12 +.. R11 -It prints only the first 10 lines of the file. Similarly tail will print the -last 10 lines of the file. If we wish to change the number of lines that we -wish to view, we use the option ``-n``. +Let us now understand the operators. The plus operator adds the specified modes +to the specified classes. The minus operator removes the specified modes from +the specified classes. And finally the equal-to operator is used where modes +specified are to be made the exact modes for the specified classes. .. L12 -:: - head -n 1 wonderland.txt +{{{ Switch to slide,Symbolic modes... }}} -.. R13 +.. R12 -It prints only the first line of the file. Similarly, we could print only -the last line of the file. +We shall now learn the function of each mode. ``r`` stands for read which reads +a file or lists a directory’s contents. ``w`` is for write by which we can +write to a file or a directory. ``x`` stands for execute. As the name suggests, +it executes a file or recurse a directory tree. + +.. L13 -The most common use of the tail command is to monitor a continuously -changing file, for instance a log file. Say you have a process running, -which is continuously logging it's information to a file, for instance the -logs of the system messages. +{{{ Switch to the terminal }}} +{{{ Highlight the command, chmod ug+x foo.sh }}} -.. L13 -:: +.. R13 - tail -f /var/log/dmesg +In the command, the parameter ``ug+x`` is the mode parameter to the +``chmod`` command. It specifies the changes to be made to the +permissions of the file ``foo.sh``. +The ``u`` and ``g`` stand for the user and group, respectively. The ``x`` +stands for the execute permission and ``+`` stands for adding the +specified permission. So, essentially, we are asking ``chmod`` command to +add the execute permission for the user and group. The permission of others +will remain unchanged. .. R14 -This will show the last 10 lines of the file as expected, but along with -that, it starts monitoring the file. Any new lines added at the end of the -file, will be shown. To interrupt tail, while it is monitoring, hit -``Ctrl-C``. which will stop any process that is running from your -current shell. - -We looked at a couple of functions that allowed us to view a part of a file, -line-wise. We shall now look at a couple of commands that will allow us to look -at only certain sections of each line of a file and merge those parts. -Let's take the ``/etc/passwd`` file as our example file. It contains -information about each user of the system. +So, if we wished to add the execute permission to all the users, instead of +adding it to just the user and group, we would have instead said .. L14 :: - cat /etc/passwd + chmod a+x foo.sh .. R15 -In the output, let us look at only the first, fifth, sixth and the last -columns.The first column is the user name, the fifth column is the user info, -the sixth column is the home folder and the last column is the path of the -shell program that the user uses. -Let's say we wish to look at only the user names of all the users in the -file, how do we do it? +or .. L15 :: - - cut -d : -f 1 /etc/passwd -.. R16 + chmod ugo+x foo.sh -It gives us the required output. Let us understand this operation in detail. -The first option ``-d`` specifies the delimiter between the various fields in -the file, in this case it is the semicolon. If no delimiter is specified, -the TAB character is assumed to be the delimiter. The ``-f`` option specifies, -the field number that we want to choose. -You can print multiple fields, by separating the field numbers with a -comma. +.. R16 Pause the video here, try out the following exercise and resume the video. @@ -220,155 +217,152 @@ Pause the video here, try out the following exercise and resume the video. .. L17 -{{{ Show slide with exercise 3 }}} +{{{ Show slide with exercise }}} .. R17 -Print only the first, fifth and the seventh fields of the file ``/etc/passwd``. +Change the permissions of a directory along with all of its +sub-directories and files. -.. R18 +.. L18 -Switch to the terminal for solution +{{{ Show slide with solution }}} -.. L18 +.. R18 -{{{ continue from paused state }}} -{{{ Switch to the terminal }}} +To change the permissions of a directory along with all of its +sub-directories and files, recursively, we use the ``-R`` option +with the chmod command as shown -:: - - cut -d : -f 1,5,7 /etc/passwd + chmod go-r -R <directory name>/ .. R19 -We get the correct output. -Instead of choosing by fields, ``cut`` also allows us to choose on the -basis of characters or bytes. For instance, we could get the first 4 -characters of all the entries of the file, ``/etc/passwd`` by saying, +It is important to note that the permissions of a file can only be changed +by a user who is the owner of a file or the superuser. +The superuser or the ``root`` user is the only user +empowered to a certain set of tasks and hence is called the superuser. +What if we wish to change the ownership of a file? The ``chown`` command is +used to change the owner and group. +By default, the owner of a file (or directory) is the user that +created it. The group is a set of users that share the same access +permissions i.e., read, write and execute. +For instance, to change the user and the group of the file +``wonderland.txt`` to ``alice`` and ``users``, respectively, we say, .. L19 :: - cut -c 1-4 /etc/passwd + chown alice:users wonderland.txt .. R20 -The end limits of the ranges can take sensible default values, if they are -left out. For example, +We get an error saying, the operation is not permitted. +We have attempted to change the ownership of a file that we own, to a +different user. Logically, this shouldn't be possible, because, this can +lead to problems, in a multi-user system. +Only the superuser is allowed to change the ownership of a file from one +user to another. The command above would have worked, if you did login as +the superuser and then changed the ownership of the file. .. L20 -:: - cut -c -4 /etc/passwd +.. L21 + +{{{ Show Summary slide }}} .. R21 -It gives the same output as before. If the start position has not been -specified, it is assumed to be the start of the line. Similarly if the end -position is not specified, it is assumed to be the end of the line. +This brings us to the end of the tutorial.In this tutorial, we have learnt to, -.. L21 -:: + 1. Chane the permissions of files using the ``chmod'' command. + #. Use the ``chown'' command to change the ownership of files. + +.. L22 - cut -c 10- /etc/passwd +{{{ Show self assessment questions slide }}} .. R22 -It prints all the characters from the 10th character up to the end of the -line. -Let us now solve an inverse problem. Let's say we have two columns of data -in two different files, and we wish to view them side by side. +Here are some self assessment questions for you to solve -.. L22 + 1. For a given file, change mode to r, w, x for all (user, group, others) + + 2. What changes, on specifying only an owner in the "chown" command? + + - Only the owner of the file + - The group ownership of the file + - Neither the owner nor the group .. L23 -{{{ Show slide with, paste }}} +{{{ Solution of self assessment questions on slide }}} .. R23 -For instance, given a file containing the names of students in a file, -students.txt, and another file with the marks of the students,marks.txt, - -.. R24 - -we wish to view the contents, side by side. The ``paste`` command allows -us to do that. +And the answers, -.. L24 +1. The required result can be obtained as, :: - paste students.txt marks.txt - paste -s students.txt marks.txt - -.. R25 - -The first command gives us the output of the two files, next to each other -and the second command gives us the output one below the other. + chmod ugo+rwx wonderland.txt -Now, this problem is a bit unrealistic because, we wouldn't have the marks -of students in a file, without any information about the student to which -they belong. Let's say our marks file had the first column as the roll -number of the student, followed by the marks of the students. What would we -then do, to get the same output that we got before? -Essentially we need to use both, the ``cut`` and ``paste`` commands, but -how do we do that? That brings us to the concept of Redirection and Piping -which is covered in the next spoken tutorial. +2. For ``chown'' command, if only an owner (a username or numeric user ID) + is given, then, that user is made the owner of each given file, and the + files' group is not changed. -.. L25 -.. L26 +.. L24 -{{{ Switch to summary slide }}} +{{{ Show the SDES & FOSSEE slide }}} -.. R26 +.. R24 -This brings us to the end of this tutorial. -In this tutorial, we have learnt to, +Software Development techniques for Engineers and Scientists - SDES, is an +initiative by FOSSEE. For more information, please visit the given link. - 1. Display the contents of files using the ``cat`` command. - #. View the contents of a file one screen at a time using the - ``less`` command. - #. Display specific contents of file using the ``head`` and - ``tail`` commands. - #. Use the ``cut``, ``paste`` and ``wc`` commands. - -.. L27 +Free and Open-source Software for Science and Engineering Education - FOSSEE, is +based at IIT Bombay which is funded by MHRD as part of National Mission on +Education through ICT. -{{{ Show self assessment questions slide }}} +.. L25 -.. R27 +{{{ Show the ``About the Spoken Tutorial Project'' slide }}} -Here are some self assessment questions for you to solve +.. R25 -1. How to view lines from 1 to 15 in wonderland.txt? +Watch the video available at the following link. It summarises the Spoken +Tutorial project.If you do not have good bandwidth, you can download and +watch it. -2. In ``cut`` command, how to specify space as the delimiter? +.. L26 -.. L28 +{{{ Show the `` Spoken Tutorial Workshops'' slide }}} -{{{ Solution of self assessment questions on slide }}} +.. R26 -.. R28 +The Spoken Tutorial Project Team conducts workshops using spoken tutorials, +gives certificates to those who pass an online test. -And the answers, +For more details, contact contact@spoken-tutorial.org -1. We can use the head command as, -:: +.. L27 - head -15 wonderland.txt +{{{ Show the ``Acknowledgements'' slide }}} -2. We use the -d option with the command as, -:: +.. R27 - cut -d " " <filename> +Spoken Tutorial Project is a part of the "Talk to a Teacher" project. +It is supported by the National Mission on Education through ICT, MHRD, +Government of India. More information on this mission is available at the +given link. -.. L29 +.. L28 -{{{ Show the Thank you slide }}} +{{{ Show the Thankyou slide }}} -.. R29 +.. R28 Hope you have enjoyed this tutorial and found it useful. Thank you! diff --git a/ult/ult_3/ult3.tex b/ult/ult_3/ult3.tex index 2ece836..82fb652 100644 --- a/ult/ult_3/ult3.tex +++ b/ult/ult_3/ult3.tex @@ -1,130 +1,176 @@ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Using Linux Tools -% -% Author: FOSSEE -% Copyright (c) 2009, FOSSEE, IIT Bombay -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -\documentclass[12pt,compress]{beamer} - +\documentclass[17pt,compress]{beamer} +\usepackage{beamerthemesplit} \mode<presentation> { \usetheme{Warsaw} \useoutertheme{infolines} \setbeamercovered{transparent} + \setbeamertemplate{navigation symbols}{} } +% Taken from Fernando's slides. +\usepackage{ae,aecompl} +\usepackage[scaled=.95]{helvet} \usepackage[english]{babel} \usepackage[latin1]{inputenc} -%\usepackage{times} \usepackage[T1]{fontenc} -% Taken from Fernando's slides. -\usepackage{ae,aecompl} -\usepackage{mathpazo,courier,euler} -\usepackage[scaled=.95]{helvet} +% change the alerted colour to LimeGreen +\definecolor{LimeGreen}{RGB}{50,205,50} +\setbeamercolor{structure}{fg=LimeGreen} +\author[FOSSEE]{} +\institute[IIT Bombay]{} +\date[]{} +% \setbeamercovered{transparent} -\definecolor{darkgreen}{rgb}{0,0.5,0} +% theme split +\usepackage{verbatim} +\newenvironment{colorverbatim}[1][]% +{% +\color{blue} +\verbatim +}% +{% +\endverbatim +}% +\usepackage{mathpazo,courier,euler} \usepackage{listings} \lstset{language=sh, basicstyle=\ttfamily\bfseries, - commentstyle=\color{red}\itshape, - stringstyle=\color{darkgreen}, showstringspaces=false, - keywordstyle=\color{blue}\bfseries} + keywordstyle=\color{black}\bfseries} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% DOCUMENT STARTS -\begin{document} +% logo +\logo{\includegraphics[height=1.30 cm]{3t-logo.pdf}} +\logo{\includegraphics[height=1.30 cm]{fossee-logo.pdf} -\begin{frame} +\hspace{7.5cm} +\includegraphics[scale=0.99]{fossee-logo.pdf}\\ +\hspace{281pt} +\includegraphics[scale=0.80]{3t-logo.pdf}} -\begin{center} -\vspace{12pt} +\begin{document} -\textcolor{blue}{\huge Using Linux Tools\\Part III} -\end{center} -\vspace{18pt} -\begin{center} -\vspace{10pt} -\includegraphics[scale=0.95]{../images/fossee-logo.png}\\ -\vspace{5pt} -\scriptsize Developed by FOSSEE Team, IIT-Bombay. \\ -\scriptsize Funded by National Mission on Education through ICT\\ -\scriptsize MHRD,Govt. of India\\ -\includegraphics[scale=0.30]{../images/iitb-logo.png}\\ -\end{center} +\sffamily \bfseries +\title +[File Permissions and Ownership] +{File Permissions and Ownership} +\author +[FOSSEE] +{\small Talk to a Teacher\\{\color{blue}\url{http://spoken-tutorial.org}}\\\vspace{0.25cm}National Mission on Education + through ICT\\{\color{blue}\url{ http://sakshat.ac.in}} \\ [0.77cm] + Contributed by FOSSEE Team \\IIT Bombay \\[0.3cm] +} + +% slide 1 +\begin{frame} + \titlepage \end{frame} + \begin{frame} \frametitle{Objectives} \label{sec-2} At the end of this tutorial, you will be able to, \begin{itemize} -\item Display the contents of files. -\item Read only parts of a file. -\item Look at the statistical information of a file. +\item Change file permissions +\item Change ownership of files \end{itemize} \end{frame} \begin{frame} -\frametitle{Pre-requisite} +\frametitle{Pre-requisites} \label{sec-3} -Spoken tutorial on - +Spoken tutorial on, \begin{itemize} -\item Using Linux tools -- Part I -\item Using Linux tools -- Part II +\item Getting started with Linux +\item Basic File Handling \end{itemize} \end{frame} \begin{frame}[fragile] - \frametitle{\texttt{less}} - \begin{itemize} - \item q: Quit - \item Arrows/Page Up/Page Down/Home/End: Navigation - \item ng: Jump to line number n - \item /pattern: Search. Regular expressions can be used - \item h: Help - \end{itemize} + \frametitle{Symbolic modes} + \begin{small} + \begin{center} + \begin{tabular}{lll} + Ref. & Class & Description \\ + \hline + u & user & the owner of the file \\ + g & group & users who are members of the \\ + & & file's group \\ + o & others & users who are not the owner of the \\ + & & file or members of the group\\ + a & all & all three of the above; is the same \\ + & & as \emph{ugo} + \end{tabular} + \end{center} + \end{small} +\end{frame} + +\begin{frame}[fragile] + \frametitle{Symbolic modes...} + \begin{small} + \begin{center} + \begin{tabular}{ll} + Operator & Description \\ + \hline + + & adds the specified modes to the \\ + & specified classes \\ + - & removes the specified modes from the \\ + & specified classes \\ + = & modes specified are to be made the \\ + & exact modes for the specified classes + \end{tabular} + \end{center} + \end{small} \end{frame} \begin{frame} - \frametitle{Exercise 1} + \frametitle{Symbolic modes...} + \begin{small} + \begin{center} + \begin{tabular}{lll} + Mode & Name & Description \\ + \hline + r & read & read a file or list a directory's \\ + & & contents \\ + w & write & write to a file or directory \\\vspace{2pt} + x & execute & execute a file or recurse a \\ + & & directory tree + \end{tabular} + \end{center} + \end{small} +\end{frame} + + +\begin{frame} + \frametitle{Exercise} + \begin{itemize} + \item Change the permissions of a directory including, \begin{itemize} - \item Print only the first, fifth and the seventh fields of the file ``/etc/passwd''. + \item All it's sub-directories + \item All files within the directory + \end{itemize} \end{itemize} \end{frame} -\begin{frame}[fragile] - \frametitle{\texttt{paste}} - \begin{center} - \begin{tabular}{l|l} - \verb~students.txt~ & \verb~marks.txt~ \\ - Hussain & 89 92 85 \\ - Dilbert & 98 47 67 \\ - Anne & 67 82 76 \\ - Raul & 78 97 60 \\ - Sven & 67 68 69 \\ - \end{tabular} - \end{center} +\begin{frame} + \frametitle{Solution} + \begin{itemize} + \item \$ chmod go-r -R <directory name>/ + \end{itemize} \end{frame} \begin{frame} \frametitle{Summary} -\label{sec-8} In this tutorial, we have learnt to, - \begin{itemize} -\item Display the contents of files using the ``cat'' command. -\item View the contents of a file one screen at a time using the - ``less'' command. -\item Display specific contents of file using the ``head'' and - ``tail'' commands. -\item Use the ``cut'', ``paste'' and ``wc'' commands. +\item Chane the permissions of files using the ``chmod'' command +\item Use the ``chown'' command to change the ownership of files \end{itemize} \end{frame} @@ -134,9 +180,14 @@ Spoken tutorial on - \begin{enumerate} -\item How to view lines from 1 to 15 in wonderland.txt ? -\vspace{15pt} -\item In ``cut'' command, how to specify space as the delimiter ? +\item For a given file, change mode to r, w, x for all (user, group, others) +\vspace{10pt} +\item What changes, on specifying only an owner in the "chown" command? +\begin{itemize} +\item Only the owner of the file +\item The group ownership of the file +\item Neither the owner nor the group +\end{itemize} \end{enumerate} \end{frame} \begin{frame} @@ -145,26 +196,71 @@ Spoken tutorial on - \begin{enumerate} -\item \$ head -15 wonderland.txt +\item \$ chmod ugo+rwx <filename> \vspace{15pt} -\item \$ cut -d " " <filename> +\item Only the owner of the file \end{enumerate} \end{frame} + +\begin{frame} +\frametitle{SDES \& FOSSEE} +\begin{center} +\begin{itemize} +\item \small{SDES}\\ +\small{\color{LimeGreen}Software Development techniques for Engineers and Scientists} \\ +\scriptsize An initiative by FOSSEE. \\ +\vspace{3pt} +\scriptsize For more information on SDES, please visit {\color{blue}\url{http://fossee.in/sdes}}\\ +\vspace{10pt} +\item \small{FOSSEE}\\ +\small {\color{LimeGreen}Free and Open-source Software for \\Science and Engineering Education} \\ +\scriptsize Based at IIT Bombay, Funded by MHRD.\\ +\vspace{3pt} +\scriptsize Part of National Mission on Education through ICT \\(NME-ICT) \\ +\end{itemize} +\end{center} +\end{frame} + +\begin{frame} +\frametitle{About the Spoken Tutorial Project} +\begin{itemize} +\item Watch the video available at {\color{blue}\url{http://spoken-tutorial.org /What\_is\_a\_Spoken\_Tutorial}} +\item It summarises the Spoken Tutorial project +\item If you do not have good bandwidth, you can download and watch it +\end{itemize} +\end{frame} + +\begin{frame} +\frametitle{Spoken Tutorial Workshops}The Spoken Tutorial Project Team +\begin{itemize} +\item Conducts workshops using spoken tutorials +\item Gives certificates to those who pass an online test +\item For more details, please write to \\ \hspace {0.5cm}{\color{blue}contact@spoken-tutorial.org} +\end{itemize} +\end{frame} + +\begin{frame} +\frametitle{Acknowledgements} +\begin{itemize} +\item Spoken Tutorial Project is a part of the Talk to a Teacher project +\item It is supported by the National Mission on Education through ICT, MHRD, Government of India +\item More information on this Mission is available at: \\{\color{blue}\url{http://spoken-tutorial.org/NMEICT-Intro}} +\end{itemize} +\end{frame} + \begin{frame} \begin{block}{} \begin{center} - \textcolor{blue}{\Large THANK YOU!} + {\Large THANK YOU!} \end{center} \end{block} \begin{block}{} \begin{center} For more Information, visit our website\\ - \url{http://fossee.in/} + {\color{blue}\url{http://fossee.in/}} \end{center} \end{block} \end{frame} \end{document} - - diff --git a/ult/ult_4/script.rst b/ult/ult_4/script.rst index 09de00e..4b1bef0 100644 --- a/ult/ult_4/script.rst +++ b/ult/ult_4/script.rst @@ -3,15 +3,17 @@ .. At the end of this tutorial, you will be able to: - .. 1. Understand what is Redirection and Piping. - .. 2. Learn various features of shell. + .. 1. Display the contents of files. + .. 2. Read only parts of a file. + .. 3. Look at the statistical information of a file. .. Prerequisites .. ------------- -.. 1. Using Linux tools - Part 1 -.. 2. Using Linux tools - Part 2 -.. 3. Using Linux tools - Part 3 +.. 1. Getting started with Linux +.. 2. Basic File Handling +.. 3. File permissions and ownership + Script ------ @@ -24,7 +26,7 @@ team along with the logo of MHRD }}} .. R1 Hello friends and Welcome to the tutorial on -'Using linux tools - Part 4'. +'Advanced File Handling'. .. L2 @@ -34,8 +36,9 @@ Hello friends and Welcome to the tutorial on At the end of this tutorial, you will be able to, - 1. Understand what is Redirection and Piping. - #. Learn various features of the shell. + 1. Display the contents of files. + #. Read only parts of a file. + #. Look at the statistical information of a file. .. L3 @@ -43,367 +46,389 @@ At the end of this tutorial, you will be able to, .. R3 -Before beginning this tutorial, we would suggest you to complete the -tutorial on "Using Linux tools from Part 1 to Part 3". +Before beginning this tutorial,we would suggest you to complete the +former tutorials as being displayed currently. .. R4 -Let us begin with the concept of 'Redirection and Piping' which -performs the same operations as the ``cut`` and ``paste`` commands. - -Consider the files ``marks.txt`` and ``students.txt``.The contents of -the files are as following: +Let us begin with how to read a file as a whole. +The ``cat`` command is the most commonly used command for this purpose. +To view the contents of a file, say, ``foo.txt``, we +simply say, .. L4 -{{{ Open the terminal }}} +{{{ Switch to terminal }}} :: - cat marks1.txt - cat students.txt + cat foo.txt .. R5 -Now, let us view the contents of both these files side-by-side. +You can see the contents of the file on the terminal. + +The cat command could also be used to concatenate the text of multiple +files. Say, we have two files,``foo.txt`` and ``bar.txt``, .. L5 :: - cut -d " " -f 2- marks1.txt | paste -d " " students.txt - + cat foo.txt bar.txt .. R6 -Now, in order to view the same output in a new file at an other -location, we say, +It shows the output of both the files concatenated on the standard output. +But if we had a long file,the output of ``cat`` command is not convenient +to read. +Let's look at the ``less`` command which turns out to be more useful in +such a case. + +``less `` allows you to view the contents of a text file one screen at a +time. .. L6 :: - cut -d " " -f 2- marks1.txt > /tmp/m_tmp.txt - paste -d " " students.txt m_tmp.txt + less wonderland.txt + +<Press enter few times and show the contents of the file, then press Ctrl-z> .. R7 -First, let us try to understand the second solution,which is a two -step approach. -Later, we shall look at the first solution. +This shows us the file, one screen at a time. .. L7 .. L8 -{{{ Show slide, with Redirection }}} +{{{ Show slide with, less }}} .. R8 -The standard output, in general, goes to the display. -Hence, the output of the commands that we type, come out to the display. -This may not be what we always require. +``less`` has a list of commands that it allows you to use, once you have +started viewing a file. A few of the common ones have been listed below. -For instance, in the solution above, we use the cut command and get only -the required columns of the file and write the output to a new temporary -file. The ``>`` character is used to state that we wish to redirect the -output, and it is followed by the location to which we wish to redirect. -For example, + * q: to Quit. - command > file1 + * [Arrows]/[Page Up]/[Page Down]/[Home]/[End]:to Navigate through + the content. -.. L9 + * ng: to jump to a given line number (n).Default, is the first line of + a file. -{{{ Show slide, with Redirection... }}} + * /pattern: Search for pattern. Regular expressions can be used. -.. R9 - -Similarly, the standard input (stdin) can be redirected as, - - command < file1 + * h: for Help. -The input and the output redirection could be combined in a single command, -as, - - command < infile > outfile +.. R9 -There is actually a third kind of standard stream, called the Standard -error (stderr). Any error messages that you get, are coming through this -stream. Like ``stdout``, ``stderr`` also streams to the display by default, -but it could be redirected to a file, as well. +Let us move ahead with the topic. Often, we would like to get only some +statistical information about a file, rather than it's full contents. +The ``wc`` command prints these details for a file. -.. R10 +.. L9 +:: -For instance, let's reproduce an error using the ``cut`` command used -before. We shall change the ``-f`` option to ``-c`` + wc wonderland.txt .. L10 -{{{ Switch to terminal }}} -:: +{{{ Highlight the required portions accordingly while narrating }}} - cut -d " " -c 2- marks1.txt > /tmp/m_tmp.txt +.. R10 + +As you can see, we get some information about the file. +The first number is the number of lines, the second is the number of words +and the third is the number of characters in the file. .. R11 -This displays an error saying that the delimiter option should be used -with the fields option only. You may verify this by looking at the -``m_tmp.txt`` file, which is now empty.We can now, redirect the -``stderr`` also to a file, instead of showing it on the display. +Let us now look at a couple of commands that let's you see parts of files, +instead of the whole file. The ``head`` and ``tail`` commands allow you to see +parts of files. As their names suggest, they display the start and end of a +file, respectively. .. L11 :: - cut -d " " -f 2- marks1.txt 1> /tmp/m_tmp.txt 2> /tmp/m_err.txt + head wonderland.txt .. R12 -The above command redirects all the errors to the ``m_err.txt`` file -and the output to the ``m_tmp.txt`` file. When redirecting, 1 stands -for ``stdout`` and 2 stands for ``stderr``. - -Let us complete the solution by using the ``paste`` command. +It prints only the first 10 lines of the file. Similarly tail will print the +last 10 lines of the file. If we wish to change the number of lines that we +wish to view, we use the option ``-n``. .. L12 :: - paste -d " " students.txt m_tmp.txt + head -n 1 wonderland.txt .. R13 -So, in two steps we solved the problem of getting rid of the roll numbers -from the marks file and displaying the marks along with the names of the -students. Now, that we know how to redirect output, we could choose to -write the output to a file, instead of showing on the display. +It prints only the first line of the file. Similarly, we could print only +the last line of the file. -Let us now look at the first solution. +The most common use of the tail command is to monitor a continuously +changing file, for instance, a log file. Say, you have a process running, +which is continuously logging it's information to a file, for instance, the +logs of the system messages. .. L13 :: - cut -d " " -f 2- marks1.txt | paste -d " " students.txt - - -.. L14 - -{{{ Show slide, with Piping }}} + tail -f /var/log/dmesg .. R14 -First of all, the hyphen at the end is to ask the paste command to -read the standard input, instead of looking for a FILE. The ``man`` -page of ``paste`` command gives us this information. - -The character ``|`` is called a pipe. -Now, let us observe the ``cut`` command. If we look at the command only -upto the ``|`` character, it appears as a normal ``cut`` command . -So, the ``|`` character here, seems -to be joining the two commands in some way. -Essentially, what we are doing is, to redirect the output of the first -command to ``stdin`` and the second command takes the input from the ``stdin``. - -More generally, - - command1 | command2 +This will show the last 10 lines of the file as expected, but along with +that, it starts monitoring the file. Any new lines added at the end of the +file, will be shown. To interrupt tail, while it is monitoring, hit +``Ctrl-C``. -executes ``command1`` and sends it's output to the ``stdin``, which is then -used as the input for ``command2``. This activity is commonly called piping. +We looked at a couple of functions that allowed us to view a part of a file, +line-wise. We shall now look at a couple of commands that will allow us to look +at, only certain sections of each line of a file and merge those parts. +Let's take the ``/etc/passwd`` file as our example file. It contains +information about each user of the system. -.. L15 +.. L14 +:: -{{{ Show slide, with Piping... }}} + cat /etc/passwd .. R15 -This is roughly equivalent to using two redirects and a temporary file. - - command1 > tempfile - command2 < tempfile - rm tempfile +In the output, let us look at only the first, fifth, sixth and the last +columns.The first column is the ``user name``, the fifth column is the +``user info``, the sixth column is the ``home folder`` and the last column +is the ``path of the shell program`` that the user uses. +Let's say, we wish to look at only the user names in the file, how do we do it? -Also, given that a pipe is just a way to send the output of a command to -the ``stdin``, it should be obvious to you that we can use a chain of -pipes. Any number of commands can be piped together and therefore it should - be noted that it is not restricted to only two commands. +.. L15 +:: + + cut -d : -f 1 /etc/passwd -The Bash shell has some nice features, that make our job of using the shell -easier and much more pleasant. Let us have a look at few of them here. +.. R16 -Bash provides the feature of 'tab completion'. What does tab completion mean? -When you are typing a word, bash helps you to complete the word. -This can be done by entering some portion of the word and thereafter, -pressing the tab key. +It gives us the required output. Let us understand this operation in detail. +The first option ``-d`` specifies the delimiter between the various fields in +the file, in this case it is the ``semicolon``. If no delimiter is specified, +the TAB character is assumed to be the delimiter. The ``-f`` option specifies, +the field number that we wish to choose. +You can print multiple fields, by separating the field numbers with a +comma. -If you do not get the desired word on pressing the tab key, it implies that -either the word doesn't exist or the word cannot be decided unambiguously. -In the latter case, pressing the tab key for a second time,will list out -all the possibilities. +Pause the video here, try out the following exercise and resume the video. .. L16 -{{{ Show slide, with Tab-completion }}} - -.. R16 - -Bash provides tab completion for the following. +.. L17 - 1. File Names - 2. Directory Names - 3. Executable Names - 4. User Names (when they are prefixed with a ~) - 5. Host Names (when they are prefixed with a @) - 6. Variable Names (when they are prefixed with a $) +{{{ Show slide with exercise }}} .. R17 -For example, - -.. L17 - -{{{ Switch to terminal }}} -:: - - pas<TAB><TAB> - ~/<TAB><TAB> +Print only the first, fifth and the seventh fields of the file ``/etc/passwd``. .. R18 -Bash also saves the history of the commands you have typed earlier. -This feature enables you to goto the previously typed commands and -use them as and when necessary. The up and down arrow keys will help -you to navigate -through these commands in the bash history. +Switch to the terminal for solution .. L18 -:: - <UP-ARROW> +{{{ continue from paused state }}} +{{{ Switch to the terminal }}} + +:: + + cut -d : -f 1,5,7 /etc/passwd .. R19 -You may also search incrementally, for commands in your bash history. -``Ctrl-r`` searches for the commands that you have typed earlier. However, -it should be noted that the number of commands saved in the history is -limited, generally upto a 1000 commands. +We get the correct output. +Instead of choosing by fields, ``cut`` also allows us to choose on the +basis of characters or bytes. For instance, we could get the first 4 +characters of all the entries of the file, ``/etc/passwd`` by saying, .. L19 :: - <Ctrl-r> pas + cut -c 1-4 /etc/passwd .. R20 -Unix recognizes certain special characters, called "meta characters", as -command directives. The shell meta characters are recognized anywhere they -appear in the command line, even if they are not surrounded by a blank space. -For this reason, it is always recommended to use only the characters A-Z, -a-z, 0-9, period, dash and underscore, when naming files and -directories on Unix. If your file or directory has a shell meta character -in the name, you may find it difficult to use this name in a shell command. +The end limits of the ranges can take sensible default values, if they are +left out. For example, .. L20 +:: -.. L21 - -{{{ Show slide, with Shell Meta Characters }}} + cut -c -4 /etc/passwd .. R21 -The characters that you see on the slide are the shell meta characters +It gives the same output as before. If the start position has not been +specified, it is assumed to be the start of the line. Similarly if the end +position is not specified, it is assumed to be the end of the line. + +.. L21 +:: + + cut -c 10- /etc/passwd .. R22 -Lets take an example, +It prints all the characters from the 10th character up to the end of the +line. +Let us now solve an inverse problem. Let's say we have two columns of data +in two different files, and we wish to view them side by side. .. L22 -{{{ Switch to terminal }}} -:: +.. L23 - ls file.? +{{{ Show slide with, paste }}} .. R23 -It means, run on a directory containing the files file, file.c, file.lst, -and myfile would list the files file.c and file.lst. However, - -.. L23 -:: - - ls file.? +For instance, consider a file 'students.txt' containing the names of students +and another file 'marks.txt' containing their respective marks. .. R24 -Run on the same directory would only list file.c because the ? only matches -one character, no more, no less. This helps you save time, while typing. - -For example, if there is a file called -california_cornish_hens_with_wild_rice and no other files whose names begin -with 'c', you could view the file without typing the whole name by typing -this +we wish to view the contents, side by side. The ``paste`` command allows +us to do that. .. L24 :: - more c* + paste students.txt marks.txt + paste -s students.txt marks.txt .. R25 -Here, the c* matches that long file name. -File-names containing meta characters can pose many problems and should -never be intentionally created. +The first command gives us the output of the two files, next to each other +and the second command gives us the output one below the other. + +Now, this problem is a bit unrealistic because, we wouldn't have the marks +of students in a file, without any information about the student to which +they belong. Let's say our marks file had the first column as the roll +number of the student, followed by the marks of the students. What would we +do then, to get the same output that we got before? + +Essentially we need to use both the ``cut`` and ``paste`` commands, but +how do we do that? That brings us to the concept of Redirection and Piping +which is covered in the next spoken tutorial. .. L25 .. L26 -{{{ Switch to Summary slide }}} +{{{ Switch to summary slide }}} .. R26 -This brings us to the end of the end of this tutorial. -In this tutorial, we have learnt to, +This brings us to the end of this tutorial. +In this tutorial, we have learnt to, - 1. Use the ``cut`` and ``paste`` commands in redirection. - 2. Use the pipe ( | ) character. - 3. Implement features of shell, like tab-completion and history. + 1. Display the contents of files using the ``cat`` command. + #. View the contents of a file one screen at a time using the + ``less`` command. .. L27 - -{{{ Show self assessment questions slide }}} - -.. R27 -Here are some self assessment questions for you to solve: +{{{ Switch to slide Summary... }}} - 1. Bash does not provide tab completion for Host Names. - True of False? +.. R27 - 2. In a file /home/test.txt ,first line is "data:myscripts:20:30". How do we - view only the minutes (last field, 30). - - - cut -d : -f 4 /home/test.txt - - cut -f 3 /home/test.txt - - cut -d : -f 3 /home/test.txt - - None of these + 1. Display only specific contents of file using the ``head`` and + ``tail`` commands. + #. Use the ``cut``, ``paste`` and ``wc`` commands. + .. L28 -{{{ Solutions for the self assessment questions on slide }}} +{{{ Show self assessment questions slide }}} .. R28 -And the answers: +Here are some self assessment questions for you to solve - 1. False. Bash provides tab completion for Host Names when they are prefixed - with a @ sign. +1. How to view lines from 1 to 15 in ``wonderland.txt``? - 2. The correct option would be -:: - - cut -d : -f 4 /home/test.txt +2. In ``cut`` command, how to specify space as the delimiter? .. L29 -{{{ Show the Thank you slide }}} +{{{ Solution of self assessment questions on slide }}} .. R29 +And the answers, + +1. We can use the head command as, +:: + + head -15 wonderland.txt + +2. We use the -d option with the command as, +:: + + cut -d " " <filename> + +.. L30 + +{{{ Show the SDES & FOSSEE slide }}} + +.. R30 + +Software Development techniques for Engineers and Scientists - SDES, is an +initiative by FOSSEE. For more information, please visit the given link. + +Free and Open-source Software for Science and Engineering Education - FOSSEE, is +based at IIT Bombay which is funded by MHRD as part of National Mission on +Education through ICT. + +.. L31 + +{{{ Show the ``About the Spoken Tutorial Project'' slide }}} + +.. R31 + +Watch the video available at the following link. It summarises the Spoken +Tutorial project.If you do not have good bandwidth, you can download and +watch it. + +.. L32 + +{{{ Show the `` Spoken Tutorial Workshops'' slide }}} + +.. R32 + +The Spoken Tutorial Project Team conducts workshops using spoken tutorials, +gives certificates to those who pass an online test. + +For more details, contact contact@spoken-tutorial.org + +.. L33 + +{{{ Show the ``Acknowledgements'' slide }}} + +.. R33 + +Spoken Tutorial Project is a part of the "Talk to a Teacher" project. +It is supported by the National Mission on Education through ICT, MHRD, +Government of India. More information on this mission is available at the +given link. + +.. L34 + +{{{ Show the Thank you slide }}} + +.. R34 + Hope you have enjoyed this tutorial and found it useful. Thank you! diff --git a/ult/ult_4/ult4.tex b/ult/ult_4/ult4.tex index 7181db5..396dceb 100644 --- a/ult/ult_4/ult4.tex +++ b/ult/ult_4/ult4.tex @@ -5,178 +5,132 @@ % Copyright (c) 2009, FOSSEE, IIT Bombay %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\documentclass[12pt,compress]{beamer} +\documentclass[17pt,compress]{beamer} +\usepackage{beamerthemesplit} \mode<presentation> { \usetheme{Warsaw} \useoutertheme{infolines} \setbeamercovered{transparent} + \setbeamertemplate{navigation symbols}{} } +% Taken from Fernando's slides. +\usepackage{ae,aecompl} +\usepackage[scaled=.95]{helvet} \usepackage[english]{babel} \usepackage[latin1]{inputenc} -%\usepackage{times} \usepackage[T1]{fontenc} -% Taken from Fernando's slides. -\usepackage{ae,aecompl} -\usepackage{mathpazo,courier,euler} -\usepackage[scaled=.95]{helvet} - -\definecolor{darkgreen}{rgb}{0,0.5,0} +% change the alerted colour to LimeGreen +\definecolor{LimeGreen}{RGB}{50,205,50} +\setbeamercolor{structure}{fg=LimeGreen} +\author[FOSSEE]{} +\institute[IIT Bombay]{} +\date[]{} +% \setbeamercovered{transparent} + +% theme split +\usepackage{verbatim} +\newenvironment{colorverbatim}[1][]% +{% +\color{blue} +\verbatim +}% +{% +\endverbatim +}% +\usepackage{mathpazo,courier,euler} \usepackage{listings} \lstset{language=sh, basicstyle=\ttfamily\bfseries, - commentstyle=\color{red}\itshape, - stringstyle=\color{darkgreen}, showstringspaces=false, - keywordstyle=\color{blue}\bfseries} + keywordstyle=\color{black}\bfseries} + +% logo +\logo{\includegraphics[height=1.30 cm]{3t-logo.pdf}} +\logo{\includegraphics[height=1.30 cm]{fossee-logo.pdf} + +\hspace{7.5cm} +\includegraphics[scale=0.99]{fossee-logo.pdf}\\ +\hspace{281pt} +\includegraphics[scale=0.80]{3t-logo.pdf}} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % DOCUMENT STARTS \begin{document} -\begin{frame} +\sffamily \bfseries +\title +[Advanced File Handling] +{Advanced File Handling} +\author +[FOSSEE] +{\small Talk to a Teacher\\{\color{blue}\url{http://spoken-tutorial.org}}\\\vspace{0.25cm}National Mission on Education + through ICT\\{\color{blue}\url{ http://sakshat.ac.in}} \\ [1.65cm] + Contributed by FOSSEE Team \\IIT Bombay \\[0.3cm] +} -\begin{center} -\vspace{12pt} -\textcolor{blue}{\huge Using Linux Tools\\Part IV} -\end{center} -\vspace{18pt} -\begin{center} -\vspace{10pt} -\includegraphics[scale=0.95]{../images/fossee-logo.png}\\ -\vspace{5pt} -\scriptsize Developed by FOSSEE Team, IIT-Bombay. \\ -\scriptsize Funded by National Mission on Education through ICT\\ -\scriptsize MHRD,Govt. of India\\ -\includegraphics[scale=0.30]{../images/iitb-logo.png}\\ -\end{center} +% slide 1 +\begin{frame} + \titlepage \end{frame} + \begin{frame} \frametitle{Objectives} \label{sec-2} At the end of this tutorial, you will be able to, \begin{itemize} -\item Understand what is Redirection and Piping. -\item Learn various features of the shell. +\item Display the contents of files +\item Read only parts of a file +\item Look at the statistical information of a file \end{itemize} \end{frame} \begin{frame} -\frametitle{Pre-requisite} +\frametitle{Pre-requisites} \label{sec-3} -Spoken tutorial on - +Spoken tutorial on, \begin{itemize} -\item Using Linux tools -- Part I -\item Using Linux tools -- Part II -\item Using Linux tools -- Part III +\item Getting started with Linux +\item Basic File Handling \end{itemize} \end{frame} \begin{frame}[fragile] - \frametitle{Redirection} - - \begin{itemize} - \item The standard output (stdout) stream goes to the display - \item Not always, what we need - \item First solution, redirects output to a file - \item \texttt{>} states that output is redirected; It is - followed by location to redirect - \end{itemize} - \begin{lstlisting} - $ command > file1 - \end{lstlisting} % $ - \begin{itemize} - \item \texttt{>} creates a new file at specified location - \item \texttt{>>} appends to a file at specified location - \end{itemize} -\end{frame} - -\begin{frame}[fragile] - \frametitle{Redirection \ldots} - \begin{itemize} - \item Similarly, the standard input (stdin) can be redirected - \end{itemize} - \begin{lstlisting} - $ command < file1 - \end{lstlisting} % $ - \begin{itemize} - \item input and the output redirection could be combined - \end{itemize} - \begin{lstlisting} - $ command < infile > outfile - \end{lstlisting} % $ - \begin{itemize} - \item Standard error (stderr) is the third standard stream - \item All error messages come through this stream - \item \texttt{stderr} can also be redirected - \end{itemize} -\end{frame} - -\begin{frame}[fragile] - \frametitle{Piping} - \begin{lstlisting} - $ cut -d " " -f 2- marks1.txt \ - | paste -d " " students.txt - - \end{lstlisting} % $ - \begin{itemize} - \item \texttt{-} instead of FILE asks \texttt{paste} to read from - \texttt{stdin} - \item \texttt{cut} command is a normal command - \item the \texttt{|} seems to be joining the two commands - \item Redirects output of first command to \texttt{stdin}, which - becomes input to the second command - \item This is called piping; \texttt{|} is called a pipe - \end{itemize} -\end{frame} - -\begin{frame}[fragile] - \frametitle{Piping \ldots} - \begin{itemize} - \item Roughly same as -- 2 redirects and a temporary file - \end{itemize} - \begin{lstlisting} - $ command1 > tempfile - $ command2 < tempfile - $ rm tempfile - \end{lstlisting} % $ - \begin{itemize} - \item Any number of commands can be piped together + \frametitle{\texttt{less}} + \begin{itemize} + \item q: Quit + \item Arrows/Page Up/Page Down/Home/End: Navigation + \item ng: Jump to line number n + \item /pattern: Search. Regular expressions can be used + \item h: Help \end{itemize} \end{frame} -\subsection{Features of the Shell} - -\begin{frame}[fragile] - \frametitle{Tab-completion} +\begin{frame} + \frametitle{Exercise 1} \begin{itemize} - \item Bash provides tab completion for the following. - \begin{enumerate} - \item File Names - \item Directory Names - \item Executable Names - \item User Names (when they are prefixed with a \~{}) - \item Host Names (when they are prefixed with a @) - \item Variable Names (when they are prefixed with a \$) - \end{enumerate} + \item Print only the first, fifth and the seventh fields of the file \verb~/etc/passwd~ \end{itemize} \end{frame} \begin{frame}[fragile] - \frametitle{Shell Meta Characters} - \begin{itemize} - \item ``meta characters'' are special command directives - \item File-names shouldn't have meta-characters - \item The following are the shell meta characters -- - \begin{itemize} - \item \verb+/<>!$%^&*|{}[]"'`~;+ - \end{itemize} - \end{itemize} + \frametitle{\texttt{paste}} + \begin{center} + \begin{tabular}{l|l} + \verb~students.txt~ & \verb~marks.txt~ \\ + Hussain & 89 92 85 \\ + Dilbert & 98 47 67 \\ + Anne & 67 82 76 \\ + Raul & 78 97 60 \\ + Sven & 67 68 69 \\ + \end{tabular} + \end{center} \end{frame} \begin{frame} @@ -185,31 +139,31 @@ Spoken tutorial on - In this tutorial, we have learnt to, +\begin{itemize} +\item Display the contents of files using the ``cat'' command. +\item View the contents of a file one screen at a time using the + ``less'' command. +\end{itemize} +\end{frame} +\begin{frame} +\frametitle{Summary...} \begin{itemize} -\item Use the ``cut'' and ``paste'' commands in redirection. -\item Use the pipe ( | ) character. -\item Implement features of shell like tab-completion and history. +\item Display specific contents of file using the ``head'' and + ``tail'' commands. +\item Use the ``cut'', ``paste'' and ``wc'' commands. \end{itemize} \end{frame} + \begin{frame}[fragile] \frametitle{Evaluation} \label{sec-9} \begin{enumerate} -\item Bash does not provide tab completion for Host Names. \\ - True or False? -\vspace{12pt} -\item In a file /home/test.txt ,first line is "data:myscripts:20:30".How to - view only minutes(last field, 30). -\vspace{5pt} -\begin{itemize} -\item cut -d : -f 4 /home/test.txt -\item cut -f 3 /home/test.txt -\item cut -d : -f 3 /home/test.txt -\item None of these -\end{itemize} +\item How to view lines from 1 to 15 in \verb~wonderland.txt~ ? +\vspace{15pt} +\item In ``cut'' command, how to specify space as the delimiter ? \end{enumerate} \end{frame} \begin{frame} @@ -218,22 +172,69 @@ Spoken tutorial on - \begin{enumerate} -\item False +\item \$ head -15 \verb~wonderland.txt~ \vspace{15pt} -\item cut -d : -f 4 /home/test.txt +\item \$ cut -d " " <filename> \end{enumerate} \end{frame} + +\begin{frame} +\frametitle{SDES \& FOSSEE} +\begin{center} +\begin{itemize} +\item \small{SDES}\\ +\small{\color{LimeGreen}Software Development techniques for Engineers and Scientists} \\ +\scriptsize An initiative by FOSSEE. \\ +\vspace{3pt} +\scriptsize For more information on SDES, please visit {\color{blue}\url{http://fossee.in/sdes}}\\ +\vspace{10pt} +\item \small{FOSSEE}\\ +\small {\color{LimeGreen}Free and Open-source Software for \\Science and Engineering Education} \\ +\scriptsize Based at IIT Bombay, Funded by MHRD.\\ +\vspace{3pt} +\scriptsize Part of National Mission on Education through ICT \\(NME-ICT) \\ +\end{itemize} +\end{center} +\end{frame} + +\begin{frame} +\frametitle{About the Spoken Tutorial Project} +\begin{itemize} +\item Watch the video available at {\color{blue}\url{http://spoken-tutorial.org /What\_is\_a\_Spoken\_Tutorial}} +\item It summarises the Spoken Tutorial project +\item If you do not have good bandwidth, you can download and watch it +\end{itemize} +\end{frame} + +\begin{frame} +\frametitle{Spoken Tutorial Workshops}The Spoken Tutorial Project Team +\begin{itemize} +\item Conducts workshops using spoken tutorials +\item Gives certificates to those who pass an online test +\item For more details, please write to \\ \hspace {0.5cm}{\color{blue}contact@spoken-tutorial.org} +\end{itemize} +\end{frame} + +\begin{frame} +\frametitle{Acknowledgements} +\begin{itemize} +\item Spoken Tutorial Project is a part of the Talk to a Teacher project +\item It is supported by the National Mission on Education through ICT, MHRD, Government of India +\item More information on this Mission is available at: \\{\color{blue}\url{http://spoken-tutorial.org/NMEICT-Intro}} +\end{itemize} +\end{frame} + \begin{frame} \begin{block}{} \begin{center} - \textcolor{blue}{\Large THANK YOU!} + {\Large THANK YOU!} \end{center} \end{block} \begin{block}{} \begin{center} For more Information, visit our website\\ - \url{http://fossee.in/} + {\color{blue}\url{http://fossee.in/}} \end{center} \end{block} \end{frame} diff --git a/ult/ult_5/script.rst b/ult/ult_5/script.rst index e112ff7..2937397 100644 --- a/ult/ult_5/script.rst +++ b/ult/ult_5/script.rst @@ -3,17 +3,15 @@ .. At the end of this tutorial, you will be able to: - .. 1. - .. 2. + .. 1. Understand what is Redirection and Piping. + .. 2. Learn various features of shell. .. Prerequisites .. ------------- -.. 1. Using Linux tools - Part 1 -.. 2. Using Linux tools - Part 2 -.. 3. Using Linux tools - Part 3 -.. 4. Using Linux tools - Part 4 - +.. 1. Getting started with Linux +.. 2. Basic File Handling +.. 4. Advanced file handling Script ------ @@ -26,7 +24,7 @@ team along with the logo of MHRD }}} .. R1 Hello friends and Welcome to the tutorial on -'Using linux tools - Part 5'. +'Redirection and Piping'. .. L2 @@ -36,11 +34,8 @@ Hello friends and Welcome to the tutorial on At the end of this tutorial, you will be able to, - 1. Sort lines of text files - #. Print lines matching a pattern - #. Translate or delete characters - #. Omit repeated lines. - + 1. Understand what is Redirection. + #. Learn the concept of Piping. .. L3 @@ -49,14 +44,15 @@ At the end of this tutorial, you will be able to, .. R3 Before beginning this tutorial,we would suggest you to complete the -tutorial on "Using Linux tools from Part 1 to Part 4". +former tutorials as being displayed currently. .. R4 -In this tutorial, we shall learn about text processing. -TO begin with, consider data kept in two files, namely marks1.txt and -students.txt -Let us see what data they contain. Open a terminal and type, +Let us begin with the concept of 'Redirection and Piping' which +performs the same operations as the ``cut`` and ``paste`` commands. + +Consider the files ``marks.txt`` and ``students.txt``.The contents of +the files are as following: .. L4 @@ -68,274 +64,267 @@ Let us see what data they contain. Open a terminal and type, .. R5 -Let's say we wish to sort the output in the alphabetical order -of the names of the files. We can use the ``sort`` command for this -purpose. - -We just pipe the previous output to the ``sort`` command as, +Now, let us view the contents of both these files side-by-side. .. L5 :: - cut -d " " -f 2- marks1.txt | paste -d " " students.txt -| sort + cut -d " " -f 2- marks1.txt | paste -d " " students.txt - .. R6 -Let's say we wish to sort the names, based on the marks in the first -subject i.e. the first column after the name. ``sort`` command also allows us to -specify the delimiter between the fields and sort the data on a particular -field. ``-t`` option is used to specify the delimiter and ``-k`` option -is used to specify the field. +Now, in order to view the same output in a new file at an other +location, we say, .. L6 :: - cut -d " " -f 2- marks1.txt | paste -d " " students.txt -| sort -t " " -k 2 + cut -d " " -f 2- marks1.txt > /tmp/m_tmp.txt + paste -d " " students.txt m_tmp.txt -.. L7 +.. R7 -{{{ Show slide with, Sort... }}} +First, let us try to understand the second solution,which is a two +step approach. +Later, we shall look at the first solution. -.. R7 +.. L7 + +.. L8 -This command give us a sorted output as required. But, what if we would -like the output to appear in the reverse order. ``-r`` option allows the output -to be sorted in the reverse order and the ``-n`` option is used to choose -a numerical sorting. +{{{ Show slide, with Redirection }}} .. R8 -Let us do it on the terminal and see for ourselves, +The standard output, in general, goes to the display. +But, this may not be what we always require. -.. L8 +For instance, in the solution above, we use the cut command and get only +the required columns of the file and write the output to a new temporary +file. The ``>`` character is used to state that we wish to redirect the +output, and it is followed by the location to which we wish to redirect. +For example, -{{{ Switch to the terminal }}} -:: + command > file1 - cut -d " " -f 2- marks1.txt | paste -d " " students.txt -| - sort -t " " -k 2 -rn +.. L9 + +{{{ Show slide, with Redirection.. }}} .. R9 -Suppose, While you are compiling the student marklist, Anne walks up to you and -wants to know her marks. You, being a kind person that you are, oblige. -But you do not wish to her to see the marks that others have scored. What -do you do? Here, the ``grep`` command comes to your rescue. +Similarly, the standard input (stdin) can be redirected as, + + command < file1 -``grep`` is a command line text search utility. You can use it to search -for Anne and show her, what she scored. ``grep`` allows us to search for a -search string in files. But we could, like any other command, pipe the -output of other commands to it. So, we shall use the previous combination -of cut and paste that we had, to get the marks of students along with their -names and search for Anne in that. +The input and the output redirection could be combined in a single command, +as, -.. L9 -:: + command < infile > outfile - cut -d " " -f 2- marks1.txt | paste -d " " students.txt - | grep Anne +.. L10 -.. R10 +{{{ Show slide, with stderr }}} -This will give us only the line containing the word Anne as the output. -The grep command is by default case-sensitive. So, we wouldn't have got -the result if we had searched for anne, with a small a, instead of -Anne, with a capital a. But, what if we didn't know, whether the name was -capitalized or not? ``grep`` allows you to do case-insensitive searches -by using the ``-i`` option. -.. L10 -:: +.. R10 - cut -d " " -f 2- marks1.txt | paste -d " " students.txt - | grep -i Anne +There is actually a third kind of standard stream, called the Standard +error (stderr). Any error messages that you get, are coming through this +stream. Like ``stdout``, ``stderr`` also streams to the display by default, +but it could be redirected to a file, as well. .. R11 -Now, in another scenario, if we wished to print all the lines, which do -not contain the word Anne, we could use the ``-v`` option. +For instance, let's reproduce an error using the ``cut`` command used +before. We shall change the ``-f`` option to ``-c`` .. L11 + +{{{ Switch to terminal }}} :: - cut -d " " -f 2- marks1.txt | paste -d " " students.txt - | grep -iv Anne + cut -d " " -c 2- marks1.txt > /tmp/m_tmp.txt .. R12 -grep allows us to do more complex searches, for instance, searching for -sentences starting or ending with a particular pattern and regular -expression based searches. - -{{{ Show slide with, tr }}} - -``tr`` is a command that takes two sets of characters as parameters, and -replaces occurrences of the characters in the first set with the -corresponding elements from the other set. It reads from the standard -output and writes to the standard output. - -For instance, if we wish to replace all the lower case letters in the -students file with upper case, we can do it as, +This displays an error saying that the delimiter option should be used +with the fields option only. You may verify this by looking at the +``m_tmp.txt`` file, which is now empty.We can now, redirect the +``stderr`` also to a file, instead of showing it on the display. .. L12 - -{{{ Switch to the terminal }}} :: - cat students.txt | tr a-z A-Z + cut -d " " -f 2- marks1.txt 1> /tmp/m_tmp.txt 2> /tmp/m_err.txt .. R13 -A common task is to remove empty newlines from a file. The ``-s`` flag -causes ``tr`` to compress sequences of identical adjacent characters in its -output to a single token. For example, +The above command redirects all the errors to the ``m_err.txt`` file +and the output to the ``m_tmp.txt`` file. When redirecting, 1 stands +for ``stdout`` and 2 stands for ``stderr``. + +Let us complete the solution by using the ``paste`` command. .. L13 :: - tr -s '\n' '\n' + paste -d " " students.txt m_tmp.txt .. R14 -Hit enter 2-3 times and see that every time we hit enter we get a newline. +So, in two steps we solved the problem of getting rid of the roll numbers +from the marks file and displaying the marks along with the names of the +students. Now, that we know how to redirect output, we could choose to +write the output to a file, instead of showing on the display. + +Let us now look at the first solution. .. L14 :: - <Enter> - <Enter> + cut -d " " -f 2- marks1.txt | paste -d " " students.txt - + +.. L15 + +{{{ Show slide, with Piping }}} .. R15 -It replaces sequences of one or more newline characters with a single newline. +First of all, the hyphen at the end is to ask the paste command to +read the standard input, instead of looking for a FILE. The ``man`` +page of ``paste`` command gives us this information. -The ``-d`` flag causes ``tr`` to delete all tokens of the specified set of -characters from its input. In this case, only a single character set -argument is used. The following command removes carriage return characters, -thereby converting a file in DOS/Windows format to the Unix format. +Now, let us observe the ``cut`` command. If we look at the command only +upto the ``|`` character, it appears as a normal ``cut`` command . -.. L15 -:: +.. L16 - cat foo.txt | tr -d '\r' > bar.txt +{{{ Show slide, with Piping.. }}} .. R16 -The ``-c`` flag complements the first set of characters. +So, the ``|`` character here, seems +to be joining the two commands in some way. +Essentially, what we are doing is, to redirect the output of the first +command to ``stdin`` and the second command takes the input from the ``stdin``. +This activity is commonly called piping and the character ``|`` is called +a pipe. -.. L16 -:: +.. L17 - tr -cd '[:alnum:]' +{{{ Show slide, with Piping... }}} .. R17 -It therefore removes all non-alphanumeric characters. +This is roughly equivalent to using two redirects and a temporary file. -Let us consider one more scenario.Suppose we have a list of items, say books, -and we wish to obtain a list which names of all the books only once, without -any duplicates. To achieve this, we use the ``uniq`` command. Let us first -have a look at our file + command1 > tempfile + command2 < tempfile + rm tempfile -.. L17 -:: +Also, given that a pipe is just a way to send the output of a command to +the ``stdin``, it should be obvious to you that we can use a chain of +pipes. Any number of commands can be piped together and therefore it should + be noted that it is not restricted to only two commands. - cat items.txt +.. L18 -.. R18 +{{{ Switch to Summary slide }}} -Now, let us try and get rid of the duplicate lines from this file using -the ``uniq`` command. +.. R18 -.. L18 -:: +This brings us to the end of the end of this tutorial. +In this tutorial, we have learnt to, - uniq items.txt + 1. Use the ``cut`` and ``paste`` commands in redirection. + 2. Use the pipe ( | ) character. + +.. L19 + +{{{ Show self assessment questions slide }}} .. R19 -Nothing happens! Why? The ``uniq`` command removes duplicate lines only when -they are next to each other. So, henceforth, we get a sorted file from the -original file and work with that file. +Here are some self assessment questions for you to solve: -.. L19 -:: +1. How will you redirect the content of a file to a device ? + +2. How to view last field(30), in a file located at /home/test.txt whose + first line is "data:myscripts:20:30" + + - cut -d : -f 4 /home/test.txt + - cut -f 3 /home/test.txt + - cut -d : -f 3 /home/test.txt + + +.. L20 - sort items.txt | uniq +{{{ Solutions for the self assessment questions on slide }}} .. R20 -``uniq -u`` command gives the lines which are unique and do not have any -duplicates in the file. ``uniq -d`` outputs only those lines which -have duplicates. +And the answers: -.. L20 +1. A file can be redirected to a device as, +:: + + cat filename > device +For eg: :: - uniq -u items-sorted.txt - -.. R21 + cat sound.wav > /dev/audio + -The ``-c`` option displays the number of times each line occurs in the file. +2. The correct option would be +:: + + cut -d : -f 4 /home/test.txt .. L21 -:: - uniq -dc items-sorted.txt +{{{ Show the SDES & FOSSEE slide }}} + +.. R21 + +Software Development techniques for Engineers and Scientists - SDES, is an +initiative by FOSSEE. For more information, please visit the given link. + +Free and Open-source Software for Science and Engineering Education - FOSSEE, is +based at IIT Bombay which is funded by MHRD as part of National Mission on +Education through ICT. .. L22 -{{{ Show summary slide }}} +{{{ Show the ``About the Spoken Tutorial Project'' slide }}} .. R22 -This brings us to the end of the end of this tutorial. -In this tutorial, we have learnt to, - - 1. Use the ``sort`` command to sort lines of text files. - #. Use the ``grep`` command to search text pattern. - #. Use the ``tr`` command to translate and/or delete characters. - #. Use the ``uniq`` command to omit repeated lines in a text. +Watch the video available at the following link. It summarises the Spoken +Tutorial project.If you do not have good bandwidth, you can download and +watch it. .. L23 -{{{ Show self assessment questions slide }}} +{{{ Show the `` Spoken Tutorial Workshops'' slide }}} .. R23 -Here are some self assessment questions for you to solve +The Spoken Tutorial Project Team conducts workshops using spoken tutorials, +gives certificates to those who pass an online test. - 1. To obtain patterns; one per line, which of the following command is used ? - - - grep -f - - grep -i - - grep -v - - grep -e - - 2. Translate the word 'linux' to upper-case. - - 3. Sort the output of the ``ls -al`` command. +For more details, contact contact@spoken-tutorial.org .. L24 -{{{ Solution of self assessment questions on slide }}} +{{{ Show the ``Acknowledgements'' slide }}} .. R24 -And the answers, - - 1. In order to obtain patterns one per line, we use the ``grep`` command - alongwith the -f option. - - 2. We use the tr command to change the word into uppercase -:: - - echo 'linux' | tr a-z A-Z - - - 3. We use the sort command as, -:: - - ls -al | sort -n -k5 -The -n means "sort numerically", and the -k5 option means to key off of -column five. +Spoken Tutorial Project is a part of the "Talk to a Teacher" project. +It is supported by the National Mission on Education through ICT, MHRD, +Government of India. More information on this mission is available at the +given link. .. L25 diff --git a/ult/ult_5/ult5.tex b/ult/ult_5/ult5.tex index 293b76f..7f22fc6 100644 --- a/ult/ult_5/ult5.tex +++ b/ult/ult_5/ult5.tex @@ -5,113 +5,174 @@ % Copyright (c) 2009, FOSSEE, IIT Bombay %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\documentclass[12pt,compress]{beamer} - +\documentclass[17pt,compress]{beamer} +\usepackage{beamerthemesplit} \mode<presentation> { \usetheme{Warsaw} \useoutertheme{infolines} \setbeamercovered{transparent} + \setbeamertemplate{navigation symbols}{} } +% Taken from Fernando's slides. +\usepackage{ae,aecompl} +\usepackage[scaled=.95]{helvet} \usepackage[english]{babel} \usepackage[latin1]{inputenc} -%\usepackage{times} \usepackage[T1]{fontenc} -% Taken from Fernando's slides. -\usepackage{ae,aecompl} -\usepackage{mathpazo,courier,euler} -\usepackage[scaled=.95]{helvet} +% change the alerted colour to LimeGreen +\definecolor{LimeGreen}{RGB}{50,205,50} +\setbeamercolor{structure}{fg=LimeGreen} +\author[FOSSEE]{} +\institute[IIT Bombay]{} +\date[]{} +% \setbeamercovered{transparent} -\definecolor{darkgreen}{rgb}{0,0.5,0} +% theme split +\usepackage{verbatim} +\newenvironment{colorverbatim}[1][]% +{% +\color{blue} +\verbatim +}% +{% +\endverbatim +}% +\usepackage{mathpazo,courier,euler} \usepackage{listings} \lstset{language=sh, basicstyle=\ttfamily\bfseries, - commentstyle=\color{red}\itshape, - stringstyle=\color{darkgreen}, showstringspaces=false, - keywordstyle=\color{blue}\bfseries} + keywordstyle=\color{black}\bfseries} + +% logo +\logo{\includegraphics[height=1.30 cm]{../images/3t-logo.pdf}} +\logo{\includegraphics[height=1.30 cm]{../images/fossee-logo.pdf} +\hspace{7.5cm} +\includegraphics[scale=0.99]{../images/fossee-logo.pdf}\\ +\hspace{281pt} +\includegraphics[scale=0.80]{../images/3t-logo.pdf}} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % DOCUMENT STARTS \begin{document} -\begin{frame} +\sffamily \bfseries +\title +[Redirection and Piping] +{Redirection and Piping} +\author +[FOSSEE] +{\small Talk to a Teacher\\{\color{blue}\url{http://spoken-tutorial.org}}\\\vspace{0.25cm}National Mission on Education + through ICT\\{\color{blue}\url{ http://sakshat.ac.in}} \\ [1.65cm] + Contributed by FOSSEE Team \\IIT Bombay \\[0.3cm] +} -\begin{center} -\vspace{12pt} -\textcolor{blue}{\huge Using Linux Tools} -\end{center} -\vspace{18pt} -\begin{center} -\vspace{10pt} -\includegraphics[scale=0.95]{../images/fossee-logo.png}\\ -\vspace{5pt} -\scriptsize Developed by FOSSEE Team, IIT-Bombay. \\ -\scriptsize Funded by National Mission on Education through ICT\\ -\scriptsize MHRD,Govt. of India\\ -\includegraphics[scale=0.30]{../images/iitb-logo.png}\\ -\end{center} +% slide 1 +\begin{frame} + \titlepage \end{frame} + \begin{frame} \frametitle{Objectives} \label{sec-2} At the end of this tutorial, you will be able to, \begin{itemize} -\item Sort lines of text files. -\item Print lines matching a pattern. -\item Translate or delete characters. -\item Omit repeated lines. +\item Understand what is Redirection +\item Learn the concept of Piping \end{itemize} \end{frame} \begin{frame} -\frametitle{Pre-requisite} +\frametitle{Pre-requisites} \label{sec-3} -Spoken tutorial on - +Spoken tutorial on, \begin{itemize} -\item Using Linux tools -- Part I -\item Using Linux tools -- Part II -\item Using Linux tools -- Part III -\item Using Linux tools -- Part IV +\item Getting started with Linux +\item Basic File Handling +\item Advanced file handling \end{itemize} \end{frame} \begin{frame}[fragile] - \frametitle{\texttt{sort} \ldots} + \frametitle{Redirection} + \begin{itemize} - \item The command below sorts, based on marks in first subject + \item The standard output (stdout) stream goes to the display + \item May not be always, what we need + \item \texttt{>} states that output is redirected to the specified location + \item It is followed by location to redirect, \end{itemize} \begin{lstlisting} - $ cut -d " " -f 2- marks1.txt \ - | paste -d " " students.txt -\ - | sort -t " " -k 2 -rn + $ command > file1 \end{lstlisting} % $ +\end{frame} + +\begin{frame}[fragile] + \frametitle{Redirection..} \begin{itemize} - \item \texttt{-t} specifies the delimiter between fields - \item \texttt{-k} specifies the field to use for sorting - \item \texttt{-r} for sorting in the reverse order - \item \texttt{-n} to choose numerical sorting + \item Similarly, the standard input (stdin) can be redirected as + \end{itemize} + \hspace{29pt}\texttt{\$ command < file1} + \begin{itemize} + \item input and output redirection could be combined + \end{itemize} + \hspace{29pt}\texttt{\$ command < infile > outfile} +\end{frame} + +\begin{frame} +\frametitle{stderr} + \begin{itemize} + \item Standard error (stderr) is the third standard stream + \item All error messages come through this stream + \item \texttt{stderr} can also be redirected + \end{itemize} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Piping} +\begin{lstlisting} +$ cut -d " " -f 2- marks1.txt + | paste -d " " students.txt - + \end{lstlisting} % $ + \begin{itemize} + \item \texttt{-} at the end asks \texttt{paste} to read from + \texttt{stdin} instead of FILE + \item \texttt{cut} command here is a normal command + \end{itemize} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Piping..} +\begin{itemize} + \item the \texttt{|} seems to be joining the two commands + \item Redirects output of first command to \texttt{stdin}, which + becomes input to the second command + \item This is called piping; \texttt{|} is called a pipe \end{itemize} \end{frame} \begin{frame}[fragile] - \frametitle{\texttt{tr}} + \frametitle{Piping..} \begin{itemize} - \item Translates or deletes characters - \item Reads from \texttt{stdin} and outputs to \texttt{stdout} - \item Given, two sets of characters, replaces one with other - \item The following, replaces all lower-case with upper-case + \item Roughly same as -- two redirects and a temporary file \end{itemize} \begin{lstlisting} - $ cat students.txt | tr a-z A-Z - \end{lstlisting} % $ + $ command1 > tempfile + $ command2 < tempfile + $ rm tempfile +\end{lstlisting} % $ +\begin{itemize} +\item Any number of commands can be piped together +\end{itemize} \end{frame} + \begin{frame} \frametitle{Summary} \label{sec-8} @@ -120,10 +181,8 @@ Spoken tutorial on - \begin{itemize} -\item Use the ``sort'' command to sort lines of text files. -\item Use the ``grep'' command to search text pattern. -\item Use the ``tr'' command to translate and/or delete characters. -\item Use the ``uniq'' command to omit repeated lines in a text. +\item Use the ``cut'' and ``paste'' commands in redirection +\item Use the pipe ( | ) character \end{itemize} \end{frame} \begin{frame}[fragile] @@ -132,18 +191,16 @@ Spoken tutorial on - \begin{enumerate} -\item To obtain patterns; one per line, which of the following command is used ? -\vspace{3pt} +\item How will you redirect the content of a file to a device ? +\vspace{12pt} +\item How to view last field(30), in a file located at \verb~/home/test.txt~ +whose first line is "data:myscripts:20:30" +\vspace{5pt} \begin{itemize} -\item grep -f -\item grep -i -\item grep -v -\item grep -e +\item cut -d : -f 4 /home/test.txt +\item cut -f 3 /home/test.txt +\item cut -d : -f 3 /home/test.txt \end{itemize} -\vspace{8pt} -\item Translate the word `linux' to upper-case. -\vspace{8pt} -\item Sort the output of the ``ls -al'' command. \end{enumerate} \end{frame} \begin{frame} @@ -152,27 +209,76 @@ Spoken tutorial on - \begin{enumerate} -\item grep -f -\vspace{15pt} -\item \$ echo `linux' | tr a-z A-Z -\vspace{15pt} -\item \$ ls -al | sort -n -k5 +\item \$ cat filename > device\\ +For eg:\\ +\hspace{8pt} \verb~cat sound.wav > /dev/audio~ +\vspace{22pt} +\item \$ cut -d : -f 4 /home/test.txt \end{enumerate} \end{frame} + +\begin{frame} +\frametitle{SDES \& FOSSEE} +\begin{center} +\begin{itemize} +\item \small{SDES}\\ +\small{\color{LimeGreen}Software Development techniques for Engineers and Scientists} \\ +\scriptsize An initiative by FOSSEE. \\ +\vspace{3pt} +\scriptsize For more information on SDES, please visit {\color{blue}\url{http://fossee.in/sdes}}\\ +\vspace{10pt} +\item \small{FOSSEE}\\ +\small {\color{LimeGreen}Free and Open-source Software for \\Science and Engineering Education} \\ +\scriptsize Based at IIT Bombay, Funded by MHRD.\\ +\vspace{3pt} +\scriptsize Part of National Mission on Education through ICT \\(NME-ICT) \\ +\end{itemize} +\end{center} +\end{frame} + +\begin{frame} +\frametitle{About the Spoken Tutorial Project} +\begin{itemize} +\item Watch the video available at {\color{blue}\url{http://spoken-tutorial.org /What\_is\_a\_Spoken\_Tutorial}} +\item It summarises the Spoken Tutorial project +\item If you do not have good bandwidth, you can download and watch it +\end{itemize} +\end{frame} + +\begin{frame} +\frametitle{Spoken Tutorial Workshops}The Spoken Tutorial Project Team +\begin{itemize} +\item Conducts workshops using spoken tutorials +\item Gives certificates to those who pass an online test +\item For more details, please write to \\ \hspace {0.5cm}{\color{blue}contact@spoken-tutorial.org} +\end{itemize} +\end{frame} + +\begin{frame} +\frametitle{Acknowledgements} +\begin{itemize} +\item Spoken Tutorial Project is a part of the Talk to a Teacher project +\item It is supported by the National Mission on Education through ICT, MHRD, Government of India +\item More information on this Mission is available at: \\{\color{blue}\url{http://spoken-tutorial.org/NMEICT-Intro}} +\end{itemize} +\end{frame} + \begin{frame} \begin{block}{} \begin{center} - \textcolor{blue}{\Large THANK YOU!} + {\Large THANK YOU!} \end{center} \end{block} \begin{block}{} \begin{center} For more Information, visit our website\\ - \url{http://fossee.in/} + {\color{blue}\url{http://fossee.in/}} \end{center} \end{block} \end{frame} + \end{document} + diff --git a/ult/ult_6/results.sh b/ult/ult_6/results.sh deleted file mode 100755 index acdac84..0000000 --- a/ult/ult_6/results.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -mkdir ~/marks -cut -d " " -f 2- marks1.txt | paste -d " " students.txt - | sort > ~/marks/results.txt diff --git a/ult/ult_6/script.rst b/ult/ult_6/script.rst index 0413ada..020f3a6 100644 --- a/ult/ult_6/script.rst +++ b/ult/ult_6/script.rst @@ -3,19 +3,15 @@ .. At the end of this tutorial, you will be able to: - .. 1. Prepare a simple shell script. - .. 2. Run a script successfully and print it's result. - .. 3. Understand what an environment variable is. + .. 1. Understand various features of shell + .. 2. Learn about shell meta characters .. Prerequisites .. ------------- -.. 1. Using Linux tools - Part 1 -.. 2. Using Linux tools - Part 2 -.. 3. Using Linux tools - Part 3 -.. 4. Using Linux tools - Part 4 -.. 5. Using Linux tools - Part 5 - +.. 1. Getting started with Linux +.. 2. Basic File Handling +.. 4. Advanced file handling Script ------ @@ -28,7 +24,7 @@ team along with the logo of MHRD }}} .. R1 Hello friends and Welcome to the tutorial on -'Using linux tools - Part 6'. +'Redirection and Piping'. .. L2 @@ -38,9 +34,8 @@ Hello friends and Welcome to the tutorial on At the end of this tutorial, you will be able to, - 1. Prepare a simple shell script. - #. Run a script successfully and print it's result. - #. Understand what an environment variable is. + 1. Understand various features of shell + #. Learn about shell meta characters .. L3 @@ -49,248 +44,236 @@ At the end of this tutorial, you will be able to, .. R3 Before beginning this tutorial,we would suggest you to complete the -tutorial on "Using Linux tools from Part 1 to Part 5". +former tutorials as being displayed currently. + +.. L4 -Let us start with creating a simple shell script. -A shell script is simply a sequence of commands, that are put into a file, -instead of entering them one by one onto the shell. The script can then be -run, to run the sequence of commands in a single shot instead of manually -running, each of the individual commands. -For instance, let's say we wish to create a directory called ``marks`` in the -home folder and save the results of the students into a file -``results.txt``. +{{{ Show slide, with Tab-completion }}} .. R4 -We open our editor and save the following text to ``results.sh`` +The Bash shell has some nice features, that make our job of using the shell +easier and much more pleasant. We shall look at a few of them, here. -.. L4 -{{{ Open an editor and type the following }}} -:: +Bash provides the feature of tab completion. What does tab completion mean? +When you are trying to type a word, bash can complete the word for you, if you +have entered enough portion of the word (to complete it unambiguously) and +then hit the tab key. - #!/bin/bash - mkdir ~/marks - cut -d " " -f 2- marks1.txt | paste -d " " students.txt - | sort > ~/marks/results.txt +If on hitting the tab key, the word doesn't get completed, either the word +doesn't exist or the word cannot be decided unambiguously. If the case is the +latter one, hitting the tab key a second time, will list the possibilities. -.. R5 +.. L5 -We can now run the script as, +{{{ Show slide, with Tab-completion.. }}} -.. L5 +.. R5 -{{{ Open the terminal }}} -:: +Bash provides tab completion for the following. - ./results.sh + File Names + Directory Names + Executable Names + User Names (when they are prefixed with a ~) + Host Names (when they are prefixed with a @) + Variable Names (when they are prefixed with a $) .. R6 -We get an error saying, Permission denied! Why? Can you think of the -reason? Yes, the file doesn't have execute permissions. -We make the file executable and then run it. +For example, .. L6 -:: - - chmod u+x results.sh - ./results.sh -.. R7 +{{{ Switch to terminal }}} +:: -We get back the prompt. We can check the contents of the file -``results.txt`` to see if the script has run. -So, here, we have our first shell script. The first line of the script is used -to specify the interpreter or shell which should be used to execute the script. -In this case, we are asking it to use the bash shell. -Once, the script has run, we get back the prompt. Here, we had to manually check, -if the contents of the file are correct. It would be useful to have our script -print out messages. For this, we can use the ``echo`` command. We can edit our -``results.sh`` script, as follows. + pas<TAB><TAB> + PA<TAB> + ~/<TAB><TAB> .. L7 -{{{ Open an editor and type the following }}} -:: +{{{ Show slide, with History }}} - #!/bin/bash - mkdir ~/marks - cut -d " " -f 2- marks1.txt | paste -d " " students.txt - | sort > ~/marks/results.txt - echo "Results generated." - -.. R8 - -Now, on running the script, we get a message on the screen informing us, -when the script has run. +.. R7 -Let's now say, that we wish to let the user decide the file to which the -results should be written to. The results file, should be specifiable by an -argument in the command line. We can do so, by editing the file, as below. +Bash also saves the history of the commands you have typed. So, you can go +back to a previously typed command. Use the up and down arrow keys to navigate +in your bash history. +You can also search incrementally, for commands in your bash history. Ctrl-r +search for the commands that you have typed before. But, note that the number +of commands saved in the history is limited, generally upto a 1000 commands. .. L8 -{{{ Make the necessary changes in the previous script }}} - +{{{ Switch to terminal }}} :: - #!/bin/bash - mkdir ~/marks - cut -d " " -f 2- marks1.txt | paste -d " " students.txt - | sort > ~/marks/$1 - echo "Results generated." + <Ctrl-r> pas +.. R8 -{{{ Highlight the text ``$1`` }}} +.. L9 + +{{{ Show slide, with Shell Meta Characters }}} .. R9 -The ``$1`` above, corresponds to the first command line argument to the -script. So, we can run the script as shown below, to save the results to -``grades.txt``. +Unix recognizes certain special characters, called "meta characters," as +command directives. The shell meta characters are recognized anywhere they +appear in the command line, even if they are not surrounded by blank space. +For that reason, it is safest to only use the characters A-Z, a-z, 0-9, and +the period, dash, and underscore characters when naming files and directories + on Unix. If your file or directory has a shell meta character in the name, +you will find it difficult to use the name in a shell command. -.. L9 -:: +The characters that you see on the slide are the shell meta characters - ./results.sh grades.txt + / < > ! $ % ^ & * | { } [ ] " ' ` ~ ; .. R10 -When we run the ``results.sh`` file, we are specifying the location of the -script by using ``./``. But for any of the other commands, -we didn't have to specify their locations. Why? The -shell has a set of locations where it searches, for the command that we are -trying to run. +Let's take an example, .. L10 -.. L11 +{{{ Switch to terminal }}} +:: -{{{ Show slide, PATH }}} + ls file.* .. R11 -These set of locations are saved in an "environment" -variable called PATH.let us look at what the value of the PATH variable is. To view the -values of variables, we can use the echo command. +It means, run on a directory containing the files file, file.c, file.lst, and +myfile would list the files file.c and file.lst. However, -.. L12 +.. L11 -{{{ Switch to the terminal }}} :: - echo $PATH + ls file.? .. R12 -So, these are all the paths that are searched, when looking to execute a -command. If we put the results.sh script in one of these locations, we -could simply run it, without using the ``./`` at the beginning. +Run on the same directory would only list file.c because the ? only +matches one character, no more, no less. This can save you a great deal of +typing time. -.. L13 +For example, if there is a file called california_cornish_hens_with_wild_rice +and no other files whose names begin with 'c', you could view the file without +typing the whole name by typing this + +.. L12 + +:: -{{{ Show slide, variables & comments }}} + more c* .. R13 -As expected, it is possible to define our own variables inside our shell -scripts. For example, +Here, the c* matches that long file name. -.. L14 +File-names containing metacharacters can pose many problems and should never +be intentionally created. -{{{ Switch to the terminal }}} -:: +.. L13 - name="FOSSEE" +.. L14 + +{{{ Switch to Summary slide }}} .. R14 -It creates a new variable ``name`` whose value is ``FOSSEE``. To refer to this -variable, inside our shell script, we would refer to it, as ``$name``. -Note that, there is no space around the ``=`` sign. +This brings us to the end of the end of this tutorial. +In this tutorial, we have learnt to, +1. Implement features of tab-completion and history. +#. Make use of the shell meta characters. + .. L15 -:: - - ls $name* + +{{{ Show self assessment questions slide }}} .. R15 -.. R16 +Here are some self assessment questions for you to solve: -It is possible to store the output of a command in a variable, by enclosing -the command in back-quotes. +1. Bash does not provide tab completion for Host Names. True of False? + +2. State the command which will list all the files in the current working + directory that end in either .c or .h .. L16 -:: - count=`wc -l wonderland.txt` +{{{ Solutions for the self assessment questions on slide }}} -.. R17 +.. R16 -It saves the number of lines in the file ``wonderland.txt`` in the variable -count. +And the answers: -The ``#`` character is used to comment out content from a shell script. -Anything that appears after the ``#`` character in a line, is ignored by -the bash shell. +1. False. Bash provides tab completion for Host Names when they are prefixed + with a @ sign. -.. L18 + +2. The command which will find the files ending either in .c or .h is, +:: -.. L19 + ls *.[ch] -{{{ Switch to 'Summary' slide }}} -.. R19 +.. L17 -This brings us to the end of the end of this tutorial. -In this tutorial, we have learnt to, +{{{ Show the SDES & FOSSEE slide }}} - 1. Prepare a shell script. - #. Display the result of a script, using the ``echo`` command. - #. Use the environment variable ``PATH``. - #. Create variables and comment out content using the ``#`` sign. +.. R17 -.. L20 +Software Development techniques for Engineers and Scientists - SDES, is an +initiative by FOSSEE. For more information, please visit the given link. -{{{ Show self assessment questions slide }}} +Free and Open-source Software for Science and Engineering Education - FOSSEE, is +based at IIT Bombay which is funded by MHRD as part of National Mission on +Education through ICT. -.. R20 +.. L18 -Here are some self assessment questions for you to solve +{{{ Show the ``About the Spoken Tutorial Project'' slide }}} - 1. Which sign is used to comment out content from a shell script. - - - $ - - % - - # - - * +.. R18 - 2. How will you add directory ``/data/myscripts`` to the beginning of - the $PATH environment variable ? +Watch the video available at the following link. It summarises the Spoken +Tutorial project.If you do not have good bandwidth, you can download and +watch it. -.. L21 +.. L19 -{{{ Solution of self assessment questions on slide }}} +{{{ Show the `` Spoken Tutorial Workshops'' slide }}} -.. R21 +.. R19 -And the answers, +The Spoken Tutorial Project Team conducts workshops using spoken tutorials, +gives certificates to those who pass an online test. - 1. We use the ``#`` sign to comment out the content from a shell script. +For more details, contact contact@spoken-tutorial.org - 2. In order to add a directory to the beginning of the $PATH variable,we - say, -:: +.. L20 - $PATH=/data/myscripts:$PATH +{{{ Show the ``Acknowledgements'' slide }}} -.. L22 +.. R20 + +Spoken Tutorial Project is a part of the "Talk to a Teacher" project. +It is supported by the National Mission on Education through ICT, MHRD, +Government of India. More information on this mission is available at the +given link. + +.. L21 {{{ Show the Thank you slide }}} -.. R22 +.. R21 Hope you have enjoyed this tutorial and found it useful. Thank you! - - diff --git a/ult/ult_6/ult6.tex b/ult/ult_6/ult6.tex deleted file mode 100644 index 389a602..0000000 --- a/ult/ult_6/ult6.tex +++ /dev/null @@ -1,176 +0,0 @@ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Using Linux Tools -% -% Author: FOSSEE -% Copyright (c) 2009, FOSSEE, IIT Bombay -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -\documentclass[12pt,compress]{beamer} - -\mode<presentation> -{ - \usetheme{Warsaw} - \useoutertheme{infolines} - \setbeamercovered{transparent} -} - -\usepackage[english]{babel} -\usepackage[latin1]{inputenc} -%\usepackage{times} -\usepackage[T1]{fontenc} - -% Taken from Fernando's slides. -\usepackage{ae,aecompl} -\usepackage{mathpazo,courier,euler} -\usepackage[scaled=.95]{helvet} - -\definecolor{darkgreen}{rgb}{0,0.5,0} - -\usepackage{listings} -\lstset{language=sh, - basicstyle=\ttfamily\bfseries, - commentstyle=\color{red}\itshape, - stringstyle=\color{darkgreen}, - showstringspaces=false, - keywordstyle=\color{blue}\bfseries} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% DOCUMENT STARTS -\begin{document} - -\begin{frame} - -\begin{center} -\vspace{12pt} -\textcolor{blue}{\huge Using Linux Tools\\Part VI} -\end{center} -\vspace{18pt} -\begin{center} -\vspace{10pt} -\includegraphics[scale=0.95]{../images/fossee-logo.png}\\ -\vspace{5pt} -\scriptsize Developed by FOSSEE Team, IIT-Bombay. \\ -\scriptsize Funded by National Mission on Education through ICT\\ -\scriptsize MHRD,Govt. of India\\ -\includegraphics[scale=0.30]{../images/iitb-logo.png}\\ -\end{center} -\end{frame} -\begin{frame} -\frametitle{Objectives} -\label{sec-2} - -At the end of this tutorial, you will be able to, -\begin{itemize} -\item Prepare a simple shell script. -\item Run a script successfully and print it's result. -\item Understand what an environment variable is. -\end{itemize} -\end{frame} - -\begin{frame} -\frametitle{Pre-requisite} -\label{sec-3} - -Spoken tutorial on - -\begin{itemize} -\item Using Linux tools -- Part I -\item Using Linux tools -- Part II -\item Using Linux tools -- Part III -\item Using Linux tools -- Part IV -\item Using Linux tools -- Part V -\end{itemize} -\end{frame} - -\begin{frame}[fragile] - \frametitle{\texttt{PATH}} - \begin{itemize} - \item The shell searches in a set of locations, for the command - \item Locations are saved in ``environment'' variable called PATH - \item \texttt{echo} can show the value of variables - \end{itemize} - \begin{lstlisting} - $ echo $PATH - \end{lstlisting} % $ - \begin{itemize} - \item Put \texttt{results.sh} in one of these locations - \item It can then be run without \texttt{./} - \end{itemize} -\end{frame} - -\begin{frame}[fragile] - \frametitle{Variables \& Comments} - \begin{lstlisting} - $ name=FOSSEE - $ count=`wc -l wonderland.txt` - $ echo $count # Shows the value of count - \end{lstlisting} % $ - \begin{itemize} - \item It is possible to create variables in shell scripts - \item Variables can be assigned with the output of commands - \item \alert{NOTE:} There is no space around the \texttt{=} sign - \item All text following the \texttt{\#} is considered a comment - \end{itemize} -\end{frame} - -\begin{frame} -\frametitle{Summary} -\label{sec-8} - - In this tutorial, we have learnt to, - - -\begin{itemize} -\item Prepare a shell script. -\item Display the result of a script, using the ``echo'' command. -\item Use the environment variable ``PATH''. -\item Create variables and comment out content using the ``\#'' sign. -\end{itemize} -\end{frame} - -\begin{frame}[fragile] -\frametitle{Evaluation} -\label{sec-9} - - -\begin{enumerate} -\item Which sign is used to comment out content from a shell script? -\begin{itemize} -\item \$ -\item \% -\item \# -\item * -\end{itemize} -\vspace{8pt} -\item How will you add directory ``/data/myscripts'' to the beginning of - the \$PATH environment variable ? -\end{enumerate} -\end{frame} -\begin{frame} -\frametitle{Solutions} -\label{sec-10} - - -\begin{enumerate} -\item `` \# '' -\vspace{15pt} -\item \$ PATH=/data/myscripts:\$PATH -\end{enumerate} -\end{frame} -\begin{frame} - - \begin{block}{} - \begin{center} - \textcolor{blue}{\Large THANK YOU!} - \end{center} - \end{block} -\begin{block}{} - \begin{center} - For more Information, visit our website\\ - \url{http://fossee.in/} - \end{center} - \end{block} -\end{frame} - -\end{document} - - diff --git a/ult/ult_6/ult_6.tex b/ult/ult_6/ult_6.tex new file mode 100644 index 0000000..c42fa21 --- /dev/null +++ b/ult/ult_6/ult_6.tex @@ -0,0 +1,244 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Using Linux Tools +% +% Author: FOSSEE +% Copyright (c) 2009, FOSSEE, IIT Bombay +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\documentclass[17pt,compress]{beamer} +\usepackage{beamerthemesplit} +\mode<presentation> +{ + \usetheme{Warsaw} + \useoutertheme{infolines} + \setbeamercovered{transparent} + \setbeamertemplate{navigation symbols}{} +} +% Taken from Fernando's slides. +\usepackage{ae,aecompl} +\usepackage[scaled=.95]{helvet} + +\usepackage[english]{babel} +\usepackage[latin1]{inputenc} +\usepackage[T1]{fontenc} + +% change the alerted colour to LimeGreen +\definecolor{LimeGreen}{RGB}{50,205,50} +\setbeamercolor{structure}{fg=LimeGreen} +\author[FOSSEE]{} +\institute[IIT Bombay]{} +\date[]{} +% \setbeamercovered{transparent} + +% theme split +\usepackage{verbatim} +\newenvironment{colorverbatim}[1][]% +{% +\color{blue} +\verbatim +}% +{% +\endverbatim +}% + +\usepackage{mathpazo,courier,euler} +\usepackage{listings} +\lstset{language=sh, + basicstyle=\ttfamily\bfseries, + showstringspaces=false, + keywordstyle=\color{black}\bfseries} + +% logo +\logo{\includegraphics[height=1.30 cm]{../images/3t-logo.pdf}} +\logo{\includegraphics[height=1.30 cm]{../images/fossee-logo.pdf} + +\hspace{7.5cm} +\includegraphics[scale=0.99]{../images/fossee-logo.pdf}\\ +\hspace{281pt} +\includegraphics[scale=0.80]{../images/3t-logo.pdf}} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% DOCUMENT STARTS +\begin{document} + +\sffamily \bfseries +\title +[Features of the Shell] +{Features of the Shell} +\author +[FOSSEE] +{\small Talk to a Teacher\\{\color{blue}\url{http://spoken-tutorial.org}}\\\vspace{0.25cm}National Mission on Education + through ICT\\{\color{blue}\url{ http://sakshat.ac.in}} \\ [1.65cm] + Contributed by FOSSEE Team \\IIT Bombay \\[0.3cm] +} + +% slide 1 +\begin{frame} + \titlepage +\end{frame} + +\begin{frame} +\frametitle{Objectives} +\label{sec-2} + +At the end of this tutorial, you will be able to, +\begin{itemize} +\item Understand various features of the shell +\item Learn about shell meta characters +\end{itemize} +\end{frame} + +\begin{frame} +\frametitle{Pre-requisites} +\label{sec-3} + +Spoken tutorial on, +\begin{itemize} +\item Getting started with Linux +\item Basic File Handling +\end{itemize} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Tab-completion} +\begin{itemize} +\item Hit tab to complete an incompletely typed word +\item Tab twice to list all possibilities when ambiguous completion +\end{itemize} +\end{frame} + +\begin{frame}[fragile] + \frametitle{Tab-completion..} + \begin{itemize} + \item Bash provides tab completion for the following + \begin{enumerate} + \item File Names + \item Directory Names + \item Executable Names + \item User Names (when prefixed with a \~{}) + \item Host Names (when prefixed with a @) + \item Variable Names (when prefixed with a \$) + \end{enumerate} + \end{itemize} +\end{frame} + +\begin{frame}[fragile] +\frametitle{History} +\begin{itemize} +\item Bash saves history of commands typed +\item Up and down arrow keys allow to navigate history +\item \texttt{Ctrl-r} searches for commands used +\item No. of commands limited, generally upto 1000 +\end{itemize} +\end{frame} + +\begin{frame}[fragile] + \frametitle{Shell Meta Characters} + \begin{itemize} + \item ``meta characters'' are special command directives + \item No meta-characters in file-names + \item While naming files, use characters A-Z, a-z, 0-9, . , - , \_ + \item shell meta characters -- \\ + \verb+/<>!$%^&*|{}[]"'`~;+ + \end{itemize} +\end{frame} + +\begin{frame} +\frametitle{Summary} +\label{sec-8} + + In this tutorial, we have learnt to, + + +\begin{itemize} +\item Implement features of shell like tab-completion and history +\item Make use of the shell meta characters +\end{itemize} +\end{frame} +\begin{frame}[fragile] +\frametitle{Evaluation} +\label{sec-9} + + +\begin{enumerate} +\item Bash does not provide tab completion for Host Names. True or False? +\vspace{12pt} +\item State the command which will list all the files in the current working + directory that end in either \verb~.c~ or \verb~.h~ +\end{enumerate} +\end{frame} +\begin{frame} +\frametitle{Solutions} +\label{sec-10} + + +\begin{enumerate} +\item False +\vspace{15pt} +\item \$ ls *.[ch] +\end{enumerate} +\end{frame} + +\begin{frame} +\frametitle{SDES \& FOSSEE} +\begin{center} +\begin{itemize} +\item \small{SDES}\\ +\small{\color{LimeGreen}Software Development techniques for Engineers and Scientists} \\ +\scriptsize An initiative by FOSSEE. \\ +\vspace{3pt} +\scriptsize For more information on SDES, please visit {\color{blue}\url{http://fossee.in/sdes}}\\ +\vspace{10pt} +\item \small{FOSSEE}\\ +\small {\color{LimeGreen}Free and Open-source Software for \\Science and Engineering Education} \\ +\scriptsize Based at IIT Bombay, Funded by MHRD.\\ +\vspace{3pt} +\scriptsize Part of National Mission on Education through ICT \\(NME-ICT) \\ +\end{itemize} +\end{center} +\end{frame} + +\begin{frame} +\frametitle{About the Spoken Tutorial Project} +\begin{itemize} +\item Watch the video available at {\color{blue}\url{http://spoken-tutorial.org /What\_is\_a\_Spoken\_Tutorial}} +\item It summarises the Spoken Tutorial project +\item If you do not have good bandwidth, you can download and watch it +\end{itemize} +\end{frame} + +\begin{frame} +\frametitle{Spoken Tutorial Workshops}The Spoken Tutorial Project Team +\begin{itemize} +\item Conducts workshops using spoken tutorials +\item Gives certificates to those who pass an online test +\item For more details, please write to \\ \hspace {0.5cm}{\color{blue}contact@spoken-tutorial.org} +\end{itemize} +\end{frame} + +\begin{frame} +\frametitle{Acknowledgements} +\begin{itemize} +\item Spoken Tutorial Project is a part of the Talk to a Teacher project +\item It is supported by the National Mission on Education through ICT, MHRD, Government of India +\item More information on this Mission is available at: \\{\color{blue}\url{http://spoken-tutorial.org/NMEICT-Intro}} +\end{itemize} +\end{frame} + +\begin{frame} + + \begin{block}{} + \begin{center} + {\Large THANK YOU!} + \end{center} + \end{block} +\begin{block}{} + \begin{center} + For more Information, visit our website\\ + {\color{blue}\url{http://fossee.in/}} + \end{center} + \end{block} +\end{frame} + + +\end{document} + diff --git a/ult/ult_7/06- track.mp3 b/ult/ult_7/06- track.mp3 deleted file mode 100644 index e69de29..0000000 --- a/ult/ult_7/06- track.mp3 +++ /dev/null diff --git a/ult/ult_7/clause.sh b/ult/ult_7/clause.sh deleted file mode 100644 index 23017f2..0000000 --- a/ult/ult_7/clause.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/sh -# Script to greet the user according to time of day -hour=`date | cut -c12-13` -now=`date +"%A, %d of %B, %Y (%r)"` -if [ $hour -lt 12 ] -then - mess="Good Morning $LOGNAME, Have a nice day!" -fi - -if [ $hour -gt 12 -a $hour -le 16 ] -then - mess="Good Afternoon $LOGNAME" -fi - -if [ $hour -gt 16 -a $hour -le 18 ] -then - mess="Good Evening $LOGNAME" -fi -echo -e "$mess\nIt is $now" - diff --git a/ult/ult_7/dir-test.sh b/ult/ult_7/dir-test.sh deleted file mode 100644 index 11479ff..0000000 --- a/ult/ult_7/dir-test.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -if test -d $1 -then - echo "Yes, the directory" $1 "is present" -fi diff --git a/ult/ult_7/emerald.mp3 b/ult/ult_7/emerald.mp3 deleted file mode 100644 index e69de29..0000000 --- a/ult/ult_7/emerald.mp3 +++ /dev/null diff --git a/ult/ult_7/foo.txt b/ult/ult_7/foo.txt new file mode 100644 index 0000000..1fe9426 --- /dev/null +++ b/ult/ult_7/foo.txt @@ -0,0 +1,9 @@ +FOO is an abbreviation of Forward Observation Officer, a British Army +term in use as early as the First World War. The etymology of foo is +explored in the Internet Engineering Task Force (IETF) Request for +Comments 3092, which notes usage of foo in 1930s cartoons including +The Daffy Doc (with Daffy Duck) and comic strips, especially Smokey +Stover and Pogo. From there the term migrated into military slang, +where it merged with FUBAR. + +source: wikipedia diff --git a/ult/ult_7/for-1.sh b/ult/ult_7/for-1.sh deleted file mode 100644 index 86545b7..0000000 --- a/ult/ult_7/for-1.sh +++ /dev/null @@ -1,4 +0,0 @@ -for i in {5..10} -do - echo $i -done diff --git a/ult/ult_7/for-2.sh b/ult/ult_7/for-2.sh deleted file mode 100644 index ad34c9a..0000000 --- a/ult/ult_7/for-2.sh +++ /dev/null @@ -1,4 +0,0 @@ -for i in `ls *.mp3` -do - echo "$i" -done diff --git a/ult/ult_7/for-3.sh b/ult/ult_7/for-3.sh deleted file mode 100644 index 8bb9f8d..0000000 --- a/ult/ult_7/for-3.sh +++ /dev/null @@ -1,4 +0,0 @@ -for i in *.mp3 -do - echo "$i" -done diff --git a/ult/ult_7/for-5.sh b/ult/ult_7/for-5.sh deleted file mode 100644 index dc17f64..0000000 --- a/ult/ult_7/for-5.sh +++ /dev/null @@ -1,4 +0,0 @@ -for i in *.mp3 -do - mv $i `echo $f|tr -s " " "-"|cut -d - -f 2-` -done diff --git a/ult/ult_6/marks1.txt b/ult/ult_7/marks1.txt index 9a5299d..9a5299d 100644 --- a/ult/ult_6/marks1.txt +++ b/ult/ult_7/marks1.txt diff --git a/ult/ult_7/premier.mp3 b/ult/ult_7/premier.mp3 deleted file mode 100644 index e69de29..0000000 --- a/ult/ult_7/premier.mp3 +++ /dev/null diff --git a/ult/ult_7/script.rst b/ult/ult_7/script.rst index 4efdfd9..b4cb55c 100644 --- a/ult/ult_7/script.rst +++ b/ult/ult_7/script.rst @@ -3,18 +3,17 @@ .. At the end of this tutorial, you will be able to: - .. 1. Prepare scripts using 'Control Operators'. - .. 2. Understand what 'Environment Variables' are. + .. 1. Sort lines of text files + .. 2. Print lines matching a pattern + .. 3. Translate or delete characters + .. 4. Omit repeated lines + .. Prerequisites .. ------------- -.. 1. Using Linux tools - Part 1 -.. 2. Using Linux tools - Part 2 -.. 3. Using Linux tools - Part 3 -.. 4. Using Linux tools - Part 4 -.. 5. Using Linux tools - Part 5 -.. 6. Using Linux tools - Part 6 +.. 1. Getting started with Linux +.. 2. Redirection and Piping @@ -28,374 +27,367 @@ team along with the logo of MHRD }}} .. R1 -Hello friends and Welcome to the tutorial on -'Using linux tools - Part 7'. +Hello friends and Welcome to the tutorial on 'Text Processing'. .. L2 -{{{ Show the 'Objectives' slide }}} +{{{ Show slide with objectives }}} .. R2 At the end of this tutorial, you will be able to, - 1. Prepare scripts using 'Control Operators'. - 2. Understand what 'Environment Variables' are. - + 1. Sort lines of text files + #. Print lines matching a pattern + #. Translate or delete characters + #. Omit repeated lines. + + .. L3 {{{ Switch to the pre-requisite slide }}} .. R3 -Before beginning this tutorial, we suggest you to complete the -tutorials, "Using Linux tools, Part 1 to Part 6". +Before beginning this tutorial,we would suggest you to complete the +former tutorials as being displayed currently. .. R4 -We have many 'Control Structures and Operators' available in the linux bash. -Let us look at how to use them. -To write an 'if', or an 'if-else' construct, we need to check or test for a -condition(s). The ``test`` command allows us to test for condition(s). It has -a whole range of tests that can be performed. The man page of ``test`` -gives you the complete listing of various types of tests that can be performed -with it. - -Let's write a simple script with an ``if`` condition that tests whether a -directory with a particular name, exists or not. +In this tutorial, we shall learn about text processing. +TO begin with, consider data kept in two files, namely marks1.txt and +students.txt +Let us see what data they contain. Open a terminal and type, .. L4 -.. L5 +{{{ Open the terminal }}} +:: -{{{ Show slide, 'if' }}} + cat marks1.txt + cat students.txt .. R5 -Let us create a script named ``dir-test.sh`` with this code. +Let's say we wish to sort the output in the alphabetical order +of the names of the files. We can use the ``sort`` command for this +purpose. - #!/bin/bash - if test -d $1 - then - echo "Yes, the directory" $1 "is present" - fi +We just pipe the previous output to the ``sort`` command as, -When the script is run with an argument, it will print a message, if a -directory with the said name exists in the current working directory. +.. L5 +:: + + cut -d " " -f 2- marks1.txt | paste -d " " students.txt -| sort .. R6 -Let's write a simple script which returns back whether the argument passed -is negative or not. +Let's say we wish to sort the names, based on the marks in the first +subject i.e. the first column after the name. ``sort`` command also allows us to +specify the delimiter between the fields and sort the data on a particular +field. ``-t`` option is used to specify the delimiter and ``-k`` option +is used to specify the field. .. L6 - -{{{ Open the file sign.sh and show }}} :: - #!/bin/bash - if test $1 -lt 0 - then - echo "number is negative" - else - echo "number is non-negative" - fi - -.. R7 - -We can run the file with a set of different inputs and see if it works. + cut -d " " -f 2- marks1.txt | paste -d " " students.txt -| sort -t " " -k 2 .. L7 -{{{ Switch to terminal }}} -:: +{{{ Show slide with, Sort... }}} + +.. R7 - ./sign.sh -11 +This command give us a sorted output as required. But, what if we would +like the output to appear in the reverse order. ``-r`` option allows the output +to be sorted in the reverse order and the ``-n`` option is used to choose +a numerical sorting. .. R8 -Instead of using the ``test`` command, square brackets may also be used. +Let us do it on the terminal and see for ourselves, .. L8 -.. L9 +{{{ Switch to the terminal }}} +:: -{{{ Show slide, [ ] - alias for test }}} + cut -d " " -f 2- marks1.txt | paste -d " " students.txt -| + sort -t " " -k 2 -rn .. R9 -Note that the spacing is important, when using the square brackets. -The left square bracket ( ``[`` ) should be followed by a space and the right -square bracket ( ``]`` ) should be preceded by a space. +Suppose, While you are compiling the student marklist, Anne walks up to you and +wants to know her marks. You, being a kind person that you are, oblige. +But you do not wish to her to see the marks that others have scored. What +do you do? Here, the ``grep`` command comes to your rescue. -Let's create something interesting using the 'if-else' clause. Let's write a -script, that greets the user, based on the time. +``grep`` is a command line text search utility. You can use it to search +for Anne and show her, what she scored. ``grep`` allows us to search for a +search string in files. But we could, like any other command, pipe the +output of other commands to it. So, we shall use the previous combination +of cut and paste that we had, to get the marks of students along with their +names and search for Anne in that. -.. L10 +.. L9 +:: -{{{ Open the file clause.sh and show }}} -{{{ Highlight the required content wherever necessary, while narrating }}} + cut -d " " -f 2- marks1.txt | paste -d " " students.txt - | grep Anne .. R10 -There are a couple of new things in this script. ``$LOGNAME`` is another -'environment variable', which has the login name of the user. The variables, -``hour`` and ``now`` are actually taking the output of the commands that -are placed in the back quotes. +This will give us only the line containing the word Anne as the output. +The grep command is by default case-sensitive. So, we wouldn't have got +the result if we had searched for anne, with a small a, instead of +Anne, with a capital a. But, what if we didn't know, whether the name was +capitalized or not? ``grep`` allows you to do case-insensitive searches +by using the ``-i`` option. -Now, let us see how to run loops in bash. We shall look at the ``for`` and -the ``while`` loops. - -.. L11 +.. L10 +:: -{{{ Show slide, 'for' }}} + cut -d " " -f 2- marks1.txt | paste -d " " students.txt - | grep -i Anne .. R11 -Suppose we have a set of files, whose file-names contain numbers before the -text, say ``08 - Society.mp3``. We would like to rename these files by -removing the numbers before the text. How would we go about doing that? +Now, in another scenario, if we wished to print all the lines, which do +not contain the word Anne, we could use the ``-v`` option. -It is clear from the problem statement that we could loop over the list of -files and rename each of them. +.. L11 +:: + + cut -d " " -f 2- marks1.txt | paste -d " " students.txt - | grep -iv Anne .. R12 -First, let us look at a simple ``for`` loop, to understand how it works. +grep allows us to do more complex searches, for instance, searching for +sentences starting or ending with a particular pattern and regular +expression based searches. + +{{{ Show slide with, tr }}} + +``tr`` is a command that takes two sets of characters as parameters, and +replaces occurrences of the characters in the first set with the +corresponding elements from the other set. It reads from the standard +output and writes to the standard output. + +For instance, if we wish to replace all the lower case letters in the +students file with upper case, we can do it as, .. L12 -{{{ Switch to terminal }}} +{{{ Switch to the terminal }}} :: - for animal in rat cat dog man - do - echo $animal - done + cat students.txt | tr a-z A-Z .. R13 -We just wrote a list of animals, each name separated by a space -and then printed each name on a separate line. The variable ``animal`` is a -'dummy' or a 'loop variable'. It can then be used to refer to the element of -the list that is currently being dealt with. We could, obviously, use -something as lame as ``i`` in place of ``animal``. +A common task is to remove empty newlines from a file. The ``-s`` flag +causes ``tr`` to compress sequences of identical adjacent characters in its +output to a single token. For example, .. L13 +:: + + tr -s '\n' '\n' .. R14 -To generate a range of numbers and iterate over them, we do the following. +Hit enter 2-3 times and see that every time we hit enter we get a newline. .. L14 +:: -{{{ Open the script ``for-1.sh`` and show }}} + <Enter> + <Enter> .. R15 -Now, let us run the script and see what we get, +It replaces sequences of one or more newline characters with a single newline. -.. L15 +The ``-d`` flag causes ``tr`` to delete all tokens of the specified set of +characters from its input. In this case, only a single character set +argument is used. The following command removes carriage return characters, +thereby converting a file in DOS/Windows format to the Unix format. -{{{ Switch to terminal }}} +.. L15 :: - sh for-1.sh + cat foo.txt | tr -d '\r' > bar.txt .. R16 -Now, we use a ``for`` loop to list the files that we are interested in. +The ``-c`` flag complements the first set of characters. .. L16 - -{{{ Open the script ``for-2.sh`` and show }}} -{{{ Switch to terminal }}} :: - sh for-2.sh + tr -cd '[:alnum:]' .. R17 - -If the file-names contain spaces, ``for`` assumes, each word separated by a -space,to be a single item in the list and prints it in a separate line. We -could modify the script slightly to overcome this problem. -.. L17 +It therefore removes all non-alphanumeric characters. -{{{ Open the script ``for-3.sh`` and show }}} -{{{ Switch to terminal }}} +Let us consider one more scenario.Suppose we have a list of items, say books, +and we wish to obtain a list which names of all the books only once, without +any duplicates. To achieve this, we use the ``uniq`` command. Let us first +have a look at our file + +.. L17 :: - sh for-3.sh + cat items.txt .. R18 -Now, we have each file name printed on a separate line. The file names are -in the form ``dd - Name.mp3`` and it has to be changed to the format -``Name.mp3``. Also, if the name has spaces, we wish to replace it with -hyphens. +Now, let us try and get rid of the duplicate lines from this file using +the ``uniq`` command. .. L18 - -{{{ Open the script ``for-4.sh`` and show }}} -{{{ Switch to terminal }}} :: - sh for-4.sh + uniq items.txt .. R19 -Now, we simply replace the echo command with a ``mv`` command. +Nothing happens! Why? The ``uniq`` command removes duplicate lines only when +they are next to each other. So, henceforth, we get a sorted file from the +original file and work with that file. .. L19 - -{{{ Open the script ``for-5.sh`` and show }}} -{{{ Switch to terminal }}} :: - sh for-5.sh + sort items.txt | uniq .. R20 -We see that we get our required output. All the files have been renamed and -the spaces are removed. -Now let us move ahead with ``while`` loop. -The ``while`` command allows us to continuously execute a block of commands -until the command that is controlling the loop is executing successfully. +``uniq -u`` command gives the lines which are unique and do not have any +duplicates in the file. ``uniq -d`` outputs only those lines which +have duplicates. + +.. L20 +:: -.. L20 + uniq -u items-sorted.txt .. R21 -Let's start with the lamest example of a ''while'' loop. +The ``-c`` option displays the number of times each line occurs in the file. .. L21 - -{{{ Open the script ``while-1.sh`` and show }}} -{{{ Switch to terminal }}} :: - sh while-1.sh - -.. R22 - -This, as you can see, is an infinite loop that prints ``True``. - -Say, we wish to write a simple program that takes input from the user -and prints it back, until the input is ``quit``, which then quits the program. + uniq -dc items-sorted.txt .. L22 -{{{ Open the script ``while-2.sh`` and show }}} -{{{ Switch to terminal }}} -:: +{{{ Show summary slide }}} - sh while-2.sh +.. R22 + +This brings us to the end of the end of this tutorial. +In this tutorial, we have learnt to, + + 1. Use the ``sort`` command to sort lines of text files. + #. Use the ``grep`` command to search text pattern. + #. Use the ``tr`` command to translate and/or delete characters. + #. Use the ``uniq`` command to omit repeated lines in a text. .. L23 -{{{ Show slide, Environment Variables }}} +{{{ Show self assessment questions slide }}} .. R23 -'Environment variables' are a way of passing information from the shell to the -programs that are run in it. Standard UNIX variables are split into two -categories,'Environment variables' and 'Shell variables'. In broad terms, -'Shell variables' apply only to the current instance of the shell and are -used to set short-term working conditions; 'Environment variables' have a -farther reaching significance, and are set at login, valid for the duration of -the session. By convention, 'Environment variables' have UPPER CASE and 'Shell -variables' have lower case names. +Here are some self assessment questions for you to solve -You can see an example of environment variables in the slide. +1. To obtain patterns; one per line, which of the following command is used ? + + - grep -f + - grep -i + - grep -v + - grep -e -.. R24 +2. Translate the word 'linux' to upper-case. -To see all the variables and their values, we could use any of the -following, +3. Sort the output of the ``ls -al`` command. .. L24 -{{{ Switch to terminal }}} -:: - - printenv | less - env - -.. R25 - -We have looked at the 'PATH' variable, in the previous tutorial. We shall now -use the ``export`` command to change it's value. +{{{ Solution of self assessment questions on slide }}} -.. L25 -:: +.. R24 - export PATH=$PATH:$HOME/bin +And the answers, -.. R26 +1. In order to obtain patterns one per line, we use the ``grep`` command + alongwith the -f option. -Observe the difference in the value of 'PATH' variable before and after -modifying it. +2. We use the tr command to change the word into uppercase +:: -``export`` command is used to export a variable to the environment of all -the processes that are started from that shell. + echo 'linux' | tr a-z A-Z + -.. L26 +3. We use the sort command as, +:: + + ls -al | sort -n -k5 +The -n means "sort numerically", and the -k5 option means to key off of +column five. -.. L27 +.. L25 -{{{ Switch to 'Summary' slide }}} +{{{ Show the SDES & FOSSEE slide }}} -.. R27 +.. R25 -This brings us to the end of this tutorial. -In this tutorial, we have learnt to, - - 1. Prepare scripts using control structures like ``if``, ``if-else``, - ``for`` and ``while``. - 2. Use 'environment variables'. - 3. Export a variable to the environment of all the processes, using - the ``export`` command. +Software Development techniques for Engineers and Scientists - SDES, is an +initiative by FOSSEE. For more information, please visit the given link. -.. L28 +Free and Open-source Software for Science and Engineering Education - FOSSEE, is +based at IIT Bombay which is funded by MHRD as part of National Mission on +Education through ICT. -{{{ Show self assessment questions slide }}} +.. L26 -.. R28 +{{{ Show the ``About the Spoken Tutorial Project'' slide }}} -Here are some self assessment questions for you to solve: +.. R26 - 1. Print the text ``dog man`` in such a way that the prompt - continues after the text. +Watch the video available at the following link. It summarises the Spoken +Tutorial project.If you do not have good bandwidth, you can download and +watch it. - 2. How can you add a new path variable ``/data/myscripts`` to $PATH variable ? +.. L27 -.. L30 +{{{ Show the `` Spoken Tutorial Workshops'' slide }}} -{{{ Solutions of self assessment questions on slide }}} +.. R27 -.. R30 +The Spoken Tutorial Project Team conducts workshops using spoken tutorials, +gives certificates to those who pass an online test. -And the answers, +For more details, contact contact@spoken-tutorial.org - 1. We print the given text using the ``echo`` command by using an additional - option -n as, -:: +.. L28 - $echo -n dog man +{{{ Show the ``Acknowledgements'' slide }}} - 2. We can add a new path variable by using the export command as, - -:: +.. R28 - $export PATH=$PATH://data/myscripts +Spoken Tutorial Project is a part of the "Talk to a Teacher" project. +It is supported by the National Mission on Education through ICT, MHRD, +Government of India. More information on this mission is available at the +given link. -.. L31 +.. L29 {{{ Show the Thank you slide }}} -.. R31 +.. R29 Hope you have enjoyed this tutorial and found it useful. Thank you! - diff --git a/ult/ult_7/script2col.rst b/ult/ult_7/script2col.rst new file mode 100644 index 0000000..b15e85c --- /dev/null +++ b/ult/ult_7/script2col.rst @@ -0,0 +1,210 @@ +.. Objectives +.. ---------- + + .. At the end of this tutorial, you will be able to: + + .. 1. Sort lines of text files + .. 2. Print lines matching a pattern + .. 3. Translate or delete characters + .. 4. Omit repeated lines + + +.. Prerequisites +.. ------------- + +.. 1. Getting started with Linux +.. 2. Redirection and Piping + + + +Script +------ + + + ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ Show the first slide containing title, name of the production | Hello friends and Welcome to the tutorial on 'Text Processing'. | +| team along with the logo of MHRD }}} | | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ Show slide with objectives }}} | At the end of this tutorial, you will be able to, | +| | | +| | 1. Sort lines of text files | +| | #. Print lines matching a pattern | +| | #. Translate or delete characters | +| | #. Omit repeated lines. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ Switch to the pre-requisite slide }}} | Before beginning this tutorial,we would suggest you to complete the | +| | former tutorials as being displayed currently. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ Open the terminal }}} | In this tutorial, we shall learn about text processing. | +| :: | TO begin with, consider data kept in two files, namely marks1.txt and | +| | students.txt | +| cat marks1.txt | Let us see what data they contain. Open a terminal and type, | +| cat students.txt | | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| :: | Let's say we wish to sort the output in the alphabetical order | +| | of the names of the files. We can use the ``sort`` command for this | +| cut -d " " -f 2- marks1.txt | paste -d " " students.txt -| sort | purpose. | +| | | +| | We just pipe the previous output to the ``sort`` command as, | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| :: | Let's say we wish to sort the names, based on the marks in the first | +| | subject i.e. the first column after the name. ``sort`` command also allows us to | +| cut -d " " -f 2- marks1.txt | paste -d " " students.txt -| sort -t " " -k 2 | specify the delimiter between the fields and sort the data on a particular | +| | field. ``-t`` option is used to specify the delimiter and ``-k`` option | +| | is used to specify the field. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ Show slide with, Sort... }}} | This command give us a sorted output as required. But, what if we would | +| | like the output to appear in the reverse order. ``-r`` option allows the output | +| | to be sorted in the reverse order and the ``-n`` option is used to choose | +| | a numerical sorting. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ Switch to the terminal }}} | Let us do it on the terminal and see for ourselves, | +| :: | | +| | | +| cut -d " " -f 2- marks1.txt | paste -d " " students.txt -| | | +| sort -t " " -k 2 -rn | | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| :: | Suppose, While you are compiling the student marklist, Anne walks up to you and | +| | wants to know her marks. You, being a kind person that you are, oblige. | +| cut -d " " -f 2- marks1.txt | paste -d " " students.txt - | grep Anne | But you do not wish to her to see the marks that others have scored. What | +| | do you do? Here, the ``grep`` command comes to your rescue. | +| | | +| | ``grep`` is a command line text search utility. You can use it to search | +| | for Anne and show her, what she scored. ``grep`` allows us to search for a | +| | search string in files. But we could, like any other command, pipe the | +| | output of other commands to it. So, we shall use the previous combination | +| | of cut and paste that we had, to get the marks of students along with their | +| | names and search for Anne in that. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| :: | This will give us only the line containing the word Anne as the output. | +| | The grep command is by default case-sensitive. So, we wouldn't have got | +| cut -d " " -f 2- marks1.txt | paste -d " " students.txt - | grep -i Anne | the result if we had searched for anne, with a small a, instead of | +| | Anne, with a capital a. But, what if we didn't know, whether the name was | +| | capitalized or not? ``grep`` allows you to do case-insensitive searches | +| | by using the ``-i`` option. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| :: | Now, in another scenario, if we wished to print all the lines, which do | +| | not contain the word Anne, we could use the ``-v`` option. | +| cut -d " " -f 2- marks1.txt | paste -d " " students.txt - | grep -iv Anne | | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ Switch to the terminal }}} | grep allows us to do more complex searches, for instance, searching for | +| :: | sentences starting or ending with a particular pattern and regular | +| | expression based searches. | +| cat students.txt | tr a-z A-Z | | +| | {{{ Show slide with, tr }}} | +| | | +| | ``tr`` is a command that takes two sets of characters as parameters, and | +| | replaces occurrences of the characters in the first set with the | +| | corresponding elements from the other set. It reads from the standard | +| | output and writes to the standard output. | +| | | +| | For instance, if we wish to replace all the lower case letters in the | +| | students file with upper case, we can do it as, | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| :: | A common task is to remove empty newlines from a file. The ``-s`` flag | +| | causes ``tr`` to compress sequences of identical adjacent characters in its | +| tr -s '\n' '\n' | output to a single token. For example, | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| :: | Hit enter 2-3 times and see that every time we hit enter we get a newline. | +| | | +| <Enter> | | +| <Enter> | | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| :: | It replaces sequences of one or more newline characters with a single newline. | +| | | +| cat foo.txt | tr -d '\r' > bar.txt | The ``-d`` flag causes ``tr`` to delete all tokens of the specified set of | +| | characters from its input. In this case, only a single character set | +| | argument is used. The following command removes carriage return characters, | +| | thereby converting a file in DOS/Windows format to the Unix format. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| :: | The ``-c`` flag complements the first set of characters. | +| | | +| tr -cd '[:alnum:]' | | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| :: | It therefore removes all non-alphanumeric characters. | +| | | +| cat items.txt | Let us consider one more scenario.Suppose we have a list of items, say books, | +| | and we wish to obtain a list which names of all the books only once, without | +| | any duplicates. To achieve this, we use the ``uniq`` command. Let us first | +| | have a look at our file | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| :: | Now, let us try and get rid of the duplicate lines from this file using | +| | the ``uniq`` command. | +| uniq items.txt | | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| :: | Nothing happens! Why? The ``uniq`` command removes duplicate lines only when | +| | they are next to each other. So, henceforth, we get a sorted file from the | +| sort items.txt | uniq | original file and work with that file. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| :: | ``uniq -u`` command gives the lines which are unique and do not have any | +| | duplicates in the file. ``uniq -d`` outputs only those lines which | +| uniq -u items-sorted.txt | have duplicates. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| :: | The ``-c`` option displays the number of times each line occurs in the file. | +| | | +| uniq -dc items-sorted.txt | | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ Show summary slide }}} | This brings us to the end of the end of this tutorial. | +| | In this tutorial, we have learnt to, | +| | | +| | 1. Use the ``sort`` command to sort lines of text files. | +| | #. Use the ``grep`` command to search text pattern. | +| | #. Use the ``tr`` command to translate and/or delete characters. | +| | #. Use the ``uniq`` command to omit repeated lines in a text. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ Show self assessment questions slide }}} | Here are some self assessment questions for you to solve | +| | | +| | 1. To obtain patterns; one per line, which of the following command is used ? | +| | | +| | - grep -f | +| | - grep -i | +| | - grep -v | +| | - grep -e | +| | | +| | 2. Translate the word 'linux' to upper-case. | +| | | +| | 3. Sort the output of the ``ls -al`` command. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ Solution of self assessment questions on slide }}} | And the answers, | +| | | +| | 1. In order to obtain patterns one per line, we use the ``grep`` command | +| | alongwith the -f option. | +| | | +| | 2. We use the tr command to change the word into uppercase | +| | :: | +| | | +| | echo 'linux' | tr a-z A-Z | +| | | +| | | +| | 3. We use the sort command as, | +| | :: | +| | | +| | ls -al | sort -n -k5 | +| | The -n means "sort numerically", and the -k5 option means to key off of | +| | column five. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ Show the SDES & FOSSEE slide }}} | Software Development techniques for Engineers and Scientists - SDES, is an | +| | initiative by FOSSEE. For more information, please visit the given link. | +| | | +| | Free and Open-source Software for Science and Engineering Education - FOSSEE, is | +| | based at IIT Bombay which is funded by MHRD as part of National Mission on | +| | Education through ICT. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ Show the ``About the Spoken Tutorial Project'' slide }}} | Watch the video available at the following link. It summarises the Spoken | +| | Tutorial project.If you do not have good bandwidth, you can download and | +| | watch it. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ Show the `` Spoken Tutorial Workshops'' slide }}} | The Spoken Tutorial Project Team conducts workshops using spoken tutorials, | +| | gives certificates to those who pass an online test. | +| | | +| | For more details, contact contact@spoken-tutorial.org | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ Show the ``Acknowledgements'' slide }}} | Spoken Tutorial Project is a part of the "Talk to a Teacher" project. | +| | It is supported by the National Mission on Education through ICT, MHRD, | +| | Government of India. More information on this mission is available at the | +| | given link. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ Show the Thank you slide }}} | Hope you have enjoyed this tutorial and found it useful. | +| | Thank you! | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ diff --git a/ult/ult_7/sign.sh b/ult/ult_7/sign.sh deleted file mode 100644 index 246150d..0000000 --- a/ult/ult_7/sign.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -if test $1 -lt 0 -then - echo "number is negative" -else - echo "number is non-negative" -fi diff --git a/ult/ult_7/society.mp3 b/ult/ult_7/society.mp3 deleted file mode 100644 index e69de29..0000000 --- a/ult/ult_7/society.mp3 +++ /dev/null diff --git a/ult/ult_6/students.txt b/ult/ult_7/students.txt index ddacd6b..ddacd6b 100644 --- a/ult/ult_6/students.txt +++ b/ult/ult_7/students.txt diff --git a/ult/ult_7/ult7.tex b/ult/ult_7/ult7.tex index a306272..3d981a6 100644 --- a/ult/ult_7/ult7.tex +++ b/ult/ult_7/ult7.tex @@ -5,142 +5,120 @@ % Copyright (c) 2009, FOSSEE, IIT Bombay %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\documentclass[12pt,compress]{beamer} - +\documentclass[17pt,compress]{beamer} +\usepackage{beamerthemesplit} \mode<presentation> { \usetheme{Warsaw} \useoutertheme{infolines} \setbeamercovered{transparent} + \setbeamertemplate{navigation symbols}{} } +% Taken from Fernando's slides. +\usepackage{ae,aecompl} +\usepackage[scaled=.95]{helvet} \usepackage[english]{babel} \usepackage[latin1]{inputenc} -%\usepackage{times} \usepackage[T1]{fontenc} -% Taken from Fernando's slides. -\usepackage{ae,aecompl} -\usepackage{mathpazo,courier,euler} -\usepackage[scaled=.95]{helvet} - -\definecolor{darkgreen}{rgb}{0,0.5,0} +% change the alerted colour to LimeGreen +\definecolor{LimeGreen}{RGB}{50,205,50} +\setbeamercolor{structure}{fg=LimeGreen} +\author[FOSSEE]{} +\institute[IIT Bombay]{} +\date[]{} +% \setbeamercovered{transparent} + +% theme split +\usepackage{verbatim} +\newenvironment{colorverbatim}[1][]% +{% +\color{blue} +\verbatim +}% +{% +\endverbatim +}% +\usepackage{mathpazo,courier,euler} \usepackage{listings} \lstset{language=sh, basicstyle=\ttfamily\bfseries, - commentstyle=\color{red}\itshape, - stringstyle=\color{darkgreen}, showstringspaces=false, - keywordstyle=\color{blue}\bfseries} + keywordstyle=\color{black}\bfseries} +% logo +\logo{\includegraphics[height=1.30 cm]{../images/3t-logo.pdf}} +\logo{\includegraphics[height=1.30 cm]{../images/fossee-logo.pdf} + +\hspace{7.5cm} +\includegraphics[scale=0.99]{../images/fossee-logo.pdf}\\ +\hspace{281pt} +\includegraphics[scale=0.80]{../images/3t-logo.pdf}} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % DOCUMENT STARTS \begin{document} -\begin{frame} +\sffamily \bfseries +\title +[Text Processing] +{Text Processing} +\author +[FOSSEE] +{\small Talk to a Teacher\\{\color{blue}\url{http://spoken-tutorial.org}}\\\vspace{0.25cm}National Mission on Education + through ICT\\{\color{blue}\url{ http://sakshat.ac.in}} \\ [1.65cm] + Contributed by FOSSEE Team \\IIT Bombay \\[0.3cm] +} -\begin{center} -\vspace{12pt} -\textcolor{blue}{\huge Using Linux Tools\\Part VII} -\end{center} -\vspace{18pt} -\begin{center} -\vspace{10pt} -\includegraphics[scale=0.95]{../images/fossee-logo.png}\\ -\vspace{5pt} -\scriptsize Developed by FOSSEE Team, IIT-Bombay. \\ -\scriptsize Funded by National Mission on Education through ICT\\ -\scriptsize MHRD,Govt. of India\\ -\includegraphics[scale=0.30]{../images/iitb-logo.png}\\ -\end{center} +% slide 1 +\begin{frame} + \titlepage \end{frame} + \begin{frame} \frametitle{Objectives} \label{sec-2} At the end of this tutorial, you will be able to, \begin{itemize} -\item Prepare scripts using 'Control Operators'. -\item Understand what 'Environment Variables' are. +\item Sort lines of text files +\item Print lines matching a pattern +\item Translate or delete characters +\item Omit repeated lines \end{itemize} \end{frame} \begin{frame} -\frametitle{Pre-requisite} +\frametitle{Pre-requisites} \label{sec-3} -Spoken tutorial on - +Spoken tutorial on, \begin{itemize} -\item Using Linux tools -- Part I -\item Using Linux tools -- Part II -\item Using Linux tools -- Part III -\item Using Linux tools -- Part IV -\item Using Linux tools -- Part V -\item Using Linux tools -- Part VI +\item Getting started with Linux +\item Redirection and Piping \end{itemize} \end{frame} \begin{frame}[fragile] - \frametitle{\texttt{if}} - \begin{itemize} - \item Print message if directory exists in \texttt{pwd} - \end{itemize} - \begin{lstlisting} - #!/bin/bash - if test -d $1 - then - echo "Yes, the directory" \ - $1 "is present" - fi - \end{lstlisting} % $ -\end{frame} - -\begin{frame}[fragile] - \frametitle{\texttt{[ ]} - alias for \texttt{test}} - \begin{itemize} - \item Square brackets (\texttt{[]}) can be used instead of - \texttt{test} - \item - \end{itemize} - \begin{lstlisting} - #!/bin/bash - if [ $1 -lt 0 ] - then - echo "number is negative" - else - echo "number is non-negative" - fi - \end{lstlisting} % $ + \frametitle{\texttt{sort}} +\verb~$ cut -d " " -f 2- marks1.txt \~ +\verb~| paste -d " " students.txt -\~ +\verb~| sort -t " " -k 2 -rn~ \begin{itemize} - \item \alert{spacing is important, when using the square brackets} + \item \texttt{-t} the delimiter between fields + \item \texttt{-k} field to use for sorting + \item \texttt{-r} for sorting in the reverse order + \item \texttt{-n} to choose numerical sorting \end{itemize} \end{frame} \begin{frame}[fragile] - \frametitle{\texttt{for}} - \begin{block}{Problem} - Given a set of \texttt{.mp3} files, that have names beginning with - numbers followed by their names --- \texttt{08 - Society.mp3} --- - rename the files to have just the names. Also replace any spaces - in the name with hyphens. - \end{block} + \frametitle{\texttt{tr}} \begin{itemize} - \item Loop over the list of files - \item Process the names, to get new names - \item Rename the files - \end{itemize} -\end{frame} - -\begin{frame}[fragile] - \frametitle{Environment Variables} - \begin{itemize} - \item Pass information from shell to programs running in it - \item Behavior of programs can change based on values of variables - \item Environment variables vs. Shell variables - \item Shell variables -- only current instance of the shell - \item Environment variables -- valid for the whole session - \item Convention -- environment variables are UPPER CASE + \item Translates or deletes characters + \item Reads from \texttt{stdin} and outputs to \texttt{stdout} + \item Given, two sets of characters, replaces one with other \end{itemize} \end{frame} @@ -152,51 +130,120 @@ Spoken tutorial on - \begin{itemize} -\item Prepare scripts using control structures like ``if'', ``if-else'', - ``for'' and ``while''. -\item Use 'environment variables'. -\item Export a variable to the environment of all the processes, using - the ``export'' command. +\item Use the ``sort'' command to sort lines of text files +\item Use the ``grep'' command to search text pattern +\end{itemize} +\end{frame} + +\begin{frame} +\frametitle{Summary..} +\begin{itemize} +\item Use the ``tr'' command to translate and/or delete characters +\item Use the ``uniq'' command to omit repeated lines in a text \end{itemize} \end{frame} + \begin{frame}[fragile] \frametitle{Evaluation} \label{sec-9} \begin{enumerate} -\item Print the text ``dog man'' in such a way that the prompt - continues after the text. +\item To obtain patterns; one per line, which of the following command is used ? +\vspace{3pt} +\begin{itemize} +\item grep -f +\item grep -i +\item grep -v +\item grep -e +\end{itemize} +\end{enumerate} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Evaluation..} +\begin{enumerate} +\setcounter{enumi}{1} +\item Translate the word `linux' to upper-case. \vspace{8pt} -\item How can you add a new path variable ``/data/myscripts'' to \$PATH variable ? +\item Sort the output of the ``ls -al'' command. \end{enumerate} \end{frame} + \begin{frame} \frametitle{Solutions} \label{sec-10} \begin{enumerate} -\item \$ echo -n dog man +\item grep -f +\vspace{15pt} +\item \$ echo `linux' | tr a-z A-Z \vspace{15pt} -\item \$ export PATH=\$PATH://data/myscripts +\item \$ ls -al | sort -n -k5 \end{enumerate} \end{frame} + +\begin{frame} +\frametitle{SDES \& FOSSEE} +\begin{center} +\begin{itemize} +\item \small{SDES}\\ +\small{\color{LimeGreen}Software Development techniques for Engineers and Scientists} \\ +\scriptsize An initiative by FOSSEE. \\ +\vspace{3pt} +\scriptsize For more information on SDES, please visit {\color{blue}\url{http://fossee.in/sdes}}\\ +\vspace{10pt} +\item \small{FOSSEE}\\ +\small {\color{LimeGreen}Free and Open-source Software for \\Science and Engineering Education} \\ +\scriptsize Based at IIT Bombay, Funded by MHRD.\\ +\vspace{3pt} +\scriptsize Part of National Mission on Education through ICT \\(NME-ICT) \\ +\end{itemize} +\end{center} +\end{frame} + +\begin{frame} +\frametitle{About the Spoken Tutorial Project} +\begin{itemize} +\item Watch the video available at {\color{blue}\url{http://spoken-tutorial.org /What\_is\_a\_Spoken\_Tutorial}} +\item It summarises the Spoken Tutorial project +\item If you do not have good bandwidth, you can download and watch it +\end{itemize} +\end{frame} + +\begin{frame} +\frametitle{Spoken Tutorial Workshops}The Spoken Tutorial Project Team +\begin{itemize} +\item Conducts workshops using spoken tutorials +\item Gives certificates to those who pass an online test +\item For more details, please write to \\ \hspace {0.5cm}{\color{blue}contact@spoken-tutorial.org} +\end{itemize} +\end{frame} + +\begin{frame} +\frametitle{Acknowledgements} +\begin{itemize} +\item Spoken Tutorial Project is a part of the Talk to a Teacher project +\item It is supported by the National Mission on Education through ICT, MHRD, Government of India +\item More information on this Mission is available at: \\{\color{blue}\url{http://spoken-tutorial.org/NMEICT-Intro}} +\end{itemize} +\end{frame} + \begin{frame} \begin{block}{} \begin{center} - \textcolor{blue}{\Large THANK YOU!} + {\Large THANK YOU!} \end{center} \end{block} \begin{block}{} \begin{center} For more Information, visit our website\\ - \url{http://fossee.in/} + {\color{blue}\url{http://fossee.in/}} \end{center} \end{block} \end{frame} -\end{document} - +\end{document} diff --git a/ult/ult_7/while-1.sh b/ult/ult_7/while-1.sh deleted file mode 100644 index 485e167..0000000 --- a/ult/ult_7/while-1.sh +++ /dev/null @@ -1,4 +0,0 @@ -while true -do - echo "True" -done diff --git a/ult/ult_7/while-2.sh b/ult/ult_7/while-2.sh deleted file mode 100644 index 5fbdd11..0000000 --- a/ult/ult_7/while-2.sh +++ /dev/null @@ -1,7 +0,0 @@ -while [ "$variable" != "quit" ] -do - read variable - echo "Input - $variable" -done -exit 0 - diff --git a/ult/ult_8/script.rst b/ult/ult_8/script.rst deleted file mode 100644 index ca2c5ec..0000000 --- a/ult/ult_8/script.rst +++ /dev/null @@ -1,339 +0,0 @@ -.. Objectives -.. ---------- - - .. At the end of this tutorial, you will be able to: - - .. 1. - .. 2. - -.. Prerequisites -.. ------------- - -.. 1. Using Linux tools - Part 1 -.. 2. Using Linux tools - Part 2 -.. 3. Using Linux tools - Part 3 -.. 4. Using Linux tools - Part 4 -.. 5. Using Linux tools - Part 5 -.. 6. Using Linux tools - Part 6 -.. 7. Using Linux tools - Part 7 - - -Script ------- - -.. L1 - -{{{ Show the first slide containing title, name of the production -team along with the logo of MHRD }}} - -.. R1 - -Hello friends and Welcome to the tutorial on -'Using linux tools - Part 8'. - -.. L2 - -{{{ Show slide with objectives }}} - -.. R2 - -At the end of this tutorial, you will be able to, - - 1. Search for files in many different ways. - #. Compare files with same names. - #. Create and extract an archive. - #. Customize a shell. - -.. L3 - -{{{ Switch to the pre-requisite slide }}} - -.. R3 - -Before beginning this tutorial,we would suggest you to complete the -tutorial on "Using Linux tools from Part 1 to Part 7". - -There are a bunch of tools, that will prove to be handy in your day -to day work. These tools will help you quickly perform tasks like searching -for files, comparing files and checking if they are the same, viewing the -exact differences between them, etc. - -.. L4 - -{{{ Show slide, find }}} - -.. R4 - -Let us start with the first tool - 'find' . -The ``find`` command lets you find files in a directory hierarchy. It -offers a very complex feature set allowing you to search for files with a -wide range of restrictions. We shall only look at some of the most -frequently used ones. - -.. R5 - -To find the files, which end with an extension, ``.pdf``, saved in the current -folder and all it's subfolders, we say - -.. L5 - -{{{ Open the terminal }}} -:: - - find . -name "*.pdf" - -.. R6 - -The ``find`` command also lists out the directory and sub-directory names -To list them, we say, - -.. L6 -:: - - find . -type d - -.. R7 - -In short, ``find`` allows you to set limits on file-size, modification time -and whole lot of other things which you can explore on seeing the man page -of ``find``. - -.. L7 - -.. R8 - -Let us now move on to the next tool, the compare tool. - -To compare two files, whether they are identical or not, we can use the -``cmp`` command. Let us consider some situation. Suppose, we run the ``find`` -command to locate some file, and it turns out that we have a file with same -name in different location. - -In this case, if we are unsure, whether both the files are the same, we can use -the ``cmp`` command to check if the files are identical. - -.. L8 -:: - - find . -name quick.c - ./Desktop/programs/quick.c - ./c-folder/quick.c - cmp Desktop/programs/quick.c c-folder/quick.c - -.. L9 - -{{{ Show slide, cmp }}} - -.. R9 - -If the cmp command doesn't return any output, it means that both files are -exactly identical. If there are any differences in the file, it gives you -the exact byte location at which the first difference occurred. - -.. R10 - -Let us now make a small change in one of quick.c file and run the ``cmp`` -command again. - -.. L10 -{{{ Switch to the terminal }}} - -:: - - cmp Desktop/programs/quick.c c-folder/quick.c - -.. R11 - -As we can see, it gives the exact location as to where a change is made. - -Now, we may not be happy with just the knowledge that the files are -different. We may want to see the exact differences between the two files. -The ``diff`` command can be used to find the exact differences between the -files. - -.. L11 - -.. L12 -:: - - diff Desktop/programs/quick.c c-folder/quick.c - -.. R12 - -We get back a line by line difference between the two files. - -.. L13 - -{{{ Show slide, diff }}} - -.. R13 - -The ``>`` mark indicates the content that has been added to the second file, -which was not present in the first file. The ``<`` mark indicates the lines -that were present in the first file, but are not existent in the second file. - -.. L14 - -{{{ Show slide, tar }}} - -.. R14 - -You would often come across (archive) files which are called *tarballs*. A -tar ball is essentially a collection of files, which may or may not be -compressed. Essentially, it eases the job of storing, backing up and -transporting multiple files, at once. - -.. R15 - -The following set of commands extracts the contents of the ``allfiles.tar`` -tarball to the directory extract. - -.. L15 - -{{{ Switch to terminal }}} -:: - - mkdir extract - cp allfiles.tar extract/ - cd extract - tar -xvf allfiles.tar - -.. L16 - -{{{ Show slide, extracting an archive }}} - -.. R16 - -The option, ``x`` tells ``tar`` to extract the files in the archive file -specified by the ``f`` option. The ``v`` option tells ``tar`` to give out a -verbose output. - -.. R17 - -Similarly, if we wish to create a ``tar`` archive, we use the ``c`` option -instead of the ``x`` option. For instance, the command below creates an -archive from all the files with the ``.txt`` extension. - -.. L17 - -{{{ Switch to terminal }}} -:: - - tar -cvzf newarchive.tar *.txt - -.. R18 - -You can also create and extract compressed archives using ``tar``. It -supports a wide variety of compressions like gzip, bzip2, lzma, etc. - -We need to add an additional option to ``tar`` to handle these -compressions. - - -+-------------+------------+ -| Compression | Option | -+-------------+------------+ -| gzip | ``-z`` | -| bzip2 | ``-j`` | -| lzma | ``--lzma`` | -+-------------+------------+ - -.. L18 - -.. R19 - -So, if we wished to create a gzip archive in the previous command, we -change it to the following - -.. L19 -:: - - tar -cvzf newarchive.tar.gz *.txt - -.. L20 - -{{{ Show slide, customizing your shell }}} - -.. R20 - -What would you do, if you want bash to execute a particular command each -time you start it up? For instance, say you want the current directory to -be your Desktop instead of your home folder, each time bash starts up. -Bash reads and executes commands in a whole bunch -of files called start-up files, when it starts up. - -When bash starts up as an interactive login shell, it reads the files -``/etc/profile``, ``~/.bash_profile``, ``~/.bash_login``, and -``~/.profile`` in that order. - -When an interactive shell that is not a login shell is started, bash reads -and executes commands from ~/.bashrc. This can be prevented using the ``--norc`` -option. Instead of using the ``~/.bashrc`` file on start-up, we can force -the bash to use another file, for which the ``--rcfile`` option may be used. - -Now, you know what you should do, to change the current directory to you -Desktop. Just put a ``cd ~/Desktop`` into your ``~/.bashrc`` and you are -set! -But as you know that the start-up files are used for a lot more complex things -than this. You could set (or unset) aliases and a whole bunch of environment -variables in the ``.bashrc``, like changing environment variables etc. - -.. L21 - -{{{ Switch to 'Summary' slide }}} - -.. R21 - -This brings us to the end of the end of this tutorial. -In this tutorial, we have learnt to, - - 1. Make use of the ``find`` command to find files in a directory hierarchy. - #. Find the differences between files with the same name, using the - ``cmp`` and ``diff`` commands. - #. Extract and create compressed archive's using the ``tar`` command. - #. Customize one's shell according to one's choice. - -.. L22 - -{{{ Show self assessment questions slide }}} - -.. R22 - -Here are some self assessment questions for you to solve - - 1. Look at the man page of ``find`` and state the options which - deal with symbolic links. - - 2. How do you append tar files to an archive? - -.. L23 - -{{{ Solution of self assessment questions on slide }}} - -.. R23 - -And the answers, - -1. The -H, -L and -P options with the ``find`` command control - the treatment of symbolic links. - - 2. To append tar files to an archive, we can use the ``tar`` command - either with the ``-A`` option or the ``-r`` option, as, -:: - - $ tar -Af <tar_file> <tar_file_to_be_added> - OR - $ tar -rf <tar_file> <tar_file_to_be_added> - - -.. L24 - -{{{ Show the Thank you slide }}} - -.. R24 - -Hope you have enjoyed this tutorial and found it useful. -Thank you! - - - diff --git a/ult/ult_8/ult8.tex b/ult/ult_8/ult8.tex deleted file mode 100644 index a34bf53..0000000 --- a/ult/ult_8/ult8.tex +++ /dev/null @@ -1,248 +0,0 @@ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Using Linux Tools -% -% Author: FOSSEE -% Copyright (c) 2009, FOSSEE, IIT Bombay -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -\documentclass[12pt,compress]{beamer} - -\mode<presentation> -{ - \usetheme{Warsaw} - \useoutertheme{infolines} - \setbeamercovered{transparent} -} - -\usepackage[english]{babel} -\usepackage[latin1]{inputenc} -%\usepackage{times} -\usepackage[T1]{fontenc} - -% Taken from Fernando's slides. -\usepackage{ae,aecompl} -\usepackage{mathpazo,courier,euler} -\usepackage[scaled=.95]{helvet} - -\definecolor{darkgreen}{rgb}{0,0.5,0} - -\usepackage{listings} -\lstset{language=sh, - basicstyle=\ttfamily\bfseries, - commentstyle=\color{red}\itshape, - stringstyle=\color{darkgreen}, - showstringspaces=false, - keywordstyle=\color{blue}\bfseries} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% DOCUMENT STARTS -\begin{document} - -\begin{frame} - -\begin{center} -\vspace{12pt} -\textcolor{blue}{\huge Using Linux Tools} -\end{center} -\vspace{18pt} -\begin{center} -\vspace{10pt} -\includegraphics[scale=0.95]{../images/fossee-logo.png}\\ -\vspace{5pt} -\scriptsize Developed by FOSSEE Team, IIT-Bombay. \\ -\scriptsize Funded by National Mission on Education through ICT\\ -\scriptsize MHRD,Govt. of India\\ -\includegraphics[scale=0.30]{../images/iitb-logo.png}\\ -\end{center} -\end{frame} -\begin{frame} -\frametitle{Objectives} -\label{sec-2} - -At the end of this tutorial, you will be able to, -\begin{itemize} -\item Search for files in many different ways. -\item Compare files with same names. -\item Create and extract an archive. -\item Customize a shell. -\end{itemize} -\end{frame} - -\begin{frame} -\frametitle{Pre-requisite} -\label{sec-3} - -Spoken tutorial on - -\begin{itemize} -\item Using Linux tools -- Part I -\item Using Linux tools -- Part II -\item Using Linux tools -- Part III -\item Using Linux tools -- Part IV -\item Using Linux tools -- Part V -\item Using Linux tools -- Part VI -\item Using Linux tools -- Part VII -\end{itemize} -\end{frame} - -\begin{frame}[fragile] - \frametitle{\texttt{`find'}} - \begin{itemize} - \item `find' command helps to find files in a directory hierarchy - \item Offers a very complex feature set\\ For eg: search files by name, owner, date,etc. - \item Look at the \texttt{man} page of `find' - \end{itemize} -\end{frame} - -\begin{frame}[fragile] - \frametitle{\texttt{`cmp'}} - \begin{itemize} - \item Compare two files - \end{itemize} - \begin{lstlisting} - $ find . -name quick.c - ./Desktop/programs/quick.c - ./c-folder/quick.c - $ cmp Desktop/programs/quick.c \ - c-folder/quick.c - \end{lstlisting} % $ - \begin{itemize} - \item No output when the files are exactly the same - \item Else, gives location where the first difference occurs - \end{itemize} -\end{frame} - -\begin{frame}[fragile] - \frametitle{\texttt{`diff'}} - \begin{itemize} - \item We know the files are different, but want exact differences - \end{itemize} - \begin{lstlisting} - $ diff Desktop/programs/quick.c \ - c-folder/quick.c - \end{lstlisting} % $ - \begin{itemize} - \item line by line difference between files - \item \texttt{>} indicates content only in second file - \item \texttt{<} indicates content only in first file - \end{itemize} -\end{frame} - -\begin{frame}[fragile] -\frametitle{\texttt{`tar'}} -\begin{itemize} -\item \emph{tarball} -- essentially a collection of files -\item May or may not be compressed -\item Eases the job of storing, backing-up \& transporting files -\end{itemize} -\end{frame} - -\begin{frame}[fragile] -\frametitle{Extracting an archive} - -\begin{lstlisting} -$ mkdir extract -$ cp allfiles.tar extract/ -$ cd extract -$ tar -xvf allfiles.tar -\end{lstlisting} %$ - -\begin{itemize} -\item \texttt{-x} --- Extract files within the archive -\item \texttt{-f} --- Specify the archive file -\item \texttt{-v} --- Be verbose -\end{itemize} -\end{frame} - -\begin{frame}[fragile] - \frametitle{Compressed archives} - \begin{itemize} - \item \texttt{tar} can create and extract compressed archives - \item Supports compressions like gzip, bzip2, lzma, etc. - \item Additional option to handle compressed archives - \begin{center} - \begin{tabular}{|l|l|}\hline - Compression & Option \\\hline - gzip & \texttt{-z} \\\hline - bzip2 & \texttt{-j} \\\hline - lzma & \texttt{-{}-lzma} \\\hline - \end{tabular} - \end{center} - \end{itemize} - \begin{lstlisting} - $ tar -cvzf newarchive.tar.gz *.txt - \end{lstlisting} % $ -\end{frame} - - -\begin{frame} -\frametitle{Customizing your shell} -\begin{itemize} -\item Bash reads \texttt{/etc/profile}, - \texttt{\textasciitilde{}/.bash\_profile}, - \texttt{\textasciitilde{}/.bash\_login}, and - \texttt{\textasciitilde{}/.profile} in that order, when starting - up as a login shell. -\item \texttt{\textasciitilde{}/.bashrc} is read, when not a login - shell -\item Put any commands that you want to run when bash starts, in this - file. -\end{itemize} -\end{frame} - - -\begin{frame} -\frametitle{Summary} -\label{sec-8} - - In this tutorial, we have learnt to, - - -\begin{itemize} -\item To make use of the ``find'' command find files in a directory hierarchy. -\item To find the differences between files with the same name, using the - ``cmp'' and ``diff'' commands. -\item To extract and create compressed archive's using the ``tar'' command. -\item Customize one's shell according to one's choice. -\end{itemize} -\end{frame} -\begin{frame}[fragile] -\frametitle{Evaluation} -\label{sec-9} - - -\begin{enumerate} -\item Look at the man page of ``find'' and state the options which - deal with symbolic links. -\vspace{8pt} -\item How do you append tar files to an archive ? -\end{enumerate} -\end{frame} -\begin{frame} -\frametitle{Solutions} - -\begin{enumerate} -\item -H, -L and -P options with the ``find'' command -\vspace{15pt} -\item tar -Af <tar\_file> <tar\_file\_to\_be\_added> -\end{enumerate} - -\end{frame} -\begin{frame} - - \begin{block}{} - \begin{center} - \textcolor{blue}{\Large THANK YOU!} - \end{center} - \end{block} -\begin{block}{} - \begin{center} - For more Information, visit our website\\ - \url{http://fossee.in/} - \end{center} - \end{block} -\end{frame} - -\end{document} - - - |