Skip to content

Commit 8f153e1

Browse files
corrected typos, added links to exercise files
1 parent d7680ec commit 8f153e1

8 files changed

+8
-8
lines changed

command-line-overview.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128

129129
# type 'w' and press tab to get 'words'
130130
$ ls /etc/dictionaries-common/words
131-
</code></pre><p>The character at which the tab key is pressed in the above example has been cherry picked for illustration purposes. The number of steps would increase if you try pressing tab after each character. With experience, using the tab key for autocompletion will become a natural part of your command line usage.<blockquote><p><img alt=info src=./images/info.svg> You can set an option to combine the features of single and double tab presses into a single tab press. This will be discussed in the <a href=./shell-customization.html>Shell Customization</a> chapter.</blockquote><h2 id=real-world-use-cases><a class=header href=#real-world-use-cases>Real world use cases</a></h2><p>If the command line environment only had file managing features, I'd still use it. Given the wide variety of applications available, I can't imagine going back to using a different GUI application for each use case. My primary work is writing ebooks, blog posts and recording videos. Here are the major CLI tools I use:<ul><li>text processing using <code>head</code>, <code>tail</code>, <code>sort</code>, <code>grep</code>, <code>sed</code>, <code>awk</code> and so on (you'll learn about these commands in later chapters)<li><a href=https://git-scm.com/>git</a> — version control<li><a href=https://github.com/jgm/pandoc/>pandoc</a> — generating PDF/EPUB book versions from markdown files<li><a href=https://github.com/rust-lang/mdBook>mdBook</a> — web version of the books from markdown files<li><a href=https://github.com/getzola/zola>zola</a> — static site generator<li><a href=https://imagemagick.org/index.php>ImageMagick</a> — image processing like resizing, adding borders, etc<li><a href=https://github.com/shssoichiro/oxipng>oxipng</a>, <a href=https://pngquant.org/>pngquant</a> and <a href=https://github.com/RazrFalcon/svgcleaner>svgcleaner</a> — optimizing images<li><a href=https://github.com/WyattBlue/auto-editor>auto-editor</a> — removing silent portions from video recordings<li><a href=https://github.com/FFmpeg/FFmpeg>FFmpeg</a> — video processing, padding for example (<code>FFmpeg</code> is also a major part of the <code>auto-editor</code> solution)</ul><p>Some of these workflows require additional management, for which I write shell functions or scripts. I do need GUI tools as well, for example, web browser, image viewer, PDF/EPUB viewers, <a href=https://github.com/MaartenBaert/ssr>SimpleScreenRecorder</a> and so on. Some of these can be handled from within the terminal too, but I prefer GUI for such cases. I do launch some of them from the terminal, primarily for providing the file or url to be opened.<p>You might wonder what advantage does the command line provide for processing images and videos? Apart from being faster, the custom parameters (like border color, border size, quality percentage, etc) are automatically saved as part of the scripts I create. After that, I can just use a single call to the script instead of waiting for a GUI application to open, navigating to required files, applying custom parameters, saving them after all the required processing is done, closing the application, etc. Also, that single script can use as many tools as needed, whereas with GUI you'll have to repeat such steps with different applications.<h2 id=exercises><a class=header href=#exercises>Exercises</a></h2><p><strong>1)</strong> By default, is <code>echo</code> a shell builtin or external command on your system? What command could you use to get an answer for this question?<p><strong>2)</strong> What output do you get for the command shown below? Does the documentation help understand the result?<pre><code class=language-bash>$ echo apple 42 'banana 100'
131+
</code></pre><p>The character at which the tab key is pressed in the above example has been cherry picked for illustration purposes. The number of steps would increase if you try pressing tab after each character. With experience, using the tab key for autocompletion will become a natural part of your command line usage.<blockquote><p><img alt=info src=./images/info.svg> You can set an option to combine the features of single and double tab presses into a single tab press. This will be discussed in the <a href=./shell-customization.html>Shell Customization</a> chapter.</blockquote><h2 id=real-world-use-cases><a class=header href=#real-world-use-cases>Real world use cases</a></h2><p>If the command line environment only had file managing features, I'd still use it. Given the wide variety of applications available, I can't imagine going back to using a different GUI application for each use case. My primary work is writing ebooks, blog posts and recording videos. Here are the major CLI tools I use:<ul><li>text processing using <code>head</code>, <code>tail</code>, <code>sort</code>, <code>grep</code>, <code>sed</code>, <code>awk</code> and so on (you'll learn about these commands in later chapters)<li><a href=https://git-scm.com/>git</a> — version control<li><a href=https://github.com/jgm/pandoc/>pandoc</a> — generating PDF/EPUB book versions from markdown files<li><a href=https://github.com/rust-lang/mdBook>mdBook</a> — web version of the books from markdown files<li><a href=https://github.com/getzola/zola>zola</a> — static site generator<li><a href=https://imagemagick.org/index.php>ImageMagick</a> — image processing like resizing, adding borders, etc<li><a href=https://github.com/shssoichiro/oxipng>oxipng</a>, <a href=https://pngquant.org/>pngquant</a> and <a href=https://github.com/RazrFalcon/svgcleaner>svgcleaner</a> — optimizing images<li><a href=https://github.com/WyattBlue/auto-editor>auto-editor</a> — removing silent portions from video recordings<li><a href=https://github.com/FFmpeg/FFmpeg>FFmpeg</a> — video processing, padding for example (<code>FFmpeg</code> is also a major part of the <code>auto-editor</code> solution)</ul><p>Some of these workflows require additional management, for which I write shell functions or scripts. I do need GUI tools as well, for example, web browser, image viewer, PDF/EPUB viewers, <a href=https://github.com/MaartenBaert/ssr>SimpleScreenRecorder</a> and so on. Some of these can be handled from within the terminal too, but I prefer GUI for such cases. I do launch some of them from the terminal, primarily for providing the file or url to be opened.<p>You might wonder what advantage does the command line provide for processing images and videos? Apart from being faster, the custom parameters (like border color, border size, quality percentage, etc) are automatically saved as part of the scripts I create. After that, I can just use a single call to the script instead of waiting for a GUI application to open, navigating to required files, applying custom parameters, saving them after all the required processing is done, closing the application, etc. Also, that single script can use as many tools as needed, whereas with GUI you'll have to repeat such steps with different applications.<h2 id=exercises><a class=header href=#exercises>Exercises</a></h2><blockquote><p><img alt=info src=images/info.svg> <img alt=info src=./images/info.svg> All the exercises are also collated together in one place at <a href=https://github.com/learnbyexample/cli-computing/blob/master/exercises/exercises.md>exercises.md</a>. For solutions, see <a href=https://github.com/learnbyexample/cli-computing/blob/master/exercises/exercise-solutions.md>exercise-solutions.md</a>.</blockquote><p><strong>1)</strong> By default, is <code>echo</code> a shell builtin or external command on your system? What command could you use to get an answer for this question?<p><strong>2)</strong> What output do you get for the command shown below? Does the documentation help understand the result?<pre><code class=language-bash>$ echo apple 42 'banana 100'
132132
</code></pre><p><strong>3)</strong> Go through <a href=https://www.gnu.org/software/bash/manual/html_node/Tilde-Expansion.html>bash manual: Tilde Expansion</a>. Is <code>~/projects</code> a relative or an absolute path? See <a href=https://unix.stackexchange.com/q/221970/109046>this unix.stackexchange thread</a> for answers.<p><strong>4)</strong> Which key would you use to get help while the <code>less</code> command is active?<p><strong>5)</strong> How would you bring the 50th line to the top of the screen while viewing a <code>man</code> page (assume <code>less</code> command is the <code>pager</code>)?<p><strong>6)</strong> What does the <code>Ctrl+k</code> shortcut do?<p><strong>7)</strong> Briefly explain the role of the following shell operators:<p><em>a)</em> <code>|</code><br> <em>b)</em> <code>></code><br> <em>c)</em> <code>>></code><p><strong>8)</strong> The <code>whatis</code> command displays one-line descriptions about commands. But it doesn't seem to work for <code>whatis type</code>. What should you use instead?<pre><code class=language-bash>$ whatis cat
133133
cat (1) - concatenate files and print on the standard output
134134

comparing-files.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
x1.txt x3.txt differ: byte 6, line 1
4545
$ echo $?
4646
1
47-
</code></pre><blockquote><p><img alt=info src=./images/info.svg> Use the <code>-s</code> option to suppress the output when you just need the exit status. The <code>-i</code> option will allow you to skip initial bytes from the input.</blockquote><h2 id=diff><a class=header href=#diff>diff</a></h2><p>Useful to find differences between text files. All the differences are printed, which might not be desirable for long files.<h3 id=common-options><a class=header href=#common-options>Common options</a></h3><p>Commonly used options are shown below. Examples will be discussed in later sections.<ul><li><code>-i</code> ignore case while comparing<li><code>-w</code> ignore white-spaces<li><code>-b</code> ignore changes in the amount of whitespace<li><code>-B</code> ignore only blank lines<li><code>-E</code> ignore changes due to tab expansion<li><code>-z</code> ignore trailing whitespaces at the end of line<li><code>-y</code> two column output<li><code>-r</code> recursively compare files between the two directories specified<li><code>-s</code> convey message when two files are same<li><code>-q</code> report if files differ, not the details of differences</ul><h3 id=default-diff><a class=header href=#default-diff>Default diff</a></h3><p>By default, the <code>diff</code> output shows lines from the first file input prefixed with <code><</code> and lines from the second file input prefixed with <code>></code>. A line containing <code>---</code> is used as the group separator. Each difference is prefixed by a command that indicates the differences (these commands are understood by tools like <code>patch</code>).<pre><code class=language-bash># change to the 'example_files/text_files' directory
47+
</code></pre><blockquote><p><img alt=info src=./images/info.svg> Use the <code>-s</code> option to suppress the output when you just need the exit status. The <code>-i</code> option will allow you to skip initial bytes from the input.</blockquote><h2 id=diff><a class=header href=#diff>diff</a></h2><p>Useful to find differences between text files. All the differences are printed, which might not be desirable for long files.<h3 id=common-options><a class=header href=#common-options>Common options</a></h3><p>Commonly used options are shown below. Examples will be discussed in later sections.<ul><li><code>-i</code> ignore case while comparing<li><code>-w</code> ignore whitespaces<li><code>-b</code> ignore changes in the amount of whitespace<li><code>-B</code> ignore only blank lines<li><code>-E</code> ignore changes due to tab expansion<li><code>-z</code> ignore trailing whitespaces at the end of line<li><code>-y</code> two column output<li><code>-r</code> recursively compare files between the two directories specified<li><code>-s</code> convey message when two files are same<li><code>-q</code> report if files differ, not the details of differences</ul><h3 id=default-diff><a class=header href=#default-diff>Default diff</a></h3><p>By default, the <code>diff</code> output shows lines from the first file input prefixed with <code><</code> and lines from the second file input prefixed with <code>></code>. A line containing <code>---</code> is used as the group separator. Each difference is prefixed by a command that indicates the differences (these commands are understood by tools like <code>patch</code>).<pre><code class=language-bash># change to the 'example_files/text_files' directory
4848
# side-by-side view of sample input files
4949
$ paste f1.txt f2.txt
5050
1 1

managing-files-directories.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@
198198
4.0K hello_world.py
199199
4.0K hi
200200
4.0K ip.txt
201-
</code></pre><blockquote><p><img alt=info src=images/info.svg> <img alt=info src=images/info.svg> As shown in the above examples, globs are expanded by the shell. Beginners often associate globs as something specific to the <code>ls</code> command, which is why I've delibrately used <code>echo</code> as well in the above examples.</blockquote><p>You can use the <code>-d</code> option to <em>not</em> show directory contents:<pre><code class=language-bash>$ echo b*
201+
</code></pre><blockquote><p><img alt=info src=images/info.svg> <img alt=info src=images/info.svg> As shown in the above examples, globs are expanded by the shell. Beginners often associate globs as something specific to the <code>ls</code> command, which is why I've deliberately used <code>echo</code> as well in the above examples.</blockquote><p>You can use the <code>-d</code> option to <em>not</em> show directory contents:<pre><code class=language-bash>$ echo b*
202202
backups
203203
# since backups is a directory, ls will show its contents
204204
$ ls b*

0 commit comments

Comments
 (0)