Difference: LinuxSystem (1 vs. 8)

Revision 82017-09-15 - uli

Line: 1 to 1
 
META TOPICPARENT name="CourseExercises"

Exercises 1: Discovering Linux

Goal:

Line: 26 to 26
  In your home directory, create subdirectories exercises, bin,src (use mkdir). Within exercises, create directories problems, solutions, doc. Within each of these create a subdirectory exercise_1. Put the file exercises_1.odt, attached to this page (see below) into ~/exercises/problems/exercise_1 (~ stands for your home directory). Print this structure using tree.
Changed:
<
<
Open a LibreOffice document and write down what you have done. Save this document under the name $HOME/exercises/doc/exercise_1.odt. Continue to document you work during this exercise such that at the end of the exercise session you have a document describing all your work.
>
>
Open a LibreOffice document and write down what you have done. Save this document under the name $HOME/exercises/doc/exercise_1/exercise_1.odt. Continue to document you work during this exercise such that at the end of the exercise session you have a document describing all your work.
 

Exercise 3: Environment variables and shell startup

Have a look at all environment variables defined (printenv). What are the values of HOME, PATH, LANGUAGE, LOGNAME?

Revision 72017-09-07 - uli

Line: 1 to 1
 
META TOPICPARENT name="CourseExercises"

Exercises 1: Discovering Linux

Goal:

Line: 29 to 29
 Open a LibreOffice document and write down what you have done. Save this document under the name $HOME/exercises/doc/exercise_1.odt. Continue to document you work during this exercise such that at the end of the exercise session you have a document describing all your work.

Exercise 3: Environment variables and shell startup

Changed:
<
<
Have a look at all environment variables defined (printenv). What are the values of HOME, PATH, LANGUAGE, LOG_NAME?
>
>
Have a look at all environment variables defined (printenv). What are the values of HOME, PATH, LANGUAGE, LOGNAME?
  To get the value of an environment variable print it (echo command) with a $ in front (e.g. echo $HOME).
Line: 49 to 49
  Now create a new environment variable MY_VARIABLE:
Changed:
<
<
export MY_VARIABLE=It’s_Me\! and print it. Get rid of it using unset.
>
>
export MY_VARIABLE=It\’s_Me\! and print it. Get rid of it using unset. (You need the "\" to make sure bash does not interpret the characters following the \, you escape the interpretation)
 

Exercise 4: Redirection and pipes

To each executable 3 input output channels are associated:

Revision 62017-09-07 - uli

Line: 1 to 1
 
META TOPICPARENT name="CourseExercises"

Exercises 1: Discovering Linux

Goal:

Line: 71 to 71
 Finally remove runningNow.txt (using rm) and type ps ax| tee runningNow.txt . What is the difference to ps ax > runningNow.txt?

Exercise 5: File permissions

Added:
>
>
File permissions are given in the octal number system while very often we use the hexadecimal number system, e.g. when writing individual bits into chip registers. Here are a few exercises to get you acquainted with these system

What is the octal value of 101 001 110 ?

How much is 7+5 when calculated in octal?

Convert the octal value of 345 to decimal

Write down the binary representation of the hex value 0x83ab

How much is 7+5 in hexadecimal?

What is the decimal value of 0xa3?

Now on to permissions, which are given in octal:

 Do an ls -l in your solutions/exercise_1 directory. Then do the same thing on /bin. Who can read, modify, write each file?

Now create a new file yesterday.sh in solutions/exercise_1/with:

Line: 101 to 117
 
<--/commentPlugin-->

META FILEATTACHMENT attachment="yesterday.txt" attr="" comment="" date="1504691903" name="yesterday.txt" path="yesterday.txt" size="680" user="uli" version="1"
Deleted:
<
<
META FILEATTACHMENT attachment="exercises_1.odt" attr="" comment="" date="1504693724" name="exercises_1.odt" path="exercises_1.odt" size="81558" user="uli" version="1"
 
META FILEATTACHMENT attachment="bashrc.png" attr="" comment="" date="1504695772" name="bashrc.png" path="bashrc.png" size="35319" user="uli" version="1"
Added:
>
>
META FILEATTACHMENT attachment="exercises_1.odt" attr="" comment="" date="1504787172" name="exercises_1.odt" path="exercises_1.odt" size="81800" user="uli" version="1"

Revision 52017-09-06 - uli

Line: 1 to 1
 
META TOPICPARENT name="CourseExercises"

Exercises 1: Discovering Linux

Goal:

Line: 24 to 24
 Linux also has hidden files, how can you see them? (Hint: Linux has zillions of commands and even more options and you will never know them all. Use the man (man stands for “manual”) to learn more about a command and its options).

Exercise 2: Create a file system structure for all exercises of this course

Changed:
<
<
In your home directory, create subdirectories exercises, bin,src (use mkdir). Within exercises, create directories problems, solutions, doc. Within each of these create a subdirectory exercise_1. Put the file exercises_1.odt, attached to this page (see below) into ~/exercises/problems/exercises_1 (~ stands for your home directory). Print this structure using tree.
>
>
In your home directory, create subdirectories exercises, bin,src (use mkdir). Within exercises, create directories problems, solutions, doc. Within each of these create a subdirectory exercise_1. Put the file exercises_1.odt, attached to this page (see below) into ~/exercises/problems/exercise_1 (~ stands for your home directory). Print this structure using tree.
  Open a LibreOffice document and write down what you have done. Save this document under the name $HOME/exercises/doc/exercise_1.odt. Continue to document you work during this exercise such that at the end of the exercise session you have a document describing all your work.

Exercise 3: Environment variables and shell startup

Revision 42017-09-06 - uli

Line: 1 to 1
 
META TOPICPARENT name="CourseExercises"

Exercises 1: Discovering Linux

Goal:

Revision 32017-09-06 - uli

Line: 1 to 1
 
META TOPICPARENT name="CourseExercises"

Exercises 1: Discovering Linux

Goal:

Line: 10 to 10
 Our first goal is therefore to become acquainted with Linux, its file structure, its commands etc. and this can be done on the PC for which we have created a dedicated bootable USB disk.

Exercise 1: Explore the Linux file system

Changed:
<
<
The Linux file system has a tree like structure with “/” at its root (the rot of the file structure is NOT /root, which is the home directory of the super user.
>
>
The Linux file system has a tree like structure with “/” at its root (the root of the file structure is NOT /root, which is the home directory of the super user.
  Start a terminal and try out a few commands.
Line: 24 to 24
 Linux also has hidden files, how can you see them? (Hint: Linux has zillions of commands and even more options and you will never know them all. Use the man (man stands for “manual”) to learn more about a command and its options).

Exercise 2: Create a file system structure for all exercises of this course

Changed:
<
<
In your home directory, create subdirectories exercises, bin,src (use mkdir). Within exercises, create directories problems, solutions, doc. Within each of these create a subdirectory exercise_1. Put this file into $HOME/exercises/problems/exercise_1. Print this structure using tree.
>
>
In your home directory, create subdirectories exercises, bin,src (use mkdir). Within exercises, create directories problems, solutions, doc. Within each of these create a subdirectory exercise_1. Put the file exercises_1.odt, attached to this page (see below) into ~/exercises/problems/exercises_1 (~ stands for your home directory). Print this structure using tree.
 
Changed:
<
<
Open a LibreOffice document and write down what you have done. Save this document under the name $HOME/exercises/doc/exercise_1.odt. Continue to document you work during this exercise such that at the end of the exercise session you have a document describing all your work.
>
>
Open a LibreOffice document and write down what you have done. Save this document under the name $HOME/exercises/doc/exercise_1.odt. Continue to document you work during this exercise such that at the end of the exercise session you have a document describing all your work.
 

Exercise 3: Environment variables and shell startup

Changed:
<
<
Have a look at all environment variables defined (printenv). What are the values of HOME, PATH, JAVA_HOME, CROSS_COMPILE?
>
>
Have a look at all environment variables defined (printenv). What are the values of HOME, PATH, LANGUAGE, LOG_NAME?
  To get the value of an environment variable print it (echo command) with a $ in front (e.g. echo $HOME).
Changed:
<
<
Have a look at hidden files in you home directory. You will find amongst many other files a file called .bashrc. Open this file with an editor (gedit, emacs, vi ...it is your choice!) and edit it adding three lines concerning .bash_profile, such that end of the file looks as follows:
>
>
Have a look at hidden files in you home directory. You will find amongst many other files a file called .bashrc. Open this file with an editor (gedit, emacs, vi ...it is your choice!) and edit it adding three lines concerning .bash_profile close to the end of the file (compare the comments), such that end of the file looks as follows:

bashrc.png

  Create a new file .bash_profile in your home directory and enter:
Line: 64 to 66
  Linux uses plenty of very small commands, which however can be combined to make up much more complex commands. This is done by connecting stdout of one command with stdin of the following one as follows: cmd1 | cmd2. The “|” defines a pipe, where stdout of cmd1 is connected to stdin of cmd2.
Changed:
<
<
Example: Copy the lyrics of the Beatles song “Yesterday” to your solutions directory. Then find out how many lines contain the word “yesterday”. Use the commands grep and wc to accomplish this. Use the cat, more or less command on yesterday.txt to verify your result is correct.
>
>
Example: Copy the lyrics of the Beatles song “Yesterday” to your solutions directory. You will find it with the uploaded files at the bottom of this page. Right click on it and select "Save Link as". Then find out how many lines contain the word “yesterday”. Use the commands grep and wc to accomplish this. Use the cat, more or less command on yesterday.txt to verify your result is correct.
  Finally remove runningNow.txt (using rm) and type ps ax| tee runningNow.txt . What is the difference to ps ax > runningNow.txt?

Exercise 5: File permissions

Line: 97 to 99
 

Comments

<--/commentPlugin-->
\ No newline at end of file
Added:
>
>
META FILEATTACHMENT attachment="yesterday.txt" attr="" comment="" date="1504691903" name="yesterday.txt" path="yesterday.txt" size="680" user="uli" version="1"
META FILEATTACHMENT attachment="exercises_1.odt" attr="" comment="" date="1504693724" name="exercises_1.odt" path="exercises_1.odt" size="81558" user="uli" version="1"
META FILEATTACHMENT attachment="bashrc.png" attr="" comment="" date="1504695772" name="bashrc.png" path="bashrc.png" size="35319" user="uli" version="1"

Revision 22017-08-13 - uli

Line: 1 to 1
 
META TOPICPARENT name="CourseExercises"
Changed:
<
<

Exercises 1: Discovering Linux

>
>

Exercises 1: Discovering Linux

 

Goal:

Today’s embedded systems are more powerful than many minicomputers we had some 20 years ago. The computer I worked on when starting my job at CERN was a Digital Equipment PDP-11 minicomputer with 128kBytes (kBytes not Mbytes!) and it had a removable hard disk with 600 Mbytes of storage space. Total cost of the machine was some 80 kUS$! This machine controlled our complete linear accelerator with some 1500 control parameters (power supplies, RF parameters, vacuum, instrumentation, operator consoles ….)

Line: 58 to 58
  cd to $HOME/exercises/solutions/exercise_1
Changed:
<
<
Now type ps ax and observe the result. What does the command do?
>
>
Now type ps ax and observe the result. What does the command do?
  After that type ps ax > runningNow.txt followed by ls. What did the system do?

Revision 12017-01-03 - uli

Line: 1 to 1
Added:
>
>
META TOPICPARENT name="CourseExercises"

Exercises 1: Discovering Linux

Goal:

Today’s embedded systems are more powerful than many minicomputers we had some 20 years ago. The computer I worked on when starting my job at CERN was a Digital Equipment PDP-11 minicomputer with 128kBytes (kBytes not Mbytes!) and it had a removable hard disk with 600 Mbytes of storage space. Total cost of the machine was some 80 kUS$! This machine controlled our complete linear accelerator with some 1500 control parameters (power supplies, RF parameters, vacuum, instrumentation, operator consoles ….)

The Raspberry Pi we will be using during the hands-on part of the course has 1 Gbyte of RAM, a “hard disk” of 32 Gbytes and its CPU exceeds by far that of the PDP-11 mentioned above. This means that we can run a full blown operating system on this machine. In fact we will use a special Linux flavor, adapted to small machines, very similar to the Linux system we can run on PCs.

Our first goal is therefore to become acquainted with Linux, its file structure, its commands etc. and this can be done on the PC for which we have created a dedicated bootable USB disk.

Exercise 1: Explore the Linux file system

The Linux file system has a tree like structure with “/” at its root (the rot of the file structure is NOT /root, which is the home directory of the super user.

Start a terminal and try out a few commands.

Use the

  • ls

  • tree

  • pwd

  • cd

commands to explore the the file system starting at the file system root. Where are the commands located, where the libraries, where is your home directory?

Linux also has hidden files, how can you see them? (Hint: Linux has zillions of commands and even more options and you will never know them all. Use the man (man stands for “manual”) to learn more about a command and its options).

Exercise 2: Create a file system structure for all exercises of this course

In your home directory, create subdirectories exercises, bin,src (use mkdir). Within exercises, create directories problems, solutions, doc. Within each of these create a subdirectory exercise_1. Put this file into $HOME/exercises/problems/exercise_1. Print this structure using tree.

Open a LibreOffice document and write down what you have done. Save this document under the name $HOME/exercises/doc/exercise_1.odt. Continue to document you work during this exercise such that at the end of the exercise session you have a document describing all your work.

Exercise 3: Environment variables and shell startup

Have a look at all environment variables defined (printenv). What are the values of HOME, PATH, JAVA_HOME, CROSS_COMPILE?

To get the value of an environment variable print it (echo command) with a $ in front (e.g. echo $HOME).

Have a look at hidden files in you home directory. You will find amongst many other files a file called .bashrc. Open this file with an editor (gedit, emacs, vi ...it is your choice!) and edit it adding three lines concerning .bash_profile, such that end of the file looks as follows:

Create a new file .bash_profile in your home directory and enter:

# add $HOME/bin to the execution path

PATH=$PATH:$HOME/bin

Save the file.

Print the current environment variable PATH. The execute: source $HOME/.bash_profile. Print the execution path again and observe differences.

Now create a new environment variable MY_VARIABLE:

export MY_VARIABLE=It’s_Me\! and print it. Get rid of it using unset.

Exercise 4: Redirection and pipes

To each executable 3 input output channels are associated:

  • stdin

  • stdout

  • stderr

stdin corresponds to your keyboard, stdout and stderr to your screen. stdout is used for any output the program produces through its print statements while stderr is reserved for error messages.

cd to $HOME/exercises/solutions/exercise_1

Now type ps ax and observe the result. What does the command do?

After that type ps ax > runningNow.txt followed by ls. What did the system do?

Linux uses plenty of very small commands, which however can be combined to make up much more complex commands. This is done by connecting stdout of one command with stdin of the following one as follows: cmd1 | cmd2. The “|” defines a pipe, where stdout of cmd1 is connected to stdin of cmd2.

Example: Copy the lyrics of the Beatles song “Yesterday” to your solutions directory. Then find out how many lines contain the word “yesterday”. Use the commands grep and wc to accomplish this. Use the cat, more or less command on yesterday.txt to verify your result is correct.

Finally remove runningNow.txt (using rm) and type ps ax| tee runningNow.txt . What is the difference to ps ax > runningNow.txt?

Exercise 5: File permissions

Do an ls -l in your solutions/exercise_1 directory. Then do the same thing on /bin. Who can read, modify, write each file?

Now create a new file yesterday.sh in solutions/exercise_1/with:

#!/bin/sh

followed by the command you typed when counting the number of “yesterdays”. Save the file.
What are the permission of it? Then type chmod +x yesterday.sh and observe the change in permissions. Type ./yesterday.sh, what happens?

Too easy?

For those who find the above exercises too easy and who want to do more (but who will not have support for this):

  • What is the current version of the Linux kernel we run?

  • What is the current version of the gcc C compiler?

  • Try to find all files that have been modified within the last 24 h.

  • change all occurrences of “yesterday” in the Beatles song to “today” using the stream editor

  • Try to find a certain string within a file system subtree

  • invent your own exercise

Further reading:

Try http://linuxcommand.org/lc3_learning_the_shell.php.

Article text.

-- Uli Raich - 2017-01-03

Comments

<--/commentPlugin-->
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback