37
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 1 AF_IC06_ Orders, packages and schedulers

AF_IC06_AF_v2.docx - apliense.xtec.catapliense.xtec.cat/.../default/files/AF_IC06_AF_v3.doc  · Web viewThe main reason of joint distribution is that every file could ... this only

Embed Size (px)

Citation preview

Page 1: AF_IC06_AF_v2.docx - apliense.xtec.catapliense.xtec.cat/.../default/files/AF_IC06_AF_v3.doc  · Web viewThe main reason of joint distribution is that every file could ... this only

AF_IC06_Orders, packages and schedulersAF Orders, packages and schedulers

AF Orders, packages and schedulers...............................................................................................1AF Introduction...............................................................................................................................2AF Glossary.....................................................................................................................................3AF Unit 1 - Basic commands and configuration files.....................................................................4AF Unit 2 - Package management in GNU/Linux.........................................................................17AF Unit 3 - Schedulers..................................................................................................................24

1AF_IC06_ Orders, packages and schedulers

Page 2: AF_IC06_AF_v2.docx - apliense.xtec.catapliense.xtec.cat/.../default/files/AF_IC06_AF_v3.doc  · Web viewThe main reason of joint distribution is that every file could ... this only

AF_IC06_ Orders, packages and schedulersAF 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 filesThis 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/LinuxThe second unit will show you what a package is, its formats and different ways to install it.

Unit 3 - SchedulersAmong 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.

2AF_IC06_ Orders, packages and schedulers

Page 3: AF_IC06_AF_v2.docx - apliense.xtec.catapliense.xtec.cat/.../default/files/AF_IC06_AF_v3.doc  · Web viewThe main reason of joint distribution is that every file could ... this only

AF_IC06_Orders, packages and schedulersAF 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 MOREPractice with all the activities (learn, speller, test, etc…) until you learn the new vocabulary

Unit 1 Vocabulary - Unix basic commands and configuration files.

Unit 2 Vocabulary - Package management in GNU / Linux.

Unit 3 Vocabulary - Schedulers.

Before starting, do the next activity using the tool ‘Quizlet’ (www.quizlet.com):

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.

3AF_IC06_ Orders, packages and schedulers

Page 4: AF_IC06_AF_v2.docx - apliense.xtec.catapliense.xtec.cat/.../default/files/AF_IC06_AF_v3.doc  · Web viewThe main reason of joint distribution is that every file could ... this only

AF_IC06_Orders, packages and schedulersAF 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..............................................................................................41.2 Your first commands............................................................................................................51.3 Working with files................................................................................................................81.4 Redirection..........................................................................................................................121.5 Permissions.........................................................................................................................141.6 Configuration files..............................................................................................................161.7 Exercise...............................................................................................................................16

1.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 itThe 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:

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

4AF_IC06_ Orders, packages and schedulers

Page 5: AF_IC06_AF_v2.docx - apliense.xtec.catapliense.xtec.cat/.../default/files/AF_IC06_AF_v3.doc  · Web viewThe main reason of joint distribution is that every file could ... this only

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 MOREAre you interested in knowing more about the Filesystem Hierarchy Standard? Take a look at this link

Filesystem Hierarchy Standard

1.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.

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.

5AF_IC06_ Orders, packages and schedulers

Page 6: AF_IC06_AF_v2.docx - apliense.xtec.catapliense.xtec.cat/.../default/files/AF_IC06_AF_v3.doc  · Web viewThe main reason of joint distribution is that every file could ... this only

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 Resultcd 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 “.”.alsols -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”.”.

6AF_IC06_ Orders, packages and schedulers

Page 7: AF_IC06_AF_v2.docx - apliense.xtec.catapliense.xtec.cat/.../default/files/AF_IC06_AF_v3.doc  · Web viewThe main reason of joint distribution is that every file could ... this only

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

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 MOREThe 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:

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.

1.3 Working with files

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

7AF_IC06_ Orders, packages and schedulers

Page 8: AF_IC06_AF_v2.docx - apliense.xtec.catapliense.xtec.cat/.../default/files/AF_IC06_AF_v3.doc  · Web viewThe main reason of joint distribution is that every file could ... this only

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 Resultls *.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 filesls ?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_fileLess 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.

8AF_IC06_ Orders, packages and schedulers

Page 9: AF_IC06_AF_v2.docx - apliense.xtec.catapliense.xtec.cat/.../default/files/AF_IC06_AF_v3.doc  · Web viewThe main reason of joint distribution is that every file could ... this only

Command Resultless 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 destinationLet’s see some examples:

Command Resultcp 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 Resultmv 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

9AF_IC06_ Orders, packages and schedulers

Page 10: AF_IC06_AF_v2.docx - apliense.xtec.catapliense.xtec.cat/.../default/files/AF_IC06_AF_v3.doc  · Web viewThe main reason of joint distribution is that every file could ... this only

This command is used to remove files. Its syntax is very simple:rm file or rm directory

Let’s see some examples:

Command Resultrm 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 MOREThere 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.

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

10AF_IC06_ Orders, packages and schedulers

Page 11: AF_IC06_AF_v2.docx - apliense.xtec.catapliense.xtec.cat/.../default/files/AF_IC06_AF_v3.doc  · Web viewThe main reason of joint distribution is that every file could ... this only

cut option file_to_cutLet’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:

ABCDEFGHIJKLMNOPQ1234567890123456789012

with the next command:cut -d':' -f1 list.txt

you will have in the output these lines:ABCDEJKLMN1234501234

● -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:parrotapple:banana:pear:orangeblue: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:

catappleblue

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:

11AF_IC06_ Orders, packages and schedulers

Page 12: AF_IC06_AF_v2.docx - apliense.xtec.catapliense.xtec.cat/.../default/files/AF_IC06_AF_v3.doc  · Web viewThe main reason of joint distribution is that every file could ... this only

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:fourdog:cat:snake:lionmug:pen:spoon:phone

with the cut command you have to get this outputone:two:fourdog:cat:lionmug:pen:phone

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

TO KNOW MOREHere you have a on-line game that will help you to learn commands in a easy way:

Game

1.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.txtIf 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.txtThe result will be added to the end of the file llistat.txt.

Redirection the input

To redirect the input we use the symbol “<”. Instead of the keyboard, you can redirect the standard input from a file. Let’s see how to use it:

12AF_IC06_ Orders, packages and schedulers

Page 13: AF_IC06_AF_v2.docx - apliense.xtec.catapliense.xtec.cat/.../default/files/AF_IC06_AF_v3.doc  · Web viewThe main reason of joint distribution is that every file could ... this only

wc -l < llistat.txtIn this example we used the command wc- to count the total number of lines of the file llistat.txt.Obviously, you can use both methods, input and output redirection, at the same time like this:

wc -l < llistat.txt > nlinies.txtWe 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 | lessIn 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 Syntaxiscomm Compares lines of two files comm file1 file2

grep

Searches for certain patterns in a file or files. In the example we search the word “ajuda” on

file1 and file2.

grep ajuda file1 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 standard output sort file1

uniq

Discards all but one of successive identical lines from

standard input, writing to standard output.

uniq file1

TO KNOW MOREThere are a lot of different filters. You can see a long list of them in the next link:

List of filters

Practise a bit

13AF_IC06_ Orders, packages and schedulers

Page 14: AF_IC06_AF_v2.docx - apliense.xtec.catapliense.xtec.cat/.../default/files/AF_IC06_AF_v3.doc  · Web viewThe main reason of joint distribution is that every file could ... this only

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

1.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:

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 “-“.

14AF_IC06_ Orders, packages and schedulers

Page 15: AF_IC06_AF_v2.docx - apliense.xtec.catapliense.xtec.cat/.../default/files/AF_IC06_AF_v3.doc  · Web viewThe main reason of joint distribution is that every file could ... this only

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 permissions8th- 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 111rw- 110r-x 101r-- 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 7rw- 110 6r-x 101 5r-- 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:

15AF_IC06_ Orders, packages and schedulers

Page 16: AF_IC06_AF_v2.docx - apliense.xtec.catapliense.xtec.cat/.../default/files/AF_IC06_AF_v3.doc  · Web viewThe main reason of joint distribution is that every file could ... this only

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!

1.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 directoryHere 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.

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

1.7 ExerciseCreate 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 <). Use as many different tools as you can. Before moving the books to their appropriate section, make a list with all the books, a list of books that only show book1 of each section, another that

16AF_IC06_ Orders, packages and schedulers

Page 17: AF_IC06_AF_v2.docx - apliense.xtec.catapliense.xtec.cat/.../default/files/AF_IC06_AF_v3.doc  · Web viewThe main reason of joint distribution is that every file could ... this only

only a shows the books of the sections Poetry, Biography and Mythology and a last list for only the books from Classic and Biography sections. Save these lists in one single file called “book.list”. Once you've done that, move the books to their section. Classic folder should only have permissions read, write, and execute by owner. Poetry and Fiction must be readable by the user, by group and by others users. History must only be readable and writable by the user and group owner. Show the correct application of these permissions in a list and save it in a file called permission.section.

AF_IC06_Orders, packages and schedulersAF Unit 2 - Package management in GNU/Linux

What is a package? How does it work? What formats can it have? Where do they go? How do I install it? In this unit you will learn the answer to all these questions through the materials and the explanations that you will receive. At the end of Unit there will be a practical exercice.

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

1.1 What is a package?.............................................................................................................171.2 What is a data repository?...................................................................................................181.3 Where is the information stored?........................................................................................181.4 DEB package management.................................................................................................191.5 Installing and updating packages in graphical mode..........................................................221.6 Exercise...............................................................................................................................23

1.1 What is a package?

In the GNU/Linux systems the software you have to install are in packets. At the time you install a program in these systems, in fact you install software packages in operating systems. A software package is a set of files that contain several files that are distributed jointly and allows the program installation. The main reason of joint distribution is that every file could needed other to workYou can find two type of packages: binary packages and source packages.

Binary packages:

Binary Packages are packets built specifically for any type of computer or architecture. They contain machine code, and not source. You can find these two type of packages:

RPM :These packages are used by distributions Red Hat, Suse, Mandrake, Conectiva, Caldera, etc.

DEB:These packages are used by distributions like Debian, those based on it, like UBUNTU. You can use these kind of packages with apt and dpkg.

17AF_IC06_ Orders, packages and schedulers

Page 18: AF_IC06_AF_v2.docx - apliense.xtec.catapliense.xtec.cat/.../default/files/AF_IC06_AF_v3.doc  · Web viewThe main reason of joint distribution is that every file could ... this only

Source Packages:

Source packages are packages that include source, and normally they can use any type of machine if code compiles correctly. They normally present format .tar.gz o tar.bz2 (that is compiled with tar and compressed with gzip o bzip). Generally every software has its install information in the README or INSTALL files.

HIGHLIGHTSDependence packages are those packages that need another package in order to work successfully.

According to GNU/Linux philosophy, a package (software) has only one function in the system. In this way, this only function could be used at any moment by another package when needed. This modularization makes a package depend on another in order to function, and thus will not have two programs that perform the same function in the same program but a system accessible by all others.

1.2 What is a data repository?

A data repository is a centralized destination to keep and storage digital information, normally data base or files, but so that we can understand, a repository is a place in Internet to store information. In the case of Linux repository, this information is software.

Repositories are used intensively in Linux, that store, the most, software packages available to install by a package management application. In this way it allows access to hundreds of applications to install and update easily.

Every distribution has its repositories where the designed programs are stored for this distribution, so that if you need to install a program you can do it directly from these repositories. This repositories are maintained by their own team of the distribution, so that you don’t have any problem to install software. In addition, if any software that we have instaledl by this method is updated in the repositories you will receive an update about it.

For every distribution we have an official repository to find the mentioned programs. But this is not the only repository available. Every system has a list of repositories available that we can modify by adding or removing other types of repositories (multimedia, security, for developers, etc.)

Linux system have a file that stores the repositories list which you can access by your package management system to install software. This file is located in /etc/management where management is usually the name of the management of our system. For exemple, if you use apt, you will have /etc/apt.

1.3 Where is the information stored?

In every Debian system, the repositories used are indicated in the file /etc/apt/sources.list. In this file every line represents a repository and the way to obtain the packages and the branch of

18AF_IC06_ Orders, packages and schedulers

Page 19: AF_IC06_AF_v2.docx - apliense.xtec.catapliense.xtec.cat/.../default/files/AF_IC06_AF_v3.doc  · Web viewThe main reason of joint distribution is that every file could ... this only

Debian that you want to use (stable, testing, unstable). Every line that starts with # will be ignored, as well as empty lines.

1.4 DEB package management

DEB Packages

The Packet System DEB is the software packet system that use Debian distribution and derived distributions. Packets DEB are UNIX standard files that included two files tar, in gzip, bzip2 or lzma. One of them contains control information (maintenance scritps and metadata) and the other one the files that will be installed in the system.

The main program used to manage this type of files is dpkg, although is often used thorough front ends apt and aptitude. You also can use graphic interfaces like Synaptic, el PackageKit or Gdebi.There are a lot of programs or command that help you to work with .deb packages. Let’s see some of them:

DPKG

DPKG program is the Debian GNU/Linux packet management system. It was created in 1993 by Ian Jackson, and is similar to RPM. It is used to install, remove and provide information about deb packets.

DPKG is a low level tool, therefore, it need a high level tool to remove packets from remote sites or to resolve dependencies.

DPKG has a problem: it can’t resolve dependencies from a package. In other words, DPKG can only install, uninstall and show information about packages. If one package has a dependency you have to acquire this dependency (download manually) and install in order to follow with the package installation.

In order to help, improve and achieve a more efficient package management Debian use a tool called APT (Advanced Packaging Tool). APT innovates in the package management in the sense that it resolves packages dependencies and is based on repositories to download packages and dependencies that have to be installed.

As you have read above, DKPG is a low level tool, and need a high level tool to resolve dependencies and download packages from remote sites. So that we have to clarify that APT does not install packages, but only resolves dependencies and downloads them from remote servers (also called repositories).

APT downloads packages index from repositories that we have set to make packages searches. When you decide to install a package, APT will download it from repositories jointly with its dependencies and store it in the directory /var/cache/apt/archives. Once APT has downloaded the package and its dependencies, its the turn of DPKG, to install it in the system.

HIGHLIGHTSBriefly, APT and DPKG are a team and they work one after the other; APT resolves

19AF_IC06_ Orders, packages and schedulers

Page 20: AF_IC06_AF_v2.docx - apliense.xtec.catapliense.xtec.cat/.../default/files/AF_IC06_AF_v3.doc  · Web viewThe main reason of joint distribution is that every file could ... this only

dependecies and downloads packages and DPKG installs them in the system.

APT

APT simplifies the software administration process in operative systems like UNIX, they automate the installation, configuration and update software packages, even if they are binary files or compiled, from their source.

APT was designed originally like a dpkg interface to work with .deb packages from Debian.

To function properly, APT needs the file the file /etc/apt/sources.list. This file contains deposit software information from which it will download packages .deb that you want to install to the system.

Let’s see some instructions that you will need with apt: ● apt-get update: you can use it to update local package index related to repositories set

in /etc/apt/sources.list.. The package index is downloaded from a file called Packages.gz.. It is important that you update every time that you make changes in the sources.list. file with apt-get update. APT connects to the repositories and downloads package index updated.

● apt-get upgrade: with upgrade we can update all packages from our distribution with its more updated version in the repositories.

● apt-get install: installs the packages specified with install word. Syntaxis is as follows:

#apt-get install package1 package2 packageN

Let’s go to see what happens when you want to install a package. First APT automatically resolves dependencies and notifies packages that you need to install. Once you give the go-ahead, APT follows with the installation and downloads every package from the repositories.

Once the packages are downloaded, they are installed and set in the system. Now you have installed the packages and you can use them whenever you want from a terminal.

● apt-get remove: it serves to uninstall all the packages specified back the remove word and all its dependencies. . Syntaxis is similar to install:

#apt-get remove package1 package2 packageN

If we add to remove –purge option, you are indicating that in addition to uninstall the packages, you want to remove set files.

● apt-get clean: removes downloaded packages. APT uses a cache where can download packages from repositories. This cache is in var/cache/apt/archives. In this directory you can find all the downloaded packages. With the clean order you can delete this cache and free up disk space.

apt-get clean

20AF_IC06_ Orders, packages and schedulers

Page 21: AF_IC06_AF_v2.docx - apliense.xtec.catapliense.xtec.cat/.../default/files/AF_IC06_AF_v3.doc  · Web viewThe main reason of joint distribution is that every file could ... this only

● apt-get autoclean: This order is very similar to apt-get clean but autoclean only deletes the outdated packages.

apt-get autoclean

It is also interesting to know apt-cache. The apt-cache does not manipulate the system but provides operations to search for and generate interesting opportunities packages. The most used options are as follows:

• Search for some package with a pattern: apt-cache search pattern• Show detailed information about a package: apt-cache show package_name• Show packages dependencie: apt-cache depends package_name

Aptitude

Aptitude is an application that tries to ease the use of APT users. This application has 2 parts: one in text mode and the other part in interactive mode.

Syntax and results are very similar to apt-get and apt-cache but we find some differences with dependencies, the options and the format screen output.Aptitude deletes orphaned dependencies when uninstalling a package. APT does not do this automatically, we need to use the clean order.

Let's see some of the instructions that we use with aptitude in text mode:

● aptitude install: To install packages with aptitude we use the order:aptitude install package_name.

● aptitude remove/purgue: To delete packages with aptitude we use the order:remove/purge package_name.

Purgue option also deletes any configuration file of the deleted package● aptitude update: Update repositories● aptitude upgrade: Update all installed packages in the latest versions that are in the

repositories.● aptitude search: • Search for packages with the indicated pattern.

aptitude search pattern

You can access at interactive mode typing 'aptitude' in the terminal. Let's see how to invoke aptitude interactive mode

You will see this screen

21AF_IC06_ Orders, packages and schedulers

Page 22: AF_IC06_AF_v2.docx - apliense.xtec.catapliense.xtec.cat/.../default/files/AF_IC06_AF_v3.doc  · Web viewThe main reason of joint distribution is that every file could ... this only

Through this screen we can install / uninstall packages by moving through the menu with the arrow keys.

TO KNOW MOREBelow, you will find fully detailed information about how to work with aptitude

Aptitude guide

1.5 Installing and updating packages in graphical mode

Almost all GNU / Linux GUI versions, incorporate graphical package managers to facilitate installation and unistallation tasks, research and package configuration. Now you will see Synaptic, a graphical package managers that incorporates the Ubuntu Desktop Edition.

Synaptic is usually used for systems .deb based packages but can also be used in systems based on RPM packages.To launch Synaptic, type synaptic in your terminal or in your desktop go to:

Applications > "Synaptic Package Manager"

The main window is divided into three sections: a package browser on the left, the package list on the upper right, and package details on the lower right.

22AF_IC06_ Orders, packages and schedulers

Page 23: AF_IC06_AF_v2.docx - apliense.xtec.catapliense.xtec.cat/.../default/files/AF_IC06_AF_v3.doc  · Web viewThe main reason of joint distribution is that every file could ... this only

Beside the name of each package there is a box. If the box is white, it means the package is not installed. If it is green, the package is already installed.

To install packages with synaptic you have to find and mark them with a double-click(or or we can use the right mouse button and select the option “Mark to install” ). Once you have marked all the packages you have to install, click at apply.If packages have dependencies of other packages, we also asked if we want to install it.

To uninstall a package, it must have the green box .You have to click them with the right mouse button and select the option “Mark for remove all”. Next click to apply

When an exclamation sign appears in the box it means that the package can be updated.As a front-end to apt, Synaptic uses the system-wide list of software repositories file located at /etc/apt/sources.list

1.6 ExerciseUsing the apt options search for a chess game. Choose your favourite and install it. Compare the /var/cache/apt/archives before installing the game and after. Is there any change? Now, using the aptitude look for a pacman game and install it. Compare again the /var/cache/apt/archives before installing the game and after. Is there any change with the two previous files?It’s Synaptics turn. Open it and remove completely the two games previously installed. Take a look again at /var/cache/apt/archives. What happened? Why?

23AF_IC06_ Orders, packages and schedulers

Page 24: AF_IC06_AF_v2.docx - apliense.xtec.catapliense.xtec.cat/.../default/files/AF_IC06_AF_v3.doc  · Web viewThe main reason of joint distribution is that every file could ... this only

AF_FM03_ AF_IC06_Orders, packages and schedulersAF 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 exists. Schedulers allow to automatize all this repetitive tasksNext you will see some of the tools it offers GNU / Linux to automatize various tasks.Here you can see a short summary of the contents of this unit:

1.1 Cron..................................................................................................................................241.2 AT.....................................................................................................................................27

1.3 Exercise............................................................................................................................28

HIGHLIGHTSTo execute some commands of this unit you need to be super user. To change to super user type sudo su and enter the root password.

1.1 Cron

Cron is one of the most used tools to automatize tasks in Unix.

Cron is a daemon that execute processes, programs or scripts, at scheduled intervals (eg, every minute, day, week or month). By default, cron runs every minute and checks the table of tasks that must be executed.

To use cron use the crontab command with one of these options:Command Explanation

crontab -e -e:If you want to edit the file planning usercrontab -l -l :If you want to see planned jobscrontab -r -r :If you want to delete crontab filecrontab -u user -u :If you want to operate with an specific user

Now let's plan a task to test the crontab. crontab -eWe will see a screen like this:

24AF_IC06_ Orders, packages and schedulers

Page 25: AF_IC06_AF_v2.docx - apliense.xtec.catapliense.xtec.cat/.../default/files/AF_IC06_AF_v3.doc  · Web viewThe main reason of joint distribution is that every file could ... this only

All the lines that starts with “#” are comments.Note that the last line has the text “m h dom mon dow command”. Every word is a field. Below this line you have to write first your time planning and then the command to run.

Let’s analyze all the fields.

The fields are:

minute hour dom month dow user cmd

field Meaningm This controls what minute of the hour the

command will run on You have to type a number between '0' and '59'.

h This controls what hour of the hour the day the command will run on You have to type a number between '0' and '23'.

dom This controls the Day Of Month that the command will run on. You have to type a number between '0' and '31'.

mon This is the month that the command will run on. It can be numerically(0-12), or the name of

25AF_IC06_ Orders, packages and schedulers

Page 26: AF_IC06_AF_v2.docx - apliense.xtec.catapliense.xtec.cat/.../default/files/AF_IC06_AF_v3.doc  · Web viewThe main reason of joint distribution is that every file could ... this only

the month.

dow This controls the Day Of Week that the command will run on. It can be numerically(0-7), or the name of the day

cmd This is the command that you want run. This field may contain multiple words or spaces

If you don't wish to specify a value for a field, just place a * in the field.

Now it is time to do our first task in cron. Our first task will be very easy, just to become familiarized with cron. We want a task that saves in a file the time of the computer. The task must execute everyday at 22:50 and the output of the command will be redirected to a file called fitxerhora.txt.

After 22:50 you will have the result in the fitxerhora.txt

Obviously, crontab is used for more useful tasks. Let’s see some examples:You want to know the list of users who are at 12:00 logged in the computer:

You want to do a weekly backup of an important directory every Monday at 23:00:

26AF_IC06_ Orders, packages and schedulers

Page 27: AF_IC06_AF_v2.docx - apliense.xtec.catapliense.xtec.cat/.../default/files/AF_IC06_AF_v3.doc  · Web viewThe main reason of joint distribution is that every file could ... this only

You want to do a daily clean in order to free up the disk space deleting downloaded .deb files (packages) from the local repository. You need admin rights to do this.

TO KNOW MOREcron also admits some literals:

● @reboot, task is executed when the system starts● @yearly, task is executed once a year: 0 0 1 1 *● @annually, the same that @yearly● @monthly, task is executed the first day of every month: 0 0 1 * *● @weekly, task is executed the first minute of the first hour of the first day of the

week: 0 0 * * 0● @daily, daily at 12:00A.M. 0 0 * * *● @midnight, the same that @daily● @hourly, task is executed the first minute of every hour: 0 * * * *

.

1.2 AT

The at command allows you to schedule jobs to be executed at certain time only a single time. It differs from cron, which is used for recurring executions (e.g. once an hour, every Tuesday, January 1 every year). The order is executed at a time and date given as arguments on the command line.The normal syntaxis of the command at is:

at hour dateThe instructions set to do are read from the standard input (stdin) and will be executed atthe appointed time. You have to finish your instruction list with EOF character, usually Control-D.If you enter a date, you must to enter an hour too.

The results of the command, standard output and error output, will be sent by email to the user who invoked at.

Command Explanationat -l You can view the scheduled instructionsat –d Lets you delete the scheduled instructionsat –f file Lets you change the standard input from a

keyboard to a file. Will read the instructions to execute from the file specified.

27AF_IC06_ Orders, packages and schedulers

Page 28: AF_IC06_AF_v2.docx - apliense.xtec.catapliense.xtec.cat/.../default/files/AF_IC06_AF_v3.doc  · Web viewThe main reason of joint distribution is that every file could ... this only

Let’s see some simple examples:Copy a file in 5 minutesFirst you have to schedule the execution

at now +5 minutes and then type the order

cp /home/alumne/file1 /home/alumne/file2.

Create a new directory at midnightWe select the time of execution

at midnight and then type the order

mkdir newdirectory

Halt the system in 2 hoursYou schedule the execution

at now +2 hours and then type the order

halt

TO KNOW MOREIf you want to expand your knowledge of AT command syntax, click on the link

At command syntax

1.3 Exercise

● Schedule a cron job to run every 6 hours starting at midnight that saves it in a file called “users.list” information about logged users. The information must appear in the file with this format:

“Hello! This is the users log of 06:00:01There are 3users online now. Users who are connected areusername1username2username3”

● With AT command make a copy of three files of your home directory. File1 copy will be scheduled in 5 minutes.File2 copy will be scheduled in 10 minutes.File3 copy will be scheduled in 15 minutes.

28AF_IC06_ Orders, packages and schedulers