Skip to content

Commit

Permalink
Updates and corrections after course.
Browse files Browse the repository at this point in the history
  • Loading branch information
V-Z committed Feb 8, 2018
1 parent e01c0f8 commit ed67687
Showing 1 changed file with 36 additions and 33 deletions.
69 changes: 36 additions & 33 deletions presentation/linux_bash_metacentrum_course.tex
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ \subsection{Files and directories}
# Set this to "no" here for global effect or in your own ~/.ssh/config
# file if you want to have the remote X11 authentification data to
# expire after twenty minutes after remote login.
ForwardX11Trusted yes
ForwardX11Trusted yes
\end{bashcode}
\end{frame}

Expand Down Expand Up @@ -868,7 +868,7 @@ \subsection{Permissions}
\end{tabular}
\end{center}
\begin{itemize}
\item \texttt{rwxr-wr--} --- 3*3 characters for permissions for owner of the file/directory, group it is belonging to, and other users (\texttt{d} on beginning marks directories, \texttt{l} links, \texttt{+} ACL, slide \ref{acl})
\item \texttt{rwxrw-r--} --- 3*3 characters for permissions for owner of the file/directory, group it is belonging to, and other users (\texttt{d} on beginning marks directories, \texttt{l} links, \texttt{+} ACL, slide \ref{acl})
\item \texttt{764} --- same as above --- numbers for each role are summed --- first one is for owner, second for group and last for others
\item Executable scripts and binaries \textbf{require} executable permission (\texttt{x})
\end{itemize}
Expand Down Expand Up @@ -1372,8 +1372,8 @@ \section{Command line}
\begin{frame}[fragile]{Expressions}
\begin{bashcode}
# Many operands have special meaning in BASH - must be escaped
echo `expr 1 '<' 2` # Is 1 smaller than 2? TRUE (1)
echo `expr 1 '>' 2` # Is 1 greater than 2? FALSE (0)
echo `expr 5 '<' 7` # Is 1 smaller than 2? TRUE (1)
echo `expr 6 '>' 4` # Is 1 greater than 2? FALSE (0)
echo `expr 5 '%' 2` # What remains after aritmetic division
echo `expr 1 '&' 0` # If both arguments non-empty and not 0, then 1
x=`expr 1 '+' 6` # Result will be in $x
Expand Down Expand Up @@ -1637,7 +1637,7 @@ \subsection{Variables}
cat /proc/cpuinfo # Raw list of information about CPU
lsusb # List of devices on USB
lspci # List of PCI devices (graphic card, network card, ...)
lspci | grep -i vga # Get information about graphical cay
lspci | grep -i vga # Get information about graphical card
lshw # Complete list of hardware
lshw -C memory # Information about RAM
hwinfo # Complete list of hardware
Expand Down Expand Up @@ -1847,21 +1847,21 @@ \subsection{Searching}
\begin{frame}[fragile]{Find examples (apply some of them to the toy data)}
\begin{bashcode}
# Find in /home/$USER/ all JPG files containing string "oxalis"
find /home/$USER/ -name "*oxalis*.jpg" -print
# Find in scripts_data all JPG files and resize them to 1000x1000 px
find scripts_data -name *.jpg -exec mogrify -resize 1000x1000 '{}' \;
find scripts_data -name "*.jpg" -exec mogrify -resize 1000x1000 '{}' \;
# Another possibility with xargs (it chains commands - reads input from
# stdin and execute command with given arguments, using all CPU threads)
# Note in the example below -print is not needed as it is default action
find photos/ -name *.jpg | xargs mogrify -resize 1000x1000
find photos/ -name "*.jpg" | xargs mogrify -resize 1000x1000
# Find all R scripts in ~/Documents and find in them lines with "DNA"
find ~/Documents -name *.r -print | xargs grep -nH DNA # Or
find ~/Documents -name *.r -exec grep -nH DNA '{}' \;
# How many directories are there in the books directory
find books/ -type d -print | wc -l # wc -l calculate lines
# Find in /home/$USER/ all JPG files containing string "oxalis"
find /home/$USER/ -name "*oxalis*.jpg" -print
# Change permissions of all files within "files" directory to 777
find files/ -type f -exec chmod 777 '{}' \;
# Change permissions of all files within "files" directory to 640
find files/ -type f -exec chmod 640 '{}' \;
# Find all executable files within current directory and list them
find . -executable -type f -print
find doc/ -type d -empty -execdir rmdir {} \; # Delete empty directories
Expand Down Expand Up @@ -1934,7 +1934,7 @@ \subsection{Network}
man mount.cifs # See for other connection options
# Mounting remote server over SSH (sshfs package must be installed)
sshfs [email protected]:/some/dir /local/mount/point
fusermount -f /mount/point # Disconnect SSHF
fusermount -u /mount/point # Disconnect SSHF
# Mount NFS share (NFS is common protocol in UNIX world)
mount -t nfs some.server.cz:/shared/directory /local/directory
# Mount webDAV folder (requires package davfs2 to be installed)
Expand Down Expand Up @@ -2325,7 +2325,7 @@ \subsection{AWK}
# (i.e. print line number (NR) and then whole original line ($0))
awk '{print NR "\t" $0}' diff_test_file_*
# substitute "a" with "XXX" ONLY for lines which contain "The"
awk '/The/{gsub(/a/, "XXX")}; 1' diff_test_file_1.txt
awk '/She/{gsub(/a/, "XXX")}; 1' diff_test_file_1.txt
# For every 4th line starting from line 2 of FASTQ file (from line 2
# every 4th line contains the DNA sequence) print its length (bzcat
# prints content of file compressed by bzip2)
Expand Down Expand Up @@ -2440,8 +2440,8 @@ \subsection{Manipulations}
sed 's/ *$//' # Delete extra spaces on the end of lines
sed '/GUI/d' # Delete all whole lines containing "GUI"
sed 's/GUI//g' # Delete all occurrences of "GUI" (not whole lines)
sed '4 i\Linux is great.' diff_test_file_1.txt # Insert to 5th line
sed '3 a\Linux is great.' diff_test_file_1.txt # Insert after 4th line
sed '4 i\Linux is great.' diff_test_file_1.txt # Insert to 4th line
sed '3 a\Linux is great.' diff_test_file_1.txt # Insert after 3rd line
\end{bashcode}
\end{frame}
Expand Down Expand Up @@ -2582,8 +2582,8 @@ \subsection{Editors}
\end{itemize}
\begin{multicols}{2}
\begin{itemize}
\item \texttt{C-h C-h} help (press twice \texttt{Ctrl~+~H})
\item \texttt{C-g} quit
\item \texttt{C-h C-h} help (twice \texttt{Ctrl~+~H})
\item \texttt{C-x C-c} quit (\texttt{X-g} for particular buffer, etc.)
\item \texttt{C-x C-f} open file
\item \texttt{C-x C-s} save file
\item \texttt{C-x C-w} save file as
Expand Down Expand Up @@ -2693,7 +2693,7 @@ \subsection{Regular expressions}
\item \alert{\texttt{[[:xdigit:]]}} --- hexadecimal digits
\item \alert{\texttt{\textasciicircum\$}} --- blank line
\item \alert{\texttt{\textasciicircum.*\$}} --- entire line whatever it is
\item \alert{\texttt{ *}} --- one or more spaces (there is space before asterisk)
\item \alert{\texttt{ +}} --- one or more spaces (there is space before plus)
\item \alert{\texttt{\&}} --- content of pattern that was matched
\item Implementation in \texttt{vim}, \texttt{sed}, \texttt{grep}, \texttt{awk} and \texttt{perl} and among various UNIX systems is almost same, but not identical\ldots
\item \textbf{grep}, \textbf{sed} and \textbf{vim} \alert{require escaping} of \alert{\texttt{+}}, \alert{\texttt{?}}, \alert{\texttt{\{}}, \alert{\texttt{\}}}, \alert{\texttt{(}} and \alert{\texttt{)}} by backslash \alert{\texttt{\textbackslash}} (e.g. \texttt{\textbackslash +}) --- \textbf{egrep} (extended version, launched as \texttt{grep -E \ldots} or \texttt{egrep \ldots}), \textbf{sed} with extended reg exp (\texttt{sed -r}) and \textbf{perl} \alert{not}
Expand All @@ -2713,15 +2713,15 @@ \subsection{Regular expressions}
# Get quality of Illumina reads mapping to reference in genomic VCF
zcat arabidopsis.vcf.gz | grep -o "MQ=[[:digit:]]\+"
# How many times there is a direct speech (text between "...")
grep -o "\"[a-ZA-Z0-9,\.?\! ]\+\"" long_text.txt | wc -l
grep -o '\"[[:upper:]][a-zA-Z0-9,\.\?\! ]\+\"' long_text.txt | wc -l
# Add after dot on the end of the line by extra line break
sed 's/\.$/.\n/' long_text.txt
# Add HTML paragraph tags (<p> and </p>)
sed -e 's/^/<p>/' -e 's/$/<\/p>/' long_text.txt | less
# Make first word of every paragraph bold in HTML (<strong>...</strong>)
sed -e 's/^/<strong>/' -e 's/^[[:graph:]]\+/&<\/strong>/' long_text.txt
# How many times is each word in the text
grep -o "\<[[:alpha:]]\+\>" long_text.txt | sort | uniq -c | less
grep -o "\<[[:alpha:]]\+\>" long_text.txt | sort | uniq -ic | less
# List all Internet web links
grep -o "http[a-zA-Z0-9\.()/:\-]\+" long_text.txt
\end{bashcode}
Expand Down Expand Up @@ -2761,7 +2761,7 @@ \subsection{BASH variables}
\item \alert{\texttt{\$1}},~\ldots~(number from \texttt{1} up to number of parameters) --- individual positional parameters (see further for example)
\item \alert{\texttt{\$0}} --- path of the starting script
\item \alert{\texttt{\$\#}} --- number of command-line arguments
\item \alert{\texttt{\$*}} --- all of the positional parameters, seen as a~single word, must be quoted
\item \alert{\texttt{\$*}} --- all of the positional parameters, seen as a~single word, must be quoted (i.e. \texttt{"\$*"})
\item \alert{\texttt{\$@}} --- same as \texttt{\$*}, but each parameter is a~quoted string --- the parameters are passed on intact, without interpretation or expansion, each parameter in the argument list is seen as a~separate word, should be quoted (i.e. something like \texttt{"\$@"})
\item \alert{\texttt{\$\$}} --- process ID (PID) of the script itself
\item \alert{\texttt{\$?}} --- Exit status of a~command, function, or the script itself
Expand Down Expand Up @@ -2980,7 +2980,7 @@ \subsection{Reading variables}
\begin{bashcode}
# Remaining part from previous slide...
if [[ ! $3 =~ $NUMBER ]]; then # Is parameter 3 number?
echo "Parameter 3~is not an integer!"
echo "Parameter 3 is not an integer!"
usagehelp # The function to print help
fi
case "$2" in
Expand Down Expand Up @@ -3156,7 +3156,7 @@ \subsection{Branching the code}
\item \texttt{-x \$FILE} --- True if \texttt{\$FILE} exists and is executable
\item \texttt{-d \$FILE} --- True if \texttt{\$FILE} exists and is a~directory
\item \texttt{-s \$FILE} --- True if \texttt{\$FILE} exists and has a~size greater than zero
\item \texttt{-n \$STR} --- True if string \texttt{\$STR} is not a~null string
\item \texttt{-n \$STR} --- True if string \texttt{\$STR} is not a~null (empty) string
\item \texttt{-z \$STR} --- True if string \texttt{\$STR} is a~null string
\item \texttt{\$STR1 == \$STR2} --- True if both strings are equal
\item \texttt{\$STR} --- True if string \texttt{\$STR} is assigned a~value and is not null
Expand Down Expand Up @@ -3322,10 +3322,10 @@ \subsection{Packages}
\item \texttt{zypper up} --- update
\item \texttt{zypper dup} -- upgrade to newer release of whole distribution
\item \texttt{zypper se \textit{term}} --- search \textit{term}
\item \texttt{rpmorphan} and/or \texttt{zypper -pa --orphaned --unneeded} --- clear packages
\item \texttt{rpmorphan} and/or \texttt{zypper -pa --orphaned --unneeded} --- list packages, which can be safely removed
\item \texttt{yast sw\_single} --- interactive manager
\item \texttt{zypper lr} --- list repositories
\item \texttt{zypper ar \textit{repository}} --- add \textit{repository} (URL remote \texttt{*.repo} file)
\item \texttt{zypper ar \textit{repository}} --- add \textit{repository} (URL of remote \texttt{*.repo} file)
\item \texttt{zypper rr \textit{repository}} --- remove \textit{repository} (name according to \texttt{zypper lr})
\item \texttt{zypper mr \textit{repository}} --- modify \textit{repository} (see \texttt{man zypper} first or use \texttt{yast sw\_single})
\item \texttt{zypper pa \textit{package}} --- get information about particular \textit{package} or another query (e.g. list of dependencies, see \texttt{man zypper})
Expand Down Expand Up @@ -3432,7 +3432,7 @@ \subsection{Compilation}
# Red Hat, CENTOS, Scientific Linux, Older Fedora and derivatives
yum groupinstall "Development Tools" "C Development Tools and Libraries"
# Fedora since version 22
dnf group install "Development Tools" "C Development Tools and Libraries"
dnf groupinstall "Development Tools" "C Development Tools and Libraries"
\end{bashcode}
\end{frame}
Expand Down Expand Up @@ -3466,7 +3466,7 @@ \subsection{Compilation}
wget https://github.com/samtools/samtools/releases/download/1.7/
samtools-1.7.tar.bz2 # Download SAMtools
tar xjvf samtools-1.7.tar.bz2 # Unpack the archive
cd cd samtools-1.7/ # Go to the unpacked directory
cd samtools-1.7/ # Go to the unpacked directory
./configure # Configure settings for compilation
./configure --help # See various configuring options
./configure --without-curses # Compile without ncurses support
Expand Down Expand Up @@ -3941,7 +3941,7 @@ \subsection{System services}
journalctl -b
# Time and date information and management
timedatectl
# End much more...
# And much more...
\end{bashcode}
\end{frame}
Expand Down Expand Up @@ -4019,7 +4019,7 @@ \section{Git} % TODO More general info about Git, separate GitHub to extra slide
git remote add origin <location> # Do only once on the beginning
# <location> can be remote server or local path
git remote add origin . # For repository within working directory
# Push changes into the (regardless where it is) repository
# Push changes into the repository (regardless where it is)
git push origin master # See further for selection of branches
\end{bashcode}
\end{frame}
Expand Down Expand Up @@ -4098,8 +4098,11 @@ \subsection{Resources}
\item Linux tutorial \url{https://ryanstutorials.net/linuxtutorial/}
\item Getting Started with BASH \url{http://www.hypexr.org/bash_tutorial.php}
\item Bash Guide \url{https://mywiki.wooledge.org/BashGuide}
\item Česky Učebnice Linuxu \url{https://www.abclinuxu.cz/ucebnice}
\item Česky příkazová řádka Ubuntu \url{http://wiki.ubuntu.cz/syst\%C3\%A9m/p\%C5\%99\%C3\%ADkazov\%C3\%A1_\%C5\%99\%C3\%A1dka/termin\%C3\%A1l}
\item Česky
\begin{itemize}
\item Učebnice Linuxu \url{https://www.abclinuxu.cz/ucebnice}
\item Příkazová řádka Ubuntu \url{http://wiki.ubuntu.cz/syst\%C3\%A9m/p\%C5\%99\%C3\%ADkazov\%C3\%A1_\%C5\%99\%C3\%A1dka/termin\%C3\%A1l}
\end{itemize}
\end{itemize}
\end{frame}
Expand Down Expand Up @@ -4212,9 +4215,9 @@ \subsection{Resources}
\begin{itemize}
\item Forum \url{https://forum.kde.org/}
\item UserBase wiki \url{https://userbase.kde.org/Welcome_to_KDE_UserBase}
\item application store \url{https://store.kde.org/}
\item Application store \url{https://store.kde.org/}
\item KDE for education \url{https://edu.kde.org/}
\item blogs \url{https://planet.kde.org/}
\item Blogs \url{https://planet.kde.org/}
\end{itemize}
\item XFCE \url{https://xfce.org/}
\begin{itemize}
Expand Down

0 comments on commit ed67687

Please sign in to comment.