What is Unix?#

Unix is a family of operating systems - sets of programs that manage the use of computer hardware resources by software applications. It thereby allows multiple users to access a computer simultaneously, perform parallelized computations, exchange data and share hardware resources. This diagram shows an oversimplified view of an operating system - the kernel (in blue) is a core program that is always active and controls interactions between the hardware (in green), and software (in red).

../../_images/Unix_Schematic.PNG

Technically, our servers use a version of Linux, a Unix-like operating system. Furthermore, even major operating systems such as Android and MacOS are Unix-based underneath.

The command#

Commands are our tool to tell the computer what to do. Most commands have options and arguments. Arguments are often essential for a command to operate properly; they are the pieces of information required by a command, such as a file name. Options are, of course, optional, and offer ways to modify the way the command works.

../../_images/command_structure_echo_with_examples.png

For instance, echo will take any text you give it as an argument and then send it back to you as output:

echo "Hello World!"

Comments#

Since many different commands exist and it is difficult to remember all of them by heart, we often want to add comments to our command which do not have any effect on the output. A comment starts with the character ‘#’ and everything that follows afterwards on the same line is ignored by the computer (meaning that comments can be used as side notes for ourselves).

One way how to use a comment is as a header, in which case the comment is placed one line above the command and the line of the comment starts with the character ‘#’.

# My first command
echo "Hello World!"

Secondly, comments are used to describe what a command does. In this case, the character ‘#’ is placed right after the command on the same line as the command itself and everything that follows afterwards will be ignored.

echo "Hello World!" # prints out the text given as an argument

Lastly, if comments are longer and describe a command in more detail than just a few words, often comments are placed on the line below a command, starting with the character ‘#’.

echo "Hello World!"
# This command prints out the text you give it as an argument, f.ex. Hello World!

New line character#

Another important concept to understand is the new line character. The ‘new line’ character is interpreted as any other character in a single word or text and is most comparable to a white space so any space between words in written text. It is commonly denoted as ‘n’, but comparable to a white space because you do not see it appear in the written text thus it is invisible. Instead of adding a space between words it actually adds a new line, so any text after a ‘new line’ character will end up on the next line.

Note that in default mode (without specified options) echo prints the output with a ‘new line’ character on the end, thus the command line interface ends up one line below the output from echo. This means that echo automatically adds a ‘new line’ character to the end of your argument “My first command”.

If you use the option -n, then it will not add a ‘new line’ to the end of the output:

# My second command
echo -n "Hello World!"

Note that with the option -n, echo prints the output without a ‘new line’ character on the end, thus the command line interface ends up on the same line as the output from echo. Note that the command line is case-sensitive! So it does matter if you write -n or -N.

Some commands end up with very complex structures, because they can have many options and arguments. Therefore, options will either be of the format -w where w is a single letter or –word where word is a string (a series of letters, in computer terms).

Exercise 1.1#

Exercise 1.1

  • Try to use echo to print “My first command”.

echo "My first command"

# Result
My first command
[]$

# Note that the output contains a new line character at the end (invisible), thus the command line interface ends up on a new line after the output
  • Try to use echo to print “My first command” with the -n option. What do you notice?

echo -n "My first command"

# Result
My first command[]$

# Note that echo -n does not add a new line to the output, thus the command line interface ends up on the same line as the output of the command
  • Try to use echo to print “My first command” with the -N option. What do you notice?

echo -N "My first command"

# Result
-N My first command
[]$

# The -N option does not exist, therefore echo will ill interpret '-N' as characters to display