Skip to content

Commit 2146939

Browse files
committed
Updates, structure changes
1 parent 3b70e68 commit 2146939

File tree

2 files changed

+67
-63
lines changed

2 files changed

+67
-63
lines changed

presentation/linux_bash_metacentrum_course.tex

Lines changed: 67 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ \subsection{Basic theory of operating system}
495495

496496
\begin{frame}{Types of files}
497497
\begin{itemize}
498-
\item \bash/ls -la # See files and its types (below)/
498+
\item \bash/ls -la/
499499
\item Regular file -- ordinary file, marked by \texttt{-}
500500
\item Directory -- in UNIX special type of file, marked by \texttt{d}
501501
\item Symbolic link (symlink, ``soft link'') -- points to another place, marked by \texttt{l}, slide \ref{links}
@@ -742,7 +742,7 @@ \subsection{Text}
742742
\item Show syntax highlight
743743
\item Show line numbers
744744
\item Show space between brackets
745-
\item Open any encoding and EOL type
745+
\item Open any encoding and EOL
746746
\item Fold source code
747747
\item Show line breaks
748748
\item Mark lines
@@ -773,6 +773,15 @@ \subsection{Text}
773773
\end{multicols}
774774
\end{frame}
775775

776+
\begin{frame}{It \textbf{is} important to select \textbf{good} text editor\ldots}
777+
\begin{center}
778+
\includegraphics[width=\textwidth-1cm]{real_programmers.png}
779+
\end{center}
780+
\begin{flushright}
781+
\url{https://xkcd.com/378/}
782+
\end{flushright}
783+
\end{frame}
784+
776785
\subsection{FISH}
777786

778787
\begin{frame}{Friendly interactive shell}
@@ -876,12 +885,21 @@ \subsection{FISH}
876885
\end{frame}
877886

878887
\begin{frame}[fragile]{The PATH variable}
879-
\begin{bashcode}
880-
#
881-
\end{bashcode}
882888
\begin{itemize}
883-
\item
889+
\item Lists directories (separated by colon \texttt{:}) where the current shell searches for commands
890+
\item If some software is installed outside standard locations, the user must specify the full path (or update the \texttt{\$PATH})
891+
\item In case there are two commands with the same name (e.g. \texttt{/bin/somecommand} and \texttt{/usr/bin/somecommand}), the order of directories in \texttt{\$PATH} matters -- the first occurrence is used, any possible later ignored
884892
\end{itemize}
893+
\begin{bashcode}
894+
# See the $PATH variable
895+
echo $PATH # Sample output is on the next line:
896+
/home/$USER/bin:/usr/local/bin:/usr/bin:/bin:/opt/bin:/sbin:/usr/sbin
897+
# Adding new directory to $PATH
898+
export PATH=$PATH:/some/new/directory # Ensure to add original $PATH
899+
# Do not do it in the following way - it would overwrite $PATH, and
900+
# there would be only the new directory (not the original content)!
901+
export PATH=/some/new/directory # Wrong! Old $PATH is missing!
902+
\end{bashcode}
885903
\end{frame}
886904

887905
\begin{frame}[fragile]{Reading variables from command line}
@@ -1004,7 +1022,7 @@ \subsection{FISH}
10041022
ls -l .bash* # Numbers in first column show links pointing to it
10051023
# For directories - number of items, for files = 1
10061024
-rw------- 1 vojta users 27298 21. led 16.43 .bash_history # One link
1007-
-rw-r--r-- 2 vojta users 2707 29. lis 16.21 .bashrc # Same data as below
1025+
-rw-r--r-- 2 vojta users 2707 29. lis 16.21 .bashrc # Same file as below
10081026
-rw-r--r-- 2 vojta users 2707 29. lis 16.21 .bashrcX # Two links
10091027
\end{bashcode}
10101028
\end{frame}
@@ -1016,7 +1034,7 @@ \section{Command line}
10161034
\item When you log off or network connection is broken, running tasks for particular terminal usually crash
10171035
\item Sometimes number of connections is limited
10181036
\item \texttt{screen} is solution -- virtual terminals
1019-
\item Launch \texttt{screen} to start new screen terminal, read some info, confirm by Space key or Enter
1037+
\item Launch \texttt{screen} to start new screen terminal, read some info, confirm by \textbf{Space key} or \textbf{Enter}
10201038
\item To detach from the screen press \texttt{Ctrl+A, D} -- screen is still running in background -- you can even log off
10211039
\item To return back to running screen use \texttt{screen -r} -- if only one screen is running, you get back to it
10221040
\item If more screens are running, use \texttt{screen -r 1234} (the number is seen from \texttt{screen -r})
@@ -1041,7 +1059,7 @@ \section{Command line}
10411059
\begin{bashcode}
10421060
systemctl status/start/stop cron.service # Check/start/stop if cron runs
10431061
crontab -l # List cron tasks
1044-
crontab -e # Edit cron tasks (launches editor according to the variable):
1062+
crontab -e # Edit cron tasks:
10451063
# Minute, Hour, Day in month, Month, Day in week, Command (absolute path)
10461064
# 0-59 0-23 1-31 1-12 0-6 starting with Sunday (WTF?)
10471065
* * * * * /usr/bin/command
@@ -1055,21 +1073,21 @@ \subsection{Chaining}
10551073

10561074
\begin{frame}{Chaining commands}
10571075
\begin{itemize}
1058-
\item \alert{\&} -- command will be launched in background, terminal is available for next typing: \texttt{firefox \&}
1059-
\item \alert{\&\&} -- second command is launched only when first command exits without error (exits with 0 status): \texttt{mkdir NewDir \&\& cd NewDir}
1060-
\item \alert{;} -- second command is launched regardless exit status of the first one: \texttt{kshfskcbd; hostname}
1061-
\item \alert{\textbraceleft\ldots\textbraceright} -- commands within curl brackets are launched as one block
1062-
\item \alert{||} -- second command is launched when first command fails (has non zero exit status):\\\texttt{cd newdir || \textbraceleft~mkdir newdir \&\& cd newdir; \textbraceright}
1076+
\item \alert{\texttt{\&}} -- command will be launched in background, terminal is available for next typing: \texttt{firefox \&} (when launching graphical application, hit \textbf{Enter} afterward if there is no active command line prompt)
1077+
\item \alert{\texttt{\&\&}} -- second command is launched only when first command exits without error (exits with status \texttt{0}): \texttt{mkdir NewDir \&\& cd NewDir}
1078+
\item \alert{\texttt{;}} -- second command is launched regardless exit status of the first one: \texttt{kshfskcbd; hostname}
1079+
\item \alert{\texttt{\textbraceleft\ldots\textbraceright}} -- commands within curl brackets are launched as one block
1080+
\item \alert{\texttt{||}} -- second command is launched when first command fails (has non zero exit status):\\\texttt{cd newdir || \textbraceleft~mkdir newdir \&\& cd newdir; \textbraceright}
10631081
\item Behavior in shells other than bash might be little bit different
1064-
\item \alert{|} -- pipe -- redirects standard output of one command into standard input of second command: \texttt{ps aux | sort}
1082+
\item \alert{\texttt{|}} -- pipe -- redirects standard output of one command into standard input of second command: \texttt{ps aux | sort}
10651083
\end{itemize}
10661084
\end{frame}
10671085

10681086
\begin{frame}[fragile]{Standard input and output and redirects}
10691087
\begin{itemize}
10701088
\item Standard input (\texttt{stdin}) is standard place where software takes input (keyboard and terminal) and writes results to standard output (\texttt{stdout}) -- typically monitor
10711089
\item Standard error output (\texttt{stderr}) is target of error messages -- typically also monitor (but can be log file or so)
1072-
\item \alert{\textgreater} -- redirects output into new place (file, device, another command)
1090+
\item \alert{\texttt{\textgreater}} redirects output into new place (file, device, another command,~\ldots)
10731091
\end{itemize}
10741092
\begin{bashcode}
10751093
cat /etc/group # Print whole file /etc/group
@@ -1078,7 +1096,7 @@ \subsection{Chaining}
10781096
cat users # See result
10791097
\end{bashcode}
10801098
\begin{itemize}
1081-
\item \alert{\textgreater\textgreater} -- adds output to the end of the file (``\textgreater'' rewrites target file)
1099+
\item \alert{\texttt{\textgreater\textgreater}} adds output to the end of the file (\texttt{\textgreater} rewrites target file)
10821100
\end{itemize}
10831101
\begin{bashcode}
10841102
grep root /etc/group >> users # Add new information into existing file
@@ -1105,10 +1123,10 @@ \subsection{Chaining}
11051123
command >> outputfile 2>error.log
11061124
\end{bashcode}
11071125
\begin{itemize}
1108-
\item /dev/null -- ``black hole'' -- discards everything (don't care about errors?): \texttt{command 2\textgreater~/dev/null}
1109-
\item /dev/stdin -- standard input (in case application reads files, not from standard input): \texttt{echo "Žluťoučký kůň" | iconv -f utf-8 -t cp1250 /dev/stdin}
1110-
\item /dev/stdout -- standard output (we wish to see errors which would be discarded otherwise): \texttt{command 2\textgreater~/dev/stdout}
1111-
\item /dev/stderr -- standard error output (right place to send errors to): \texttt{echo "error" > /dev/stderr}
1126+
\item \texttt{/dev/null} -- ``black hole'' -- discards everything (don't care about errors?): \texttt{command 2\textgreater~/dev/null}
1127+
\item \texttt{/dev/stdin} -- standard input (in case application reads files, not from standard input): \texttt{echo "Žluťoučký kůň" | iconv -f utf-8 -t cp1250 /dev/stdin}
1128+
\item \texttt{/dev/stdout} -- standard output (we wish to see errors which would be discarded otherwise): \texttt{command 2\textgreater~/dev/stdout}
1129+
\item \texttt{/dev/stderr} -- standard error output (right place to send errors to): \texttt{echo "error" > /dev/stderr}
11121130
\end{itemize}
11131131
\end{frame}
11141132

@@ -1118,6 +1136,7 @@ \subsection{Information and management}
11181136
\begin{bashcode}
11191137
uname -a # Information about Linux kernel (version, ...)
11201138
lsb_release -a # Information about Linux distribution release
1139+
cat /etc/os-release # Similar to above command
11211140
lscpu # Information about CPU
11221141
cat /proc/cpuinfo # Raw list of information about CPU
11231142
lsusb # List of devices on USB
@@ -1132,6 +1151,7 @@ \subsection{Information and management}
11321151
uptime # How long is the system running, number of users, average load
11331152
date # Date and time - plenty of options for formatting
11341153
mount # Information about mounted file systems
1154+
findmnt # Display mounted devices in tree structure
11351155
\end{bashcode}
11361156
\end{frame}
11371157

@@ -1158,24 +1178,6 @@ \subsection{Information and management}
11581178
\end{bashcode}
11591179
\end{frame}
11601180

1161-
\begin{frame}[fragile]{Managing system services}
1162-
\begin{itemize}
1163-
\item Different among distributions -- several main methods
1164-
\item Most common is SystemD, less common older init scripts and RC scripts
1165-
\item Used to manage services like web server, database, \ldots
1166-
\item \alert{Read documentation for your distribution!}
1167-
\item All actions require root authentication
1168-
\end{itemize}
1169-
\begin{bashcode}
1170-
# SystemD - huge amount of possibilities
1171-
systemctl enable/disable/status/start/stop servicename # TAB helps
1172-
# RC scripts
1173-
rcservicename status/start/stop # TAB helps to select service
1174-
# Init scripts
1175-
/etc/init.d/servicename status/start/stop # TAB helps to select service
1176-
\end{bashcode}
1177-
\end{frame}
1178-
11791181
\begin{frame}[fragile]{Users}
11801182
\begin{bashcode}
11811183
whoami # What is my user name
@@ -1206,18 +1208,18 @@ \subsection{Directories}
12061208
cd # Change directory (just "cd" or "cd ~" goes to home directory)
12071209
cd .. # One directory up; cd ../..; cd ../../another/directory/
12081210
cd relative/path/from/current/position # Go to selected directory
1209-
cd /absolute/path/from/root # Absolute path stars by "/"
1211+
cd /absolute/path/from/root # Absolute path starts by "/"
12101212
tree # Tree like hierarchy of files and directories
12111213
tree -d # List only directories; see tree --help
12121214
tree -L 2 # Only up to second level; combine: tree -d -L 3
12131215
du -sh # Disk usage by current directory, -s for sum, -h for nice units
1214-
mkdir # Make directory
1215-
rmdir # Remove empty directory
1216+
mkdir NewDirectory # Make directory
1217+
rmdir DirectoryToRemove # Remove empty directory
12161218
ls # List directory content
12171219
# Try parameters -l, -a, -1, -F, -h (with -l or -s), --help
12181220
rm -r # Recursive delete - remove also non-empty directories
12191221
mv from to # Move files/directories (also for renaming)
1220-
cp from to # Copy, -r (recursive, including subdirectories)
1222+
cp from to # Copy, -r (recursive, including subdirectories)
12211223
# -a (keeps all attributes), -v (verbose)
12221224
file somefile # Information about questioned file (what it is, ...)
12231225
xdg-open somefile # Open file by graphical application as in GUI
@@ -1230,9 +1232,9 @@ \subsection{Directories}
12301232
\item \texttt{mc} to launch MC
12311233
\item Move, copy, delete, files/directories, connect to SSH/(S)FTP, \ldots
12321234
\item Can be used with mouse
1233-
\item Edit text files (F4)
1234-
\item F2 for quick menu
1235-
\item F9 for top menu with many possibilities
1235+
\item Edit text files (\texttt{F4})
1236+
\item \texttt{F2} for quick menu
1237+
\item \texttt{F9} for top menu with many functions
12361238
\item And much more\ldots
12371239
\item Not possible to live without it :-)
12381240
\end{itemize}
@@ -1260,26 +1262,28 @@ \subsection{Archives}
12601262
\begin{itemize}
12611263
\item \texttt{gzip}, \texttt{bzip2} and \texttt{lzma} are able to pack only one file -- use them together with \texttt{tar} to pack multiple files
12621264
\item \texttt{gzip}, \texttt{bzip2} and \texttt{lzma} when used \textbf{without} \texttt{tar} \alert{move} file into archive
1263-
\item \texttt{lzma} has excellent compression, but sometimes it is very slow
1265+
\item \texttt{lzma} has excellent compression, but sometimes is very slow
12641266
\end{itemize}
12651267
\end{frame}
12661268

12671269
\begin{frame}{Compressing and decompressing archives}
1268-
\begin{center}
1269-
\begin{tabular}{llll}
1270-
\textbf{Archive} & \textbf{Decompressing command}\\
1271-
*.tar & tar xvf archive.tar\\
1272-
*.tar.gz\alert{/}*.tgz & tar xzvf archive.tar.gz\alert{/}.tgz\\
1273-
*.tar.bz\alert{/}*.tbz\alert{/}*.tar.bz2 & tar xjvf archive.tar.bz\alert{/}.tbz\alert{/}.tar.bz2\\
1274-
*.tar.xz & lzcat archive.tar.xz | tar xvf -\\
1275-
*.gz & gunzip archive.gz\\
1276-
*.bz2 & bunzip2 archive.bz2\\
1277-
*.xz & unlzma archive.xz\\
1278-
*.zip & unzip archive.zip\\
1279-
*.rar & unrar x archive.rar\\
1280-
\end{tabular}
1281-
\includegraphics[height=2cm]{tar.png}
1282-
\end{center}
1270+
\begin{center}
1271+
\begin{tabular}{llll}
1272+
\textbf{Archive} & \textbf{Decompressing command}\\
1273+
*.tar & tar xvf archive.tar\\
1274+
*.tar.gz\alert{/}*.tgz & tar xzvf archive.tar.gz\alert{/}.tgz\\
1275+
*.tar.bz\alert{/}*.tbz\alert{/}*.tar.bz2 & tar xjvf archive.tar.bz\alert{/}.tbz\alert{/}.tar.bz2\\
1276+
*.tar.xz & lzcat archive.tar.xz | tar xvf -\\
1277+
*.gz & gunzip archive.gz\\
1278+
*.bz2 & bunzip2 archive.bz2\\
1279+
*.xz & unlzma archive.xz\\
1280+
*.zip & unzip archive.zip\\
1281+
*.rar & unrar x archive.rar\\
1282+
\end{tabular}
1283+
\end{center}
1284+
\includegraphics[height=2cm]{tar.png}
1285+
\hfill
1286+
\url{https://xkcd.com/1168/}
12831287
\end{frame}
12841288

12851289
\subsection{Searching}
@@ -1311,7 +1315,7 @@ \subsection{Searching}
13111315
find photos/ -name *.jpg -exec mogrify -resize 1000x1000 '{}' \;
13121316
\end{bashcode}
13131317
\begin{itemize}
1314-
\item First \texttt{find}'s parameter is location, to search -- absolute or relative, ``\texttt{.}'' means current directory (the only compulsory parameter)
1318+
\item First \texttt{find}'s parameter is location to search -- absolute or relative, ``\texttt{.}'' means current directory (the only compulsory parameter)
13151319
\item \texttt{-type} for only directories or only files (without this parameter, files as well as directories are looked for)
13161320
\item \texttt{-name} supports wildcarts (\texttt{*}, \texttt{?} and \texttt{[\ldots]})
13171321
\item \texttt{-print} is default action -- prints list of results

presentation/real_programmers.png

82.5 KB
Loading

0 commit comments

Comments
 (0)