From 3d54237f2e3bda550613b634dfec185ad2952daf Mon Sep 17 00:00:00 2001 From: marcel-dempers Date: Fri, 29 Nov 2024 07:27:06 +1100 Subject: [PATCH] course updates --- .../commandline/introduction/README.md | 166 ++++++++++++++++++ .../operating-systems/introduction/README.md | 4 +- 2 files changed, 168 insertions(+), 2 deletions(-) create mode 100644 course/content/operating-systems/commandline/introduction/README.md diff --git a/course/content/operating-systems/commandline/introduction/README.md b/course/content/operating-systems/commandline/introduction/README.md new file mode 100644 index 0000000..489895b --- /dev/null +++ b/course/content/operating-systems/commandline/introduction/README.md @@ -0,0 +1,166 @@ +# 🎬 Introduction to Command Line + +## 💡 Preface + +This module is part of a course on DevOps.
+Checkout the [course introduction](../../../../README.md) for more information
+This module is part of [chapter 2](../../../../chapters/chapter-2-operating-systems/README.md) + +## What is command line ? + +[Command line](https://en.wikipedia.org/wiki/Command-line_interface) is the means of interacting with a computer or operating system by inputting lines of text.
+Each line being a command, I.E "Command" and "line"
+ +In order to talk to an operating system, we type commands in a Terminal Program.
+The terminal program basically runs the operating system shell, which is the command line intepreter
+The terminal basically acts as a text-based interface to a Shell program.
+The [Shell](https://en.wikipedia.org/wiki/Shell_(computing)) interprets commands, processes it and produces output. + +In simple terms communication flows like this: + +`User -> Terminal -> Shell -> Kernel` + +A User types commands into the Terminal.
+The terminal gives us access to the shell, which takes the command, processes it by talking to the Kernal through special API's and produces output and we can see that output in the Terminal.
+ +## Types of Shells + +There are a number of shells out there depending on your operating system.
+ +On Windows we have PowerShell and CMD (Command Prompt), on Linux we have [Bourne Shell](https://en.wikipedia.org/wiki/Bourne_shell) (sh) and [Bourne-Again Shell](https://en.wikipedia.org/wiki/Bash_(Unix_shell)) (bash). Linux also has other shells like Z shell, or zsh.
+ +In this module, I will showcase an example of Windows Shells and Linux Shells.
+So you understand the difference between Terminals and Shells
+ +## Types of Terminals + +On windows as we can see there is a built-in terminal that can run either Powershell or CMD Command Prompt. Windows also launched a newer terminal called [Windows Terminal](https://github.com/microsoft/terminal) which is available on Github.
+ +On Windows, we get different terminals like GNOME Terminal, Terminology, Terminator and more
+ +In this demo, I will show you an example of Windows Terminal and Terminator on Linux
+ +## Why Learn the Command Line + +### Troubleshooting + +Command line is very important in times when there is no access to Apps \ GUI's or User Interfaces.
+Most of the time, when accessing production servers, you may only be able to access it via a terminal through protocols like SSH.
+ +Some examples include: + +* When a production server runs out of disk space, you need command line to troubleshoot it +* When services are unable to reach network endpoints, you need command line to test network connectivity + +Command line could also be required when certain systems are mostly driven by API's.
+For example, some Microsoft Azure or Amazon AWS services have more options to configure via their API's and their GUI portals are often playing catchup.
+API's are generally built before UIs, meaning UI's may be behind or may never support certain capabilities.
+ +### Scripting and Automation + +Another reason to learn command line, is that it gives you a foundation to start automating from.
+When you want to automate something, you gather and stitch together all the commands you need and then write it in a script which allows you to run the script to perform many commands at once
+ +Some examples may include: + +* We could stitch together commands that check if folder structures exists or not and create them if they dont exist. Then automatically create configuration files with default settings in them to setup an application +* We could stitch together commands that makes a copy of important files and folders on our system, compress them as a "zip" file and upload it to remote storage to create an automated backup process. + +## Command Line Structure + +As a beginner, one of the most important things to learn about is the structure of command lines
+Generally, all or most commands conform to some standard.
+ +### Executable + +For example, all command lines start with some form of executable or binary.
+A binary of executable is a program or script.
+For example in our Introduction to `git` , we learned about the `git` command. In that case `git` is the executable. + +So we start off our command with the executable: + +``` +git +``` + +### Commands and Subcommands + +An executable may have commands, and commands by have subcommands.
+However, some executable may have no commands. This is generally true for command line executables where they generally only perform one thing, like `ls` + +If you run `ls --help` , you'll notice the usage: + +``` +Usage: ls [OPTION]... [FILE]... +List information about the FILEs (the current directory by default). +``` + +`ls` has no commands.
+ +Commands or Subcommands are generally after the executable. For example: + +``` + + +``` +GIT on the other hand, has many commands and some commands also have subcommands.
+ +For example: + +``` +git checkout +git pull +git commit +git push +#etc +``` + +### Arguments, Options, Flags or Parameters + +When a command needs inputs, the command may require arguments, options, flags or parameters.
+Those terms are often used interchangably.
+Command line options generally start with dashes.
+Generally a single `-` character indicates a short abbreviated form of an option and a double `--` is a long form version of the same option.
+ +For example, `-h` and `--help` generally mean the same thing, but one is abbreviated, so shorter to type out and the other is longer, which means its more descriptive but longer to type out.
+ +If we take a look at `git` that we learned about: + +``` +git commit -m "commit message here" +``` + +Above, `-m` stands for message. + +## Collection of important commands + +* `echo` : This command allows us to print text to the screen or print variable contents + - For example, `echo "hello"`, or `echo $HOME` +* `cat` : This command displays file contents. It can display one or multiple files contents and concatenates them + - For example `cat ` +* `ls` : Allos to list contents of a directory +* `cd` : Change working directory +* `pwd` : Writes the full path of the currend working directory to the screen +* `touch` : Creates a file without content +* `nano` : Starts a simple Linux text editor +* `cp` : Copies a file or directory +* `mv` : Renames a file or directory. Useful for renaming files or moving content +* `rm` : Removes a file or directory + +## Command inputs and outputs + +We can capture outputs of a command.
+For example when running `ls`, it outputs to the terminal.
+We can capture that output by placing the `>` character after the command followed by a file name that we want to pass output to
+ +``` +ls -l / > output.txt +``` + +The single `>` will override the file and replace all its current content with the input provided.
+If we want to preserve the current content and simply append input to it, we use the double `>` +For example: + +``` +echo "add more content" >> output.txt +``` \ No newline at end of file diff --git a/course/content/operating-systems/introduction/README.md b/course/content/operating-systems/introduction/README.md index b83f43d..c81a900 100644 --- a/course/content/operating-systems/introduction/README.md +++ b/course/content/operating-systems/introduction/README.md @@ -39,7 +39,7 @@ In DevOps, SRE and even cloud engineering, Operating systems will play a fundame Your workstation or laptop, may be Microsoft Windows, or MacOS, or you may have Linux installed
Therefore all the tools you may use will be dependant or compatible with either one for different operating systems
-In addition to that, production systems you may interact with will have an Operating system installed
+In addition to that, production systems you may interact with, will have an Operating system installed
Therefore, scripts, automation and deployment pipelines, open-source tools, infrastructure as code and all the DevOps technologies we will use in this course, needs to cater for operating systems
To support and monitor production systems in real world scenarios, you need to have an understanding of how to use different operating systems
@@ -211,4 +211,4 @@ Another way for us to interact with the Operating system is through the Terminal This forms another important part of this course as it will be one of the primary ways we will interact with systems in upcoming chapters
In upcoming modules, we will learn about the command line and how to use a terminal.
-This will form the basis and foundation of our automation and scripting skills
\ No newline at end of file +This will form the basis and foundation of our automation and scripting skills