Page MenuHomec4science

document.tex
No OneTemporary

File Metadata

Created
Sat, May 11, 16:19

document.tex

\note{
##Course duration
0.5 day
##Description
The goal of this course is to give the basis on the usage of a Linux system in
order for the user to be able to use the general purpose clusters, and to feel
at ease like a penguin in cold water.
##Contents:
- Overview of Linux
- Connecting to a remote machine (from Linux, Windows or Mac)
- Using a Linux/Unix system with only the command line
- Basics on file organization
- Common shell commands
- Writing a shell script
##Prerequisites:
Participants are asked to bring their laptop in order for the training to be
personalized to their specific environment.
}
\begin{frame}
\begin{minipage}{0.3\textwidth}
\centering
\includegraphics[width=3cm]{images/Tux}
\end{minipage}
\begin{minipage}{0.5\textwidth}
\titlepage
\centering
\url{https://c4science.ch/u/linux}
\end{minipage}
\end{frame}
\section{Overview of Linux}
\begin{frame}{What is Linux}
\begin{minipage}{0.7\linewidth}
\begin{block}{Just for fun}
\begin{itemize}
\item 1991 Linus Torvalds starts Linux ``for fun''
\item \emph{``I'm doing a (free) operating system (just a hobby, won't be big and professional like gnu) for 386(486) AT clones.''}
\end{itemize}
\end{block}
\end{minipage}
\hspace*{0.5ex}
\begin{minipage}{0.25\linewidth}
\centering
\vspace*{1.2ex}
\includegraphics[clip=true, trim=0 50px 0 30px,width=\linewidth]{images/220px-Linus_Torvalds}
\end{minipage}
\hspace*{0.5ex}
\begin{block}{What is a Linux distribution}
\begin{itemize}
\item Linux Kernel + softwares
\item Desktop distributions: windowing system (X11, Wayland) + desktop manager
(GNOME, KDE), package manager, service manager
\item Common distributions: Debian, Ubuntu, Redhat, Arch, ...
\end{itemize}
\end{block}
\end{frame}
\begin{frame}{What is Linux}
\begin{minipage}{0.25\linewidth}
\centering
\includegraphics[width=4.0\textwidth]{images/linux-distrib}
\end{minipage}
\end{frame}
\begin{frame}{Where can you find Linux}
\begin{minipage}{0.45\linewidth}
\begin{block}{Supercomputers}
\centering
\includegraphics[width=\linewidth]{images/top_500_2018}
\end{block}
\end{minipage}
\hspace*{2ex}
\begin{minipage}{0.45\linewidth}
\begin{block}{Smartphones}
\centering
\includegraphics[width=\linewidth]{images/smartphones_2018}
\end{block}
\end{minipage}
\begin{block}{Other numbers}
\begin{itemize}
\item Desktop: 2.21\%
\item Servers (web): 66\%
\item Servers (mainframe): 28\%
\item Embedded: 29.44\%
\end{itemize}
\end{block}
\end{frame}
\section{Login}
\begin{frame}{Login}
\begin{block}{First step: get a shell}
\begin{itemize}
\item Shell: user interface to the operating system's services
\item Start a shell on your local machine
\item Connect to a remote machine to get a shell
\item SSH: Secure SHell
\end{itemize}
\end{block}
\vspace{2ex}
\begin{minipage}{.45\linewidth}
\begin{block}{Windows}
\begin{itemize}
\item \href{https://git-scm.com/downloads}{Git Bash}
\end{itemize}
\end{block}
\end{minipage}
\hspace*{4.5ex}
\begin{minipage}{.45\linewidth}
\begin{block}{Linux/OSX}
\begin{itemize}
\item Start a terminal
\end{itemize}
\end{block}
\end{minipage}
\end{frame}
\begin{frame}{Login}
\begin{block}{Terminal}
\centering
\begin{tikzonimage}[scale=1.2]{images/terminal}
\draw[thick, red] (0.8cm, 5.1cm) --
(0.8cm, 4.8cm) --
(3.8cm, 4.8cm) --
(3.8cm, 5.1cm) -- cycle;
\node (host) at (3cm, 4.55cm) {};
\node[red] (hostname) at (3.5cm, 2.5cm) {\code{ssh -l $<$username$>$ $<$hostname$>$}};
\path[-latex, thick, red] (hostname) edge [bend left] (host);
\end{tikzonimage}
\end{block}
\end{frame}
\begin{frame}{Some usefull commands}
\begin{block}{}
\centering
\begin{tabular}{r|l}
\code{ls} & list files\\
\code{cd} & change directory\\
\code{pwd} & path of the current directory\\
& \\
\code{man} & get help on commands\\
\code{apropos} & search for a command and print a brief description\\
\code{echo} & print the arguments in the terminal \\
\end{tabular}
\end{block}
\end{frame}
\begin{exo}{First commands}
\begin{extrainfos}
List of usefull commands:
\vspace{1ex}
\begin{tabular}{r|l}
\code{ls} & list files\\
\code{cd} & change directory\\
\code{pwd} & path of the current \\
\code{man} & get help on commands\\
\code{apropos} & search for a command and print a brief description\\
\code{echo} & print the arguments in the terminal \\
\end{tabular}
\end{extrainfos}
\begin{questions}
\item Connect to the remote machine \code{scitascours1.epfl.ch}.
\item Check your current folder and your files.
\item Check the help of \code{ls} (\texttt{Q} to quit).
\end{questions}
\begin{block}<2->{}
\begin{command}
> pwd
> ls%
\end{command}
\end{block}
\begin{block}<3->{}
\begin{command}
> man ls%
\end{command}
\end{block}
\end{exo}
\section{File-system}
\begin{frame}{File structure}
\begin{block}{``On UNIX everything is a file''}
\begin{tabular}{rl}
\textbf{Directories} & files that are lists of other files\\
\textbf{Special files} & files for input/output mechanisms\\
\textbf{Links} & way to make files visible in different parts\\
& of the file system\\
\textbf{Sockets,} & way to communicate between processes\\
\textbf{named pipes} & \\
\end{tabular}
\end{block}
\end{frame}
\begin{frame}{File structure}
\begin{block}{Standard directories}
\begin{tabular}{ll}
\textbf{/etc} & System configurations files\\
\textbf{/boot} & Boot files, kernel and boot loader\\
\textbf{/home} & User accounts\\
\textbf{/usr} & Software, libraries, documentations, for user programs \\
\textbf{/var} & Variables files such as log files, mail queues, databases \\
\textbf{/opt} & Third-party and extra softwares\\
\end{tabular}
\end{block}
\begin{block}{Virtual directories}
\begin{tabular}{ll}
\textbf{/dev} & Peripheral hardware related files \\
\textbf{/proc} & Informations about processes\\
\textbf{/sys} & Informations about the kernel\\
\end{tabular}
\end{block}
\end{frame}
\begin{frame}{Tree view}
\begin{block}{}
\centering
\begin{tikzpicture}[every node/.style=draw=black,thick,anchor=west,text depth=.5ex,text height=2.2ex]
\node {/}
child { node {etc/}}
child { node {usr/}
child { node {bin/}}
child { node {lib/}}
}
child [missing] {}
child { node {home/}
child { node (a) {user1/}
child { node {Download/}}
child [missing] {}
child { node (b) {Desktop/}}
}
child [missing] {}
child { node {user2/}}
};
\end{tikzpicture}
\end{block}
\end{frame}
\begin{exo}{Directory structure}
\begin{questions}
\item Show directory structure under the root folder
\item Change directory to the root folder and list the content
\end{questions}
\begin{block}<2->{}
\begin{command}
> ls /%
\end{command}
\end{block}
\begin{block}<3->{}
\begin{command}
> cd /
> ls%
\end{command}
\end{block}
\end{exo}
\begin{frame}{Relative/absolute path}
\newcommand*\redcolor{}
\newcommand*\bluecolor{}
\newcommand*\fillbluecolor{none}
\only<1-3>{\renewcommand*\redcolor{red}}
\only<4->{\renewcommand*\bluecolor{blue}}
\only<4->{\renewcommand*\fillbluecolor{blue!20}}
\begin{block}{}
\centering
\begin{tikzpicture}[every node/.style=draw=black,thick,anchor=west,text depth=.5ex,text height=2.2ex]
\node[\bluecolor] {/}
child { node {etc/}}
child { node {usr/}
child { node {bin/}}
child { node {lib/}}
}
child [missing] {}
child { node[\bluecolor] (p) {home/}
child [missing] {}
child { node[\bluecolor,\redcolor,fill=\fillbluecolor] (n) {user1/}
child { node {Download/}}
child [missing] {}
child { node[\bluecolor] {Desktop/}}
child [missing] {}
child { node[\redcolor] (dot) {.}}
child { node[\redcolor] (ddot) {..}}
}
child [missing] {}
child [missing] {}
child { node {user2/}}
};
\path[\redcolor, -latex, visible on=<2-3>] (dot) edge [bend right] (n);
\path[\redcolor, -latex, visible on=<3-3>] (ddot) edge [bend right] (p);
\end{tikzpicture}
\end{block}
\begin{block}<4->{}
\code{/home/user1/Desktop}\\
\code{./Desktop}
\end{block}
\end{frame}
\begin{exo}{Relative/absolute path}
\begin{questions}
\item Try the command \code{ls -a}
\item List the parent folder of your home
\item List the root folder with a relative path
\item To what correspond the folder \code{../././..}
\end{questions}
\vspace*{-.7ex}
\begin{block}<2->{}
\begin{command}
> ls ../%
\end{command}
\end{block}
\vspace*{-.7ex}
\begin{block}<3->{}
\begin{command}
> ls ../../%
\end{command}
\end{block}
\vspace*{-.7ex}
\begin{block}<4->{}
\begin{command}
> cd ../././..
> pwd %
\end{command}
\end{block}
\end{exo}
\begin{frame}{File creation/suppression commands}
\begin{block}{}
\centering
\begin{tabular}{r|l}
\code{cp} & copy files\\
\code{mv} & move/rename files\\
\code{rm} & remove file \color{red}{caution no trash}\\
\code{mkdir} & create a folder\\
\code{cat} & print the content of file, used to concatenate\\
\code{touch} & update the date of a file, used to create empty files\\
\code{tail/head}& print the end/beginning of a file\\
\code{more/less}& print the content of a file ``more or less the same''\\
\code{grep} & search a string in a file\\
\code{find} & find a file\\
\code{file} & the type of file based on content
\end{tabular}
\end{block}
\end{frame}
\begin{exo}{File handling commands}
\begin{extrainfos}
\centering
\begin{tabular}{r|l}
\code{cp} & copy files\\
\code{mv} & move/rename files\\
\code{rm} & remove file \color{red}{caution no trash}\\
\code{mkdir} & create a folder\\
\code{cat} & print the content of file, used to concatenate\\
\code{touch} & update the date of a file, used to create empty files\\
\code{tail/head}& print the end/beginning of a file\\
\code{more/less}& print the content of a file ``more or less the same''\\
\code{grep} & search a string in a file\\
\code{find} & find a file\\
\code{file} & the type of file based on content
\end{tabular}
\end{extrainfos}
\begin{questions}
\item Test the different commands (do not forget you can check the help with
\code{man <command>})
\item Create a directory named \code{exercise\_linux}
\item Copy the file \code{CodingStyle} from your home directory into the \code{exercise\_linux} folder
\item Check the content of this file
\item Print the last 3 lines
\item Find the lines containing the world ``coding'' independently of the case
\item Rename the file as \code{KernelCodingStyle}
\item Copy the folder \code{exercise\_linux} to \code{exo\_linux}
\item Remove the folder \code{exercise\_linux}
\end{questions}
\end{exo}
\begin{frame}[fragile]{Answer to exercise~\arabic{exercise}}
\begin{block}{}
\vspace*{-.8ex}
\begin{command}
> mkdir exercise_linux %
\end{command}
\vspace*{-1.4ex}
\end{block}
\vspace*{-1.1ex}
\begin{block}<2->{}
\vspace*{-.8ex}
\begin{command}
> cd exercise_linux
> cp /ssoft/playground/richart/CodingStyle .%
\end{command}
\vspace*{-1.4ex}
\end{block}
\vspace*{-1.1ex}
\begin{block}<3->{}
\vspace*{-.8ex}
\begin{command}
> less CodingStyle%
\end{command}
\vspace*{-1.4ex}
\end{block}
\vspace*{-1.1ex}
\begin{block}<4->{}
\vspace*{-.8ex}
\begin{command}
> tail -n3 CodingStyle%
\end{command}
\vspace*{-1.4ex}
\end{block}
\vspace*{-1.1ex}
\begin{block}<5->{}
\vspace*{-.8ex}
\begin{command}
> grep -n --color -i coding CodingStyle%
\end{command}
\vspace*{-1.4ex}
\end{block}
\vspace*{-1.1ex}
\begin{block}<6->{}
\vspace*{-.8ex}
\begin{command}
> mv CodingStyle KernelCodingStyle%
\end{command}
\vspace*{-1.4ex}
\end{block}
\vspace*{-1.1ex}
\begin{block}<7->{}
\vspace*{-.8ex}
\begin{command}
> cd ..
> cp -r exercise_linux exo_linux%
\end{command}
\vspace*{-1.4ex}
\end{block}
\vspace*{-1.1ex}
\begin{block}<8->{}
\vspace*{-.8ex}
\begin{command}
> rm -r exercise_linux %
\end{command}
\vspace*{-1.4ex}
\end{block}
\end{frame}
\begin{frame}{File permissions}
\begin{block}{Possible permissions}
Partial results of the command \code{ls -l CodingStyle}\\
\texttt{-}\tikz[baseline]{ \node[anchor=base, fill=blue!20 ] (u1) {\texttt{rw-}}; }
\tikz[baseline]{ \node[anchor=base, fill=red!20 ] (g1) {\texttt{r--}}; }
\tikz[baseline]{ \node[anchor=base, fill=green!20] (o1) {\texttt{r--}}; }
\hspace*{1em}\texttt{richart} \hspace*{1em}\texttt{scitas-ge}
\hspace*{1ex}\texttt{CodingStyle}
\begin{itemize}
\item[] \tikz[baseline]{ \node[anchor=base, fill=blue!20 ] (u1)
{u}; } User permissions
\item[] \tikz[baseline]{ \node[anchor=base, fill=red!20 ] (u1)
{g}; } Group permissions
\item[] \tikz[baseline]{ \node[anchor=base, fill=green!20 ] (u1)
{o}; } Other users permissions
\end{itemize}
\end{block}
\begin{block}{\texttt{rwx}/\texttt{---} explanations}
\begin{tabular}{r|l}
\code{-} or 0 & Permission not granted \\
\code{r} or 4 & Read/List permission \\
\code{w} or 2 & Write/Create permission \\
\code{x} or 1 & Execute/Traverse permission\\
\end{tabular}
\end{block}
\end{frame}
\begin{frame}{Permission commands}
\begin{block}{}
\begin{tabular}{r|l}
\code{chmod} & change permissions \\
\code{chgrp} & change main group \\
\code{chown} & change ownership \\
\code{newgrp} & login with a new group as main group \\
\code{id} & print user and group ids \\
\end{tabular}
\end{block}
\begin{block}{\texttt{chmod} details}
\code{chmod [ugoa][+-=][rwxXst] files}\\
\code{chmod octal files}
example: \code{u=rw,go=r} equivalent to \code{644}
\end{block}
\end{frame}
\begin{exo}{Permissions}
\begin{extrainfos}
Partial results of the command \code{ls -l CodingStyle}\\
\texttt{-}\tikz[baseline]{ \node[anchor=base, fill=blue!20 ] (u1) {\texttt{rw-}}; }
\tikz[baseline]{ \node[anchor=base, fill=red!20 ] (g1) {\texttt{r--}}; }
\tikz[baseline]{ \node[anchor=base, fill=green!20] (o1) {\texttt{r--}}; }
\hspace*{1em}\texttt{richart} \hspace*{1em}\texttt{scitas-ge}
\hspace*{1ex}\texttt{CodingStyle}
\begin{itemize}
\setlength\itemsep{.1em}
\item[] \tikz[baseline]{ \node[anchor=base, fill=blue!20 ] (u1)
{u}; } User permissions
\item[] \tikz[baseline]{ \node[anchor=base, fill=red!20 ] (u1)
{g}; } Group permissions
\item[] \tikz[baseline]{ \node[anchor=base, fill=green!20 ] (u1)
{o}; } Other users permissions
\end{itemize}
\begin{tabular}{r|l}
\code{-} or 0 & Permission not granted \\
\code{r} or 4 & Read/List permission \\
\code{w} or 2 & Write/Create permission \\
\code{x} or 1 & Execute/Traverse permission\\
\end{tabular}
\begin{tabular}{r|l}
\code{chmod} & change permissions \\
\code{chgrp} & change main group \\
\code{chown} & change ownership \\
\code{newgrp} & login with a new group as main group \\
\code{id} & print user and group ids \\
\end{tabular}
\end{extrainfos}
\begin{questions}
\item Print your ids
\item Check the permissions of your home folders
\item Change the the default group of the file \code{KernelCodingStyle} to \code{hpc-cluster-users}
\item Remove the list permission on \code{exo\_linux}
\item Try to list the \code{exo\_linux} folder of someone that as completed
the previous step
\end{questions}
\end{exo}
\begin{frame}[fragile]{Answer to exercise~\arabic{exercise}}
\begin{block}{}
\vspace*{-.8ex}
\begin{command}
> id %
\end{command}
\vspace*{-1.4ex}
\end{block}
\vspace*{-1.1ex}
\begin{block}<2->{}
\vspace*{-.8ex}
\begin{command}
> ls -l %
\end{command}
\vspace*{-1.4ex}
\end{block}
\vspace*{-1.1ex}
\begin{block}<3->{}
\vspace*{-.8ex}
\begin{command}
> chgrp hpc-cluster-users exo_linux/KernelCodingStyle %
\end{command}
\vspace*{-1.4ex}
\end{block}
\vspace*{-1.1ex}
\begin{block}<4->{}
\vspace*{-.8ex}
\begin{command}
> chmod go-r exo_linux%
\end{command}
\vspace*{-1.4ex}
\end{block}
\vspace*{-1.1ex}
\begin{block}<5->{}
\vspace*{-.8ex}
\begin{command}
> ls -l /home/richart/exo_linux
> ls -l /home/richart/exo_linux/KernelCodingStyle%
\end{command}
\vspace*{-1.4ex}
\end{block}
\end{frame}
\begin{frame}{Permissions: the special case of \texttt{root}}
\begin{block}{The \texttt{root} account}
\begin{itemize}
\item It's a special account, to which regular permissions do not apply
\item Used to administer the system
\item Should only be used to install trusted software
\item Preferably via the \code{sudo} command
\end{itemize}
\end{block}
\end{frame}
\section{Shell}
\vspace{-.2cm}
\begin{frame}{More about Shell}
\begin{block}{}
\begin{itemize}
\item Different shells: \texttt{sh}, \texttt{bash}, \texttt{csh}, \texttt{tcsh}, \texttt{zsh}, etc.
\item For EPFL account: {\scriptsize\url{https://cadiwww.epfl.ch/cgi-bin/accountprefs/}}
\item In general \code{echo \$SHELL}
\end{itemize}
\end{block}
\vspace{-.2cm}
\begin{block}{What is happening when you run a command}
\begin{itemize}
\item Expansions
\item Redirection
\item Execution
\end{itemize}
\end{block}
\vspace{-.2cm}
\begin{block}{Key shortcuts}
\begin{tabular}{r|l}
\texttt{Tab} & auto-complete \\
\texttt{(up)} & go back in the command history \\
\texttt{(down)} & go down in the command history \\
\texttt{Ctrl-r} & reverse search in the history \\
\texttt{Ctrl-d} & exit the shell \\
\end{tabular}
\end{block}
\end{frame}
\begin{frame}[fragile]{Expansions}
\begin{block}{}
\begin{itemize}
\item Accolade: \code{\{a\{b,c\},d\}} $\longrightarrow$ \code{ab ac d}
\item Tilde: \code{\textasciitilde richart/} $\longrightarrow$ \code{/home/richart}
\item Variables: \code{export FOO=bar} \code{\$FOO} $\longrightarrow$ \code{bar}
\item Command: \code{\$(command)} $\longrightarrow$ result of command
\item Split spaces: \code{arg1 arg2 arg3} the quoted arguments are not split
\item Path: \code{*} matches any string\\
\hspace{2.4em} \code{?} matches any single character\\
\hspace{2.4em} \code{[...]} matches any character in the brackets
\end{itemize}
\end{block}
\begin{itemize}
\item \textbf{TIP:} use \code{echo <command>} to test your expansions \!
\end{itemize}
\end{frame}
\begin{exo}{Expansions}
\begin{extrainfos}
\begin{tabular}{r|l}
\code{touch} & change the date of a file used to create new files \\
\code{echo} & print to the screen \\
\code{export} & make a variable known in all the new subprocess \\
\end{tabular}
\end{extrainfos}
\begin{questions}
\item Try the command \code{touch file\{0,1,2\}\{0,1,2,3,4,5\}.log}
\item List your home folder with a tilde expression
\item Set a variable \code{FOO} to the content of your choice and print its
content
\item Try the commands:\\
\code{touch foo bar}\\
\code{touch "foo bar"}\\
\code{export BROL=brol}\\
\code{touch "foo bar \$BROL"}\\
\code{touch 'foo bar \$BROL'}
\item List all file of the form \code{file<number>.log}
\item List the files \code{file<number>.log} where \texttt{<}number\texttt{>} is any number
with last digit 2,3 or 4
\item Remove the previous files using the results of the ls command
\end{questions}
\end{exo}
\begin{frame}[fragile]{Answer to exercise~\arabic{exercise}}
\vspace*{-1.1ex}
\begin{block}<1->{}
\vspace*{-.8ex}
\begin{command}
> ls ~/%
\end{command}
\vspace*{-1.4ex}
\end{block}
\vspace*{-1.1ex}
\begin{block}<2->{}
\vspace*{-.8ex}
\begin{command}
> export FOO="the content of my choice"
> echo $FOO%
\end{command} %$
\vspace*{-1.4ex}
\end{block}
\vspace*{-1.1ex}
\begin{block}<3->{}
\vspace*{-.8ex}
The second command create a file name containing a space that can be escaped
with \code{\textbackslash}
\begin{command}
> rm foo\ bar foo bar foo\ bar\ \$BROL foo\ bar\ brol%
\end{command}
\vspace*{-1.4ex}
\end{block}
\vspace*{-1.1ex}
\begin{block}<4->{}
\vspace*{-.8ex}
\begin{command}
> ls file*.log %
\end{command}
\vspace*{-1.4ex}
\end{block}
\vspace*{-1.1ex}
\begin{block}<5->{}
\vspace*{-.8ex}
\begin{command}
> ls file{2..4}.log %
\end{command}
\vspace*{-1.4ex}
\end{block}
\vspace*{-1.1ex}
\begin{block}<6->{}
\vspace*{-.8ex}
\begin{command}
> rm $(ls file*.log) %
\end{command}
\vspace*{-1.4ex}
\end{block}
\end{frame}
\begin{frame}[fragile]{Redirection}
\begin{block}{\texttt{process}}
\centering
\begin{tikzpicture}
\node [draw,text width=9ex,text height=3ex,text centered,text depth=2ex] (p) {process};
\node (i) at (-2.5cm, 0cm) {stdin (0) };
\node (o) at ( 2.5cm, .4cm) {stdout (1)};
\node (e) at ( 2.5cm,-.4cm) {stderr (2)};
\draw (i) -- (p);
\draw (p) -- (o);
\draw (p) -- (e);
\end{tikzpicture}
\end{block}
\begin{block}{\texttt{process > file.out}}
\centering
\begin{tikzpicture}
\node [draw,text width=9ex,text height=3ex,text centered,text depth=2ex] (p) {process};
\node (i) at (-2.5cm, 0cm) {stdin (0)};
\node (o) at ( 2.5cm, .4cm) {stdout (1)};
\node (e) at ( 2.5cm,-.4cm) {stderr (2)};
\node [draw,text width=7ex,text height=2ex,text centered,text depth=1ex]
(f) at (6cm, .4cm) {file.out};
\node (s) at (4.5cm, .4cm) {\color{red}{\texttt{>}}};
\draw (i) -- (p);
\draw (p) -- (o);
\draw (p) -- (e);
\draw (o) -- (s) -- (f);
\end{tikzpicture}
\end{block}
\begin{block}{\texttt{process 2> file.err}}
\centering
\begin{tikzpicture}
\node [draw,text width=9ex,text height=3ex,text centered,text depth=2ex] (p) {process};
\node (i) at (-2.5cm, 0cm) {stdin (0)};
\node (o) at ( 2.5cm, .4cm) {stdout (1)};
\node (e) at ( 2.5cm,-.4cm) {stderr (2)};
\node [draw,text width=7ex,text height=2ex,text centered,text depth=1ex]
(f) at (6cm, -.4cm) {file.err};
\node (s) at (4.5cm, -.4cm) {\color{red}{\texttt{2>}}};
\draw (i) -- (p);
\draw (p) -- (o);
\draw (p) -- (e);
\draw (e) -- (s) -- (f);
\end{tikzpicture}
\end{block}
\end{frame}
\begin{frame}[fragile]{Redirection}
\begin{block}{\texttt{process1 | process2}}
\centering
\begin{tikzpicture}
\node [draw,text width=7ex,text height=2ex,text centered,text depth=1.5ex] (p1) {\scriptsize{process1}};
\node (i1) at (-1.8cm, 0cm) {\scriptsize{stdin (0)}};
\node (o1) at ( 1.8cm, .4cm) {\scriptsize{stdout (1)}};
\node (e1) at ( 1.8cm,-.4cm) {\scriptsize{stderr (2)}};
\node (pipe) at (3cm, .4cm) {\color{red}{\texttt{|}}};
\draw (i1) -- (p1);
\draw (p1) -- (o1);
\draw (p1) -- (e1);
\node [draw,text width=7ex,text height=2ex,text centered,text depth=1.5ex]
(p2) at (5.9cm, .4cm) {\scriptsize{process2}};
\node (i2) at ( 4.1cm, .4cm) {\scriptsize{stdin (0)}};
\node (o2) at ( 7.7cm, .8cm) {\scriptsize{stdout (1)}};
\node (e2) at ( 7.7cm, 0cm) {\scriptsize{stderr (2)}};
\draw (i2) -- (p2);
\draw (p2) -- (o2);
\draw (p2) -- (e2);
\draw (o1) -- (pipe) -- (i2);
\end{tikzpicture}
\end{block}
\begin{block}{\texttt{process > file.out 2>\&1}}
\centering
\begin{tikzpicture}
\node [draw,text width=9ex,text height=3ex,text centered,text depth=2ex] (p) {process};
\node (i) at (-2.5cm, 0cm) {stdin (0)};
\node (o) at ( 2.5cm, .4cm) {stdout (1)};
\node (e) at ( 2.5cm,-.4cm) {stderr (2)};
\node [draw,text width=7ex,text height=2ex,text centered,text depth=1ex]
(f) at (6cm, .4cm) {file.out};
\node (s1) at (4.4cm, .4cm) {\color{red}{\texttt{>}}};
\node [draw,text width=7ex,text height=2ex,text centered,text depth=1ex]
(f) at (6cm, .4cm) {file.out};
\node (s2) at (4.4cm, -0cm) {\color{red}{\texttt{2>\&1}}};
\draw (i) -- (p);
\draw (p) -- (o);
\draw (p) -- (e);
\draw (o) -- (s1) -- (f);
\draw (e) -- (s2) -- (f);
\end{tikzpicture}
\end{block}
\end{frame}
\begin{exo}{Redirection}
\begin{extrainfos}
\begin{tabular}{r|l}
\code{date} & print the date \\
\code{wc} & wc count the numbers of lines/words/characters in a file \\
\end{tabular}
\vspace{1.5ex}
Syntax for redirections:
\vspace{-1.5ex}
\begin{itemize}
\item \code{command > file} redirect the standard output to \texttt{file}
\item \code{command 2> file} redirect the standard error to \texttt{file}
\item \code{command < file} redirect \texttt{file} to the standard input
\item \code{command1 | command2} redirect the stdout of \texttt{command1} in stdin of \texttt{command2}
\end{itemize}
\end{extrainfos}
\begin{questions}
\item Redirect the content of the \code{date} command in the \texttt{date.log} file
\item Count the number of words generated by the command \code{date} with the
help of the command \code{wc}
\item Redirect the error output for the command \code{ls / tmp}
\end{questions}
\vspace*{-1.1ex}
\begin{block}<2->{}
\vspace*{-.8ex}
\begin{command}
> date > date.log%
\end{command}
\vspace*{-1.4ex}
\end{block}
\vspace*{-1.1ex}
\begin{block}<3->{}
\vspace*{-.8ex}
\begin{command}
> date | wc -w%
\end{command}
\vspace*{-1.4ex}
\end{block}
\vspace*{-1.1ex}
\begin{block}<4->{}
\vspace*{-.8ex}
\begin{command}
> ls / tmp 2> errors%
\end{command}
\vspace*{-1.4ex}
\end{block}
\end{exo}
\begin{frame}{Execution}
\begin{block}{}
\begin{itemize}
\item Execution generate a new process
\item A process is identified by a \texttt{pid}
\item Can be run in foreground or background (\code{\&})
\end{itemize}
\end{block}
\begin{block}{Commands}
\begin{tabular}{r|l}
\code{ps} & list the running processes \\
\code{jobs} & list the jobs running in the current shell \\
\code{kill} & kill processes \\
\code{bg} & resume jobs in background \\
\code{fg} & resume jobs in foreground \\
\end{tabular}
\end{block}
\begin{block}{Key shortcuts}
\begin{tabular}{r|l}
\texttt{Ctrl-c} & kill the current job in foreground \\
\texttt{Ctrl-z} & suspend the current job in foreground \\
\end{tabular}
\end{block}
\end{frame}
\begin{exo}{Execution}
\begin{extrainfos}
\begin{tabular}{r|l}
\code{ps} & list the running processes \\
\code{jobs} & list the jobs running in the current shell \\
\code{kill} & kill processes \\
\code{bg} & resume jobs in background \\
\code{fg} & resume jobs in foreground \\
\end{tabular}
\end{extrainfos}
\begin{questions}
\item Run the command \code{(sleep 30; echo Slept well)}
\item Run the command \code{(sleep 30; echo Slept well)\&}
\item Now you have 30 seconds to check the \texttt{pid} with \code{ps}
\item If you still have spare seconds kill the process before it print on screen
\end{questions}
\end{exo}
\section{Editing files}
\begin{frame}{Command line editors: nano vi emacs}
\begin{block}{nano}
\begin{itemize}
\item \code{Ctrl-o} to save file
\item \code{Ctrl-x} to quit
\end{itemize}
\end{block}
\begin{block}{vi}
\begin{itemize}
\item command mode and edition mode
\item \code{i} to insert, \code{esc} to go back to command mode
\item \code{:wq} to save and quit
\item \code{:q!} to force quit
\end{itemize}
\end{block}
\begin{block}{emacs}
\begin{itemize}
\item \code{Ctrl-x Ctrl-s} to save file
\item \code{Ctrl-x Ctrl-c} to quit
\end{itemize}
\end{block}
\end{frame}
\begin{exo}{Execution}
\begin{extrainfos}
\begin{itemize}
\item nano\\
\begin{tabular}{r|l}
\code{Ctrl-o} & save file \\
\code{Ctrl-x} & quit \\
\end{tabular}
\item vi\\
\begin{tabular}{r|l}
\code{i} & insert \\
\code{esc} & go back to command mode \\
\code{:wq} & save and quit\\
\code{:q!} & force quit\\
\end{tabular}
\item emacs\\
\begin{tabular}{r|l}
\code{Ctrl-x Ctrl-s} & save file \\
\code{Ctrl-x Ctrl-c} & quit\\
\end{tabular}
\end{itemize}
\end{extrainfos}
\begin{questions}
\item Try this editors
\begin{itemize}
\item nano
\item vim
\item emacs
\end{itemize}
\end{questions}
\end{exo}
\section{Scripts}
\begin{frame}{Shell scripts}
\begin{block}{What is it}
\begin{itemize}
\item It is a file containing a list of commands to execute in order
\item Can contain loops (\texttt{for}, \texttt{while}), conditions
(\texttt{if})
\item Often start with interpreter information \code{\#!/bin/bash}
\end{itemize}
\end{block}
\begin{block}{Example of bash script}
\begin{itemize}
\item \texttt{\textasciitilde/.bashrc}
\item cluster job script
\end{itemize}
\end{block}
\end{frame}
\begin{exo}{Shell scripts}
\begin{questions}
\item Write a script that print \texttt{Hello World}, wait 2seconds and then
print the date
\item Make your script executable
\item Run it
\end{questions}
\begin{block}<2->{hello.sh}
\vspace*{-.8ex}
\begin{command}
#!/bin/bash
echo Hello World
sleep 2
date%
\end{command}
\vspace*{-1.4ex}
\end{block}
\begin{block}<3->{}
\vspace*{-.8ex}
\begin{command}
> chmod +x ./hello.sh%
\end{command}
\vspace*{-1.4ex}
\end{block}
\begin{block}<4->{}
\vspace*{-.8ex}
\begin{command}
> ./hello.sh%
\end{command}
\vspace*{-1.4ex}
\end{block}
\end{exo}
%\section{Extra Material}
\begin{frame}{Transferring files: SFTP clients}
\begin{minipage}{.45\linewidth}
\begin{block}{Filezilla}
{\scriptsize\url{https://filezilla-project.org}}
\centering
\begin{tikzonimage}[width=.96\linewidth]{images/filezilla}
\end{tikzonimage}
\vspace*{3.5ex}
\end{block}
\end{minipage}
\hspace*{2ex}
\begin{minipage}{.45\linewidth}
\begin{block}{Cyberduck}
{\scriptsize\url{https://cyberduck.io/}}
\centering
\begin{tikzonimage}[width=.96\linewidth]{images/cyberduck}
\end{tikzonimage}
\end{block}
\end{minipage}
\end{frame}
\begin{frame}{X11 Forwarding}
\begin{block}{Windows}
Install XMing {\scriptsize\url{http://sourceforge.net/projects/xming/}} or
XWin32 (distrilog)\\
\end{block}
\vspace*{-1ex}
\begin{block}{Mac OS}
Install XQuartz {\scriptsize\url{http://xquartz.macosforge.org/landing/}}, MacPort or Homebrew\\
Connect with \code{ssh -Y <username>@<hostname>}
\end{block}
\end{frame}
%\section{Sources}
\begin{frame}{Sources}
\begin{block}{}
\begin{itemize}
\item Wikipedia: \url{http://en.wikipedia.org/}
\begin{itemize}
\item \href{https://en.wikipedia.org/wiki/History_of_Linux}{History\_of\_Linux}
\item \href{https://en.wikipedia.org/wiki/Usage_share_of_operating_systems}{Usage\_share\_of\_operating\_systems}
\item \href{https://en.wikipedia.org/wiki/Mobile_operating_system}{Mobile\_operating\_system}
\end{itemize}
\item DistroWatch: \url{http://distrowatch.com/}
\item \href{http://tldp.org/LDP/intro-linux/html/}{The Linux Documentation Project}
\end{itemize}
\end{block}
\end{frame}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: "slides"
%%% End:

Event Timeline