AF_IC06_AF_v2.docx - XTEC



|AF_IC06_Orders, packages and schedulers |

|AF Orders, packages and schedulers |

AF Orders, packages and schedulers 1

AF Introduction 2

AF Glossary 3

AF Unit 1 - Basic commands and configuration files. 4

AF Unit 2 - Package management in GNU/Linux 17

AF Unit 3 - Schedulers 24

|AF_IC06_ Orders, packages and schedulers |

|AF Introduction |

This formative activity will introduce you to the unix world through the commands, the packages and the schedulers. It has three units

Unit 1 - Basic commands and configuration files

This unit will introduce the command-line interpreter, a program that will allow us to communicate directly with the operating system.

Through examples and exercises we will learn its syntax and discover some of the most common commands of GNU / Linux. At the end of Unit there will be a practical exercise.

Unit 2 - Package management in GNU/Linux

The second unit will show you what a package is, its formats and different ways to install it.

Unit 3 - Schedulers

Among the tasks that the system administrator has to do, there are many repetitive ones to be performed regularly, such as cleaning up temporary files and folders, rebuilding the system databases, backup etc..Fortunately for them, schedulers exist. Schedulers allow to automatize all these repetitive tasks

Every unit has many examples in order to facilitate the learning. At the end of every unit, you will have to do a practical exercise.

|AF_IC06_Orders, packages and schedulers |

|AF Glossary |

To make good use of the contents of the units it’s required to be familiar with certain English words. To help you with this task below is a list of activities for every unit..

|TO KNOW MORE |

|Practice with all the activities (learn, speller, test, etc…) until you learn the new vocabulary |

|[pic] |

|Unit 1 Vocabulary - Unix basic commands and configuration files. |

| |

|[pic] |

|Unit 2 Vocabulary - Package management in GNU / Linux. |

| |

|[pic] |

|Unit 3 Vocabulary - Schedulers. |

| |

Before starting, do the next activity using the tool ‘Quizlet’ ():

In pairs, make your own set of vocabulary words including either images or the catalan translation and share it with your teacher on your moodle site.

| | |

| | |

|AF_IC06_Orders, packages and schedulers |

|AF Unit 1 - Basic commands and configuration files. |

This unit will introduce the command-line interpreter, a program that will allow us to communicate directly with the operating system.

Through examples and exercises we will learn its syntax and discover some of the most common commands of GNU / Linux. At the end of Unit there will be a practical exercise.

Here you can see a short summary of the contents of this unit:

1.1 The command-line interpreter 4

1.2 Your first commands 5

1.3 Working with files 8

1.4 Redirection 12

1.5 Permissions 14

1.6 Configuration files 16

1.7 Exercise 16

1. The command-line interpreter

As mentioned in the introduction, the command-line interpreter is the program that allows us communicate with the operating system through a set of instructions provided by it

The first thing we see in the terminal is the prompt. It’s a character or set of characters displayed in the command line to indicate that it is waiting for orders. The prompt shows information about who is logged in, on what machine we are logged into, what is its present working directory and if the logged in user is a super user or a normal user.

Remember that in Unix a super User account means that his owner has total control of all the system and can run any kind of command without any restrictions. Normal users have limited access to critical system files and directories. Let’s see an exemple of a prompt:

[pic]

Notice that after the user information there is a @ and after the machine name’s information there is a :.

user@machine: ~$

According to the last paragraph, we can obtain some information thanks to this promt.

● It’s from a user called alumne

● This user is logged into a Machine called tramuntana.

● It’s situated in the /Música directory.

● It’s a normal user. Note that the last character in the prompt is a $. That means it is a normal user. If it was a super user it would be a #.

Before starting we need to know where we are. Most Linux distributions follow the Filesystem Hierarchy Standard. The first directory of the system is called the root directory.This root directory is represented by a forward slash, like this: /. Everything that exists on your Linux system can be found below this root directory, even if stored on different physical devices.

|TO KNOW MORE |

|Are you interested in knowing more about the Filesystem Hierarchy Standard? Take a look at this link |

|[pic] |

|Filesystem Hierarchy Standard |

| |

| |

2. Your first commands

pwd(Print Working Directory)

In linux the directory you are standing in is called the working directory .If you want to know where you are, use the pwd command.

[pic]

cd(Change Directory)

To change current working directory you have to use the cd command followed by an argument. You can move to a new directory using the relative or the absolute pathname. Every element of the pathname is separated by a /.

If the pathname is in relation to current directory -> Relative Pathname. Always begin without a /.

If the pathname is in relation to root -> Absolute pathname. Always begin with a /.

Let’s see an exemple to better understand it:

We have a directory called Imatges in our current directory(/home/alumne)). We can access it in two different ways.

With the relative pathname:

cd Images

With the absolute pathname:

cd /home/alumne/Imatges

Both options take you to the Imatges directory.

If you need to move up one directory, use cd command in this way.

cd..

With it, if you are in /home/alumne/Imatges, you’ll go to /home/alumne.

To return to your home directory type cd with no argument. Very useful if you are lost in the file system!

|Command |Result |

|cd directory_name |Changes current working directory to a directory called “directory |

| |name” using relative pathname. |

|cd /directory_name |Changes current working directory to a directory called “directory |

| |name” using absolute pathname. |

|cd .. |Moves up one directory your corrent workind directory. |

|cd |Returns to your home directory. |

ls

If you want to list the contents of a directory you have to use the ls command. It’s one of the most used commands and accepts a lot of different options and arguments.

Its use is quite simple:

ls –options arguments

Here you have some examples:

|Command |Result |

|ls |List the content of the current directory. |

|ls /home/Music |List the content of the directory /home/Music. |

|ls –l |List the content in a long listing format. |

|ls –a |List the entries starting with “.”.also |

|ls -t |List but sort the content by modification time. |

|ls -s |List and print the size, in blocks, of each file. |

|ls -i |List and print index number of each file |

Obviously, you can mix these different options between them and add arguments or not.

For example:

ls –la /home/Music

It will show the content in of /home/Music directory in a long listing format and will also include the entries starting with”.”.

Now we will take a quick look at the long listing format.

[pic]

What are these columns? Let's see it:

● First column is for the file permissions.

● Second column is for the number of hardlinks.

● Third column is for the name of the user who owns the file.

● Fourth column is for the name of the group that has file permissions.

● Fifth column is for the size in bytes.

● Sixth column is for the modification time of the file or directory.

● Seventh column is for the name of the file or directory.

|TO KNOW MORE |

|The command ls accepts a lot of different options and arguments. Here you only have seen a few of them. If you want to broaden your |

|knowledge, check out this link: |

|[pic] |

|List of ls options |

| |

Practise a bit:

Take a tour of the directories and files of your filesystem with the previous commands learned. Start at your home directory. Go up a level and discover your new working directory. Change directory to root and list all the files. Choose a new directory and go to it. List its content and read the content of some files. Change to another directory using its absolute pathname. Print the working directory. Try to enter wrong pathname and finally return to your home directory.

3. Working with files

In this chapter you will see some of the most used commands for manipulating files and directories.

Wildcards

Before getting into it, we will introduce the wildcards. A wildcard is a character that can stand for all members of some class of characters. When you use a wildcard the computer systems substitutes the members of the class for the wildcard character.

|Wildcard |Meaning |

|* |Matches any number of characters in a filename, including none. |

|? |Matches any single character |

|[characters] |Matches any character that is in the set of chracters. |

|[!characters] |Matches any character that isn’t in the set of characters. |

With some examples you will understand better. We use the ls command for the examples.

Imagine that you have a directory with the files house.txt, mouse.txt, blouse.txt and couse.txt

|Command |Result |

|ls *.txt |Lists all the files that have the .txt extension. You’ll get all the |

| |files. |

|ls *ouse.txt |Lists all the files that end with ouse.txt. You’ll get all the files |

|ls ?ouse,txt |Lists all the files that start with any character followed by |

| |ouse.txt. You’ll get all the files except blouse.txt |

|ls [hm]ouse.txt |Lists all the files that start with h or m followed by ouse.txt. |

| |You’ll get house.txt and mouse.txt. |

|ls [!hm]ouse.txt |Lists all the files except those that starts with h or m followed by |

| |ouse.txt. You’ll get blouse.txt and couse.txt |

|ls [a-k]ouse.txt |Lists all the files that starts with a letter between a and k and |

| |followed by ouse.txt. You’ll get house.txt and couse.txt. |

less

This command allows you to view the contents of a file allowing you to navigate through a long file. This command is used as follows:

less text_file

Less will display the content of the text file one-page at time. To navigate through the text file you can use the arrows keys or the Page Up and Page Down keys.You can also search for an occurrence using the “/” followed by the text to search for. To return to the command line use the q.

|Command |Result |

|less file_name |Display the content of the file file_name |

cp

This command copies files and directories from the source to the destination. Its syntax is very simple:

cp source destination

Let’s see some examples:

|Command |Result |

|cp mouse.txt cat.txt |It will copy the content of mouse.txt to cat.txt. If cat.txt doesn’t |

| |exist, it will be created. If it exists, it will be overwritten. |

|cp –i mouse.txt cat.txt |It will copy the content of mouse.txt to cat.txt. If cat.txt doesn’t |

| |exist, it will be created. If it exists, it will be overwritten. If |

| |you put the –i option you will be asked before overwriting the |

| |destination file. |

|cp *.txt pets |You can use the wildcards with the command. It will copy all the files|

| |with .txt extension to the pets directory. |

Note:With directories you can do the same operations.

mv

This command moves files and directories from the source to the destination. Its syntax is very simple:

mp source destination

Let’s see some examples:

|Command |Result |

|mv mouse.txt dog.txt |It will move the content of mouse.txt to dogt.txt. If dog.txt doesn’t |

| |exist, mouse.txt will be renamed to dog.txt. If it exists, its |

| |contents will be replaced |

|mv –i mouse.txt dog.txt |If you put the –i option, you will be asked before it is overwritten. |

Note:With directories you can do the same operations.

rm

This command is used to remove files. Its syntax is very simple:

rm file or rm directory

Let’s see some examples:

|Command |Result |

|rm mouse.txt cat.txt |It will remove the files mouse.txt and cat.txt. |

|rm –i mouse.txt cat.txt |It will remove the files but the user will be asked before deleting |

| |each file |

|rm *.* |It will remove all the files of the directory. |

mkdir

This command is used to create directories. You can use it by typing:

mkdir new_directory

An example of this command:

mkdir animals

It will create a new directory called animals.

rmdir

This command is used to delete directories. You can use it by typing:

mkdir new_directory

An example of this command:

rmdir animals

It will delete the directory animals.

|TO KNOW MORE |

|There are two basic tools that will help you in your experience with the cli. |

|The first of them is the man command. It shows information from the manual about the command asked. For example, man cp will show |

|documentation about the usage of the cp command. |

|The other is the help option. For the most commands you will receive information about it if you type the name of the command followed by |

|“--help”. For example, cp –help. |

cut

This command trims lines at the end or at the beginning by a specified number of characters. Its syntax is:

cut option file_to_cut

Let’s see some examples of some of the different options that the command admits

● -c It means cut characters. You must indicate the range of characters you want to cut. For example cut -c1-5,10-15 file will cut only the characters in these positions of every line of the file.. For example, if you have a file called list.txt with these lines:

ABCDEFGHIJKLMNOPQ

1234567890123456789012

with the next command:

cut -d':' -f1 list.txt

you will have in the output these lines:

ABCDEJKLMN

1234501234

● -f Specifies a field list, separated by a delimiter. The option -f specifies which number of field you want to extract, and the option -d specifies what is the field delimiter that is used in the input file. For example, if you have a file with these lines:

cat:dog:bear:lion:parrot

apple:banana:pear:orange

blue:red:green:yellow

with the next command:

cut -d':' -f1 file

you indicate that the field delimiter is “:” and that you want to cut the first field,so in the output you will have:

cat

apple

blue

If you want the second and the fourth field, you will have to type:

cut -d':' –f2,4 file

To summarize:

|Command |Result |

|cut –c |-c It means cut characters. You must indicate the range of characters |

| |you want to cut. |

|cut –f |Specifies a field list, separated by a delimiter. . The option -f |

| |specifies which number of field you want to extract, and the option -d|

| |specifies what is the field delimiter that is used in the input file. |

|rm *.* |It will remove all the files of the directory. |

Practise a bit:

Create a new directory called Testdirectory. Copy inside this directory three files from your home directory, list them and then delete the files and the directory.

Create a file called cutpractice.exercise with this content:

one:two:three:four

dog:cat:snake:lion

mug:pen:spoon:phone

with the cut command you have to get this output

one:two:four

dog:cat:lion

mug:pen:phone

Try to do it with –c and with –f option.

|TO KNOW MORE |

|Here you have a on-line game that will help you to learn commands in a easy way: |

|[pic] |

|Game |

| |

4. Redirection

Redirection is one of the most powerful tools that you can use in your terminal. Until now you have seen that many commands print their output on the screen. With the redirection you can change the output and the input of many commands to files, devices or other commands.

Redirection the output

Toredirect the output of a command you have to use the symbol “>”. Let’s see an example of its use:

ls > llistat.txt

If you enter this command in your terminal you will not see any results on your screen. The results of the command are written in a file called llistat.txt. Note that if the file “llistat.txt” doesn’t exist, it will be created. If the file “llistat.txt” exists, it will be overwritten.

There is another form of redirect the output of a command to a file. The symbol “>>” also redirects the output but adds the result to the redirected file. No overwriting the file. So, if you type:

ls -l >> llistat.txt

The result will be added to the end of the file llistat.txt.

Redirection the input

To redirect the input we use the symbol “ nlinies.txt

We start counting the number of lines of llistat.txt and then the result is written in the file nlinies.txt

Pipelines

It will be very helpful for you once you are familiar with it. Pipelines connect the standard output of a command with the standard input of another command. In other words, you can connect two commands.directly

ls -l | less

In the last instruction the standard output of the command “ls-l” is redirected as standard input of the command less. With this simple trick we can control the scroll of the ls command.

Usually pipelines are used with filters. A filter is a program that takes its input from another command, does some operation with it and shows the result by the standard output.

Here is a list of some of these filters:

|Name |Function |Syntaxis |

|comm |Compares lines of two files |comm file1 file2 |

|grep |Searches for certain patterns in a file or |grep ajuda file1 file2 |

| |files. In the example we search the word “ajuda” | |

| |on file1 and file2. | |

|head |Shows the first lines of a file. |head file1 |

|tail |Shows the last lines of a file.. |tail file1 |

|sort |Orders the content of a file and shows it for the|sort file1 |

| |standard output | |

|uniq |Discards all but one of successive identical |uniq file1 |

| |lines from standard input, writing to standard | |

| |output. | |

|TO KNOW MORE |

|There are a lot of different filters. You can see a long list of them in the next link: |

|[pic] |

|List of filters |

| |

Practise a bit

Create a file that only shows the first three files of your home directory. Use filters to do it.

5. Permissions

Unix is a multi-user system. This means that there could been a lot of users working on a same computer. Without any kind of control everybody could access everything. Permissions help to protect files and directories from unallowed and unwanted users. To understand a little better how permissions work, let’s add a “ls -l” to our directory:

[pic]

We focus all our attention in the first column. It is composed by 10 characters:

1st character: It’s for the file type. d is for a directory and - is for a regular file.

2nd character: If there is an “r” it indicates read permission for the file owner. Without permission with a “-“.

3rd character: If there is an “w” it indicates write permission for the file owner. Without permission with a “-“.

4th character: If there is an “x” it indicates execution permission for the file owner. Without permission with a “-“.

5thcharacter: If there is an “r” it indicates read permission for the group owner. Without permission with a “-“.

6th character: If there are an “w” indicates write permission for the group owner. Without permission with a “-“.

7th character: If there are an “x” indicates execution permission for the group owner. Without permission with a “-“.

8thcharacter: If there are an “r” indicates read permission for the other users. Without permission with a “-“.

9th character: If there are an “w” indicates write permission for the other users. Without permission with a “-“.

10th character: If there are an “x” indicates execution permission for the other users. Without permission with a “-“.

Therefore, a file that only the owner can read and write will have these permissions:

-rw-------

chmod

The owner of a file can change the permissions of a file with the chmod command.

If you look at the permission column, you will see that we can separate it in three parts :

2nd - 4th character refers to owner permissions.

5th -7th character refers to group permissions

8th- 10th character refers to other users permissions.

Each one of these parts is composed by three characters; first character for the read permissions. second character for the write permissions, and third character for the execution permissions.

Now we assign a “1” if we have the permission and a “0” if not.

rwx 111

rw- 110

r-x 101

r-- 100

-wx 011

-w- 010

--x 001

--- 000

Note that if you transform it from binary to a decimal you will have all the information relative to the permissions in a single digit.

rwx 111 7

rw- 110 6

r-x 101 5

r-- 100 4

-wx 011 3

-w- 010 2

--x 001 1

--- 000 0

If you repeat this process for the all the set of permissions (owner, group and others) you will have a decimal number of three digits; the first digit for the owner permissions, the second for the group permissions and the third for the other users permissions.

With all this, we will see how to use the chmod command with the Ter.txt file.

● Give all permissions to the owner and read permissions to the group and other users:

chmod 744 Ter.txt

● Give all permissions to the owner, write and read permissions to the group and any right to the other users:

chmod 760 Ter.txt

● Give read permissions to the owner, to the group and to the other users:

chmod 444 Ter.txt

|HIGHLIGHTS |

| |

|And now,we will see an activity related to permissions and chmod command. Download the file PermissionsQuiz.htm to your computer and open it|

|with your browser. Inside, you will find a quiz about file permissions.Try to get the best score! |

6. Configuration files

In Unix systems there are a lot of configuration files, almost one for every function that you can configure. Among others, we can find configuration files for system, boot for the network, the users, the package management, services and applications on your computer, the GUI ...

Most of them are in the /etc directory

Here you have a list of some of them:

● /etc/fstab Contains information about devices that are mounted automatically during system startup.

● /etc/network/interface Contains interface file network configuration

● /etc/passwd Contains information from local users

● /etc/shadow Contain encrypted password

● /etc/group Stores information on existing groups in our system

● /etc/apt/sources.list A file that lists the 'sources' from which packages can be obtained.

● /boot/grub/menu.lst Contains grub’s configuration.

● /etc/resolv.conf Contains information about DNS server.

● /etc/init.d/ This directory contains init scripts, starting and charging of most system services.

|HIGHLIGHTS |

|Before modifying a configuration file it is important to make a backup so you can go back in time and resolve potential configuration errors |

7. Exercise

Create a file system that imitates the file system of a library. Inside a folder called Library there you will have have folders for each book section. These folders are named Classic, Poetry, Fiction, Biography, History and Mythology.

Create 3 files for each book section directory. Files must have the name of sectionname1.book, sectionname 2.book and sectionname 3.book.You have to create the files in your home directory using the tools we have seen in section 1.4 Redirection (filters, pipes,>, >>, and ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download