Terminal 102
Time N/A

Difficulty Advanced
Prerequisites Learn Linux
Departments Human Technologies
Authors Ross Parker
Daniel Roskams
Groupings Individual
Pairs
Minimum Year Group None

Blurb

Terminal gives us access to the command line interface (CLI), which is a very powerful way to control our computers. In this unit you will expand your knowledge of how to exploit the CLI to get crazy useful things done fast.

License

This work is shared under the following license: Creative Commons BY-SA-NC

Outline

The Pitch
Why should I bother learning this?
  • Every major computer system (think Google, Twitter) is run by a system administrator (or sysadmin for short).
  • Sysadmins wield huge power, and are backed by their skills in the terminal.
  • Through this unit you can start really adding power to your CLI use.
Resources
What is needed to run this unit?
  • Laptop (running a variation of *nix, such as Linux, Mac OS, BSD or Unix).
  • Internet access
  • Virtual Box (free, open source)
  • Ubuntu Linux (free, open source)
Interdisciplinary Links
Do not try and force this. What areas of other subjects might this reflect and/discuss language. For IB, links with ToK.
Teacher Reflection
What was successful? What needs changing? Alternative Assessments and Lesson Ideas? What other Differentiation Ideas/Plans could be used?
  • This is a new unit, with the content provided almost exclusively by Daniel Roskams, a student in Year 9, as a follow up to his Terminal 101 unit.
Credits
Any CC attribution, thanks, credit, etc.
  • Software Development thumbnail by fullvector on freepik under Freepik License.
  • Text by Daniel Roskams, shared under Public Domain (No more reading licenses! Hooray!)

This page requires you to be logged in to access it. Please login and try again.
Want To Run Big Systems?
The Pitch
  • Every major computer system (think Google, Twitter) is run by a system administrator (or sysadmin for short).
  • Sysadmins wield huge power, and are backed by their skills in the terminal.
  • Through this unit you can start really adding power to your CLI use.

Your Virtual Machine
Getting Ready
  • You should already have a virtual box setup from Terminal 101. If you deleted it, then use the instructions below to get up and running again.

Mac

  • VirtualBox is a free, open source system for running one operating system in another. Download the Mac version of VirtualBox and install it on your computer.
  • Inside our virtual box, we will run the CLI version of Ubuntu Linux, which is also free and open source. Download Ubuntu Server and save the resulting .iso file on your desktop.
    • Most downloads are done over HTTP, which is OK.
    • But, if you want to get a faster download you can try BitTorrent: if there are lots of people sharing the same file, it will be super quick.
    • If you want to use BitTorrent, try the Transmission client for Mac.
    • Please note, BitTorrent is fine to use for downloading freely shared materials (e.g. open source, Creative Commons, public domain, etc), but it is illegal to use it to share copyrighted materials.
  • The video below might help you in your installation.

Chromebook

  • Installing a Linux VM on a Chromebook is easy
    • It's actually a beta feature of the Chromebook, since Chrome OS is a Linux-based operating system
    • Follow these instructions and set up your Linux terminal on your Chromebook

What Is The "command line"?
Theory

Most people call a terminal a `command line'. Although these sound similar, they are not the same. There are many interfaces with which to run commands on the system, and these interfaces are called _shells_.

A shell is, at a simple level, a program that runs in the terminal to read and execute commands. The default shell that comes with many GNU/Linux systems is called /bash/, which stands for the /Bourne-Again Shell/. (You can find more information about this here and here.

However, bash can be a little tedious to use, occasionally. Even though it has tab completion (the ability to complete commands by pressing [tab]), it wasn't designed with new users in mind. Therefore, we will use a shell called /fish/, which stands for the Friendly Interactive SHell. (Wikiepdia article, Fish official site)

In Ubuntu, you can install /fish/ by typing in the command:

  • sudo apt-get -q -y install fish

Type in your password, and fish should be downloaded and installed.

Syntax of Commands
More Theory

Here is a quick review of how commands are structured (there was already one in Terminal 101) but with the minor addition of command-line options.



Normally, when you log in, the /bash/ shell is started. To change this, we use the /chsh/ command, which stands for CHange SHell.

  • chsh -s $(command -v fish)

This changes the shell run at login time to wherever `fish' is stored. The syntax, $(command -v fish), asks the /bash/ shell to replace that with the output of the command inside the parentheses. To see what happens when you run `command -v fish', you can type this:

  • command -v fish

The output will probably be:

  • /usr/bin/fish

From now on, I will assume that you have /fish/ running. If you are still using /bash/, you can start /fish/ using the following command:

  • exec fish -l
Command-line Options and Flags
Options, options

An option or flag is a special argument that changes the operation of programs in a way different from simply specifying different arguments. For example, if you execute this command:

  • ls

while in your home directory, you will see the contents of your home directory with each entry seperated by a tab. However, if you execute this command instead:

  • ls -l

you will see the same files, but a different format: more information is shown for example the file size and owner. The -l is an /option/. There are many varying options to different commands, and it is very difficult to remember all of them. This is where the manual pages come in.

Manual Pages
man

Most UNIX-like systems come with built-in documentation, called the man pages. `man' is short for `manual', and it is the `man' command that formats and displays manuals in an easily human-readable format. Here is an example:

  • man cat


This will display the documentation for the `cat' command. However, the manual is not very easy to understand. Here are a few keywords, commonly used in many manuals and other technical documentation, that are essential to comprehend the manual:

  • standard input -- usually referring to the user's keyboard.
  • standard output -- usually referring to the current virtual terminal.
  • standard error -- usually referring to the current virtual terminal also.

These can be respectively abbreviated as `stdin', `stdout' and `stderr' respectively. Notice how the definitions all include a `usually'. Sometimes, standard input and output does not refer to the keyboard and screen. How this is done is a very important part of the command-line interface, but because the details are quite advanced, they are covered later on.

Filesystem Layout
ext4

A quick intro on the file and directory layout is needed. In UNIX-like systems (including GNU/Linux) the directory that contains everything is the slash. In fish, type the following:

  • cd /

The /cd/ command changes the current directory of the shell to /. The current directory is where all commands will operate. For example, if you enter these commands:

  •   cd ~
  •   ls
  •   cp /etc/hosts ./junk
  •   ls

You will find that there is a new file, `junk', listed. The content of that file is not important. Now, you can change to a different directory:

  • cd /tmp

/tmp is a directory for storing temporary stuff. We can use it for testing purposes, because all things here will probably get deleted the next time you start the virtual machine. Therefore, you /can/ use /tmp as a ``trash can''.

Now try to remove the ``junk'' file:

  • rm junk
  • rm: cannot remove `junk': file or directory


Well, the file was not found. This is because we have changed the directory to somewhere else. Now enter this command:

  • rm ~/junk

The command does not have any output. Typically, this means that everything went OK.

All these commands are equivalent to clicking on folders in a file manager (like Finder). Here is a small table, detailing what each command does and its equivalent in a file manager:



This table is confusing. It doesn't actually say /how/ to use each command. Here are the explanations of the commands:

cd -- Change Directory

The way you use this command is: you type in /cd/, and then a space, and then the name of a directory. In other words, the command is ``cd'', and the first argument is the name of the directory to change to.

For example, to change to the /tmp directory:

  • cd /tmp

or to change to the ~/Documents directory:

  • cd ~/Documents

rm -- ReMove files

This command can take more than one argument. However, the basic use is to supply the first argument as the file to delete.

To remove a file called ``stuff.txt'':

  • rm stuff.txt

To remove two files, ``junk.txt'' and ``garbage.txt'':

  • rm junk.txt garbage.txt

To remove a directory, you need to use the -r option, or otherwise an error will occur.

  • rm -r /path/to/directory

This will remove the directory and all the files under it at /path/to/directory.

ls -- LiSt files

This command does not need to have any arguments. For example, to list the contents of the directory the shell is in, you can run:

  • ls

You can specify one or more arguments, which should be the folders (or files) to display.

  • ls /tmp
  • ls /etc
  • ls /usr /bin

These three commands list the contents of /tmp, /etc, and both /usr and /bin, respectively. In addition, there are also several options that you can pass to /ls/. You can find these in the manual pages, `man ls'.

mv -- MoVe files

This command moves files into a different location. You can also use it to change the names of files. Therefore, there is no `rename' command!

  • mv ~/stuff.txt ~/doc/junk.txt

This moves the file `~/stuff.txt' to `~/doc/' and also changes the name to `junk.txt'. Another simple example:

  • mv resources/ images/

This changes the name of the directory, `resources', into `images'.

cp -- CoPy files

The /cp/ command copies one or more files and places it into the specified location. However, be careful when copying directories and their contents, this will be covered slightly later:

  • cp (command -s fish) ~/fish

This copies the /fish/ program into the `fish' file in your home directory. This isn't very useful, but it demonstrates the point. Now, to copy entire directories, an option is required:

  • cp -r /tmp/stuff /tmp/morestuff

This copies the entire contents of the directory /tmp/stuff and places it into the directory /tmp/morestuff.

Doing Useful Work
Hands On

The commands covered so far are quite basic. They do not enable you to do anything except move files around. Now, we will cover text editing, which at least enables you to do some kind of useful work. There are several text editors available for GNU/Linux, but here, we will cover the one called /nano/ because it is the easiest one to use.

First, create a file for us to edit:

  • echo "Hello World" > file.txt

This command echoes the text "Hello World", and this would normally go to the terminal. However, the `>' character changes this, and instead of going to the terminal, the text goes into a file, which is created if it is nonexistent. In other words, the /standard output/ of the /echo/ command is redirected to point at a file, instead of the terminal (which is actually a special file).

Now, with the test file created, /nano/ can be started:

  • nano file.txt

You will see a program open and take up your entire screen. The text you echo'd into the file will appear. Now you can do whatever you would do in a normal text editor, but there is no formatting (bold, italic). You must move the cursor with the arrow keys.

Look at the row of keyboard shortcuts at the bottom few lines of the screen. From this, you can find that saving the file is as simple as pressing Control-o, and then pressing Enter. To exit the editor, press Control-x.

Doing Useful Work 2
More Hands On

You may be wondering if I had forgotten about the internet. Of course, it is also possible to browse the web in the terminal as well! To do this, a program called `links' needs to be installed. This can be done with the apt-get command:

  • sudo apt-get install -qy links

The first command, `sudo', asks for your password, before running everything else on the line. `sudo' gives the command extra privileges, which are required for installing programs.

After that is completed, you can browse a website:

  • links https://gibbon.ichk.edu.hk

This will go to Gibbon, where you can again use the arrow keys to navigate until you reach the login box. Type in your username and password, and then press the login button (with the Enter key). You should now see your lessons (but not the timetable, this issue is detailed below).

To open a menu in Links, press F10 or equivalent. You can then use the arrow keys to navigate the menu, and from there you can get help, etc. Keyboard shortcuts are listed next to menu entries, if any.

Lack of Javascript

Unfortunately, the /links/ browser cannot use JavaScript, and most other text based browsers do not support it either. This is, of course, a rather serious impediment to ordinary work. I do not know of any way to fix this, however there is a (rather messy) way of viewing the timetable in Gibbon.

After logging in to Gibbon, press `g' to open the menu for going to a webpage. Set it to:

  https://gibbon.ichk.edu.hk/index_tt_ajax.php

and your timetable should appear. Press Backspace to go back one page.

Doing Useful Work 3
Even More Hands On

Checking email will in fact work, if you use Gmail. It will look remarkably similar to the normal version, but of course without any fancy stuff. If you would prefer using a mail client to access your mail, for example to speed things up, you can use /mutt/. [5] [6] Installation is simple:

  • sudo apt-get install -qy mutt

However, configuring it to work properly with your email account is non-trivial and varies significantly between different mail providers, so you will need to look up the details by yourself.

To open a menu in Links, press F10 or equivalent. You can then use the arrow keys to navigate the menu, and from there you can get help, etc. Keyboard shortcuts are listed next to menu entries, if any.

Evidence
Finishing Up
  • Spend some time now to create some evidence of what you have learned (video screenshot of you running some commands, and explaining what they do?) and then submit to Gibbon.
There are no records to display.
Powered by Gibbon v27.0.00dev

Founded by Ross Parker at ICHK Secondary | Built by Ross Parker, Sandra Kuipers and the Gibbon community
Copyright © Gibbon Foundation 2010-2024 | Gibbon™ of Gibbon Education Ltd. (Hong Kong)
Created under the GNU GPL | Credits | Translators | Support