Web Analytics

See also ebooksgratis.com: no banners, no cookies, totally FREE.

CLASSICISTRANIERI HOME PAGE - YOUTUBE CHANNEL
Privacy Policy Cookie Policy Terms and Conditions
Appunti di informatica libera

[next] [previous] [top] [last] [indice generale] [violazione GPL] [translators] [docinfo] [indice analitico] [volume] [part]


Chapter 587.   Introduction to GNU/Linux

(1)

The operating system GNU/Linux is the result of a vary large contribution from various Unix environments. Therefore a large part of what concerns and composes GNU/Linux, is not exclusively for this environment.

This introductive chapter is aimed especially to readers without Unix experience, but who already has some knowledge of Unix could also find something useful.

587.1   Distinction between upper and lower case letters

The operating systems Unix, as well as GNU/Linux, are sensitive to the difference between upper and lower case letters. The difference is fundamental, so that the possible files named: Ciao, cIao, CIAO, ecc. are all different.

One should not confuse this characteristic with what happens in other environments such as, for example, MS-Windows 95/98/NT/2000, that keep the upper and lower case letters, but then do not consider them different when one refers to those file names.

When one considers the upper and lower case letters different, the context is often defined as case sensitive, whereas the other way round, when they are not considered different, the context is defined as case insensitive.

587.2   Root

In the Unix environments, there are frequent references to the term root in various contexts and with different meanings. Root is the root or origin, without other meanings. According to the context, it may represent either the origin or the starting point. For example, it is possible to have:

The situations in which this definition is used can be many more than the above. For the time being, it is important to be clear about the extension of this word's meaning.

587.3   Users

GNU/Linux, as the other systems derived from Unix, is multi-user. The characteristic implies a distrinction among different users. Basically there is a distinction between the system administrator, or superuser, and the other users.

The system administrator is the user that can do whatever he wishes, mainly he risks to produce serious damages even for small errors.

The common user is one who uses the system without pretending to organize it and has no possibility to start programs or access data that are not authorized to him.

587.3.1   Users entry

To use a system of this type, you must be registered in the system, i.e it is necessary to have received an account.

On a user point of view, the account is a name linked to a special password that allows him to be recognised and then allows him to access the system. In addition, an l'account establishes the membership to a user group.

The administrator name is always root, that of other users is decided individually.

587.3.2   Single Usage

The Unix systems and the programs that can be used on these systems, are not developped for a lack of attention: the orders are not discussed. Many small errors can cause a lot of damage if they are made by the user root.

It is very imporatnt to avoid as much as possible using the system as the administrator user (root) even when one is the single user of the computer.

587.4   Composition

The GNU/Linux operating system, as all other Unix operating systems, is composed basically by:

587.4.1   Start Up

The boot is the way in which an operating system can be started when the computer is switched on. Usually, the software recorded in the ROM of the computers that use disks, executes the instructions contained in the first sector of a diskette or, when it is missing, in the so called MBR (Master boot record) that is the first sector of the first hard disk. The code contained in the start up sector of the diskette or of the fixed disk runs the kernel (it starts it).

If GNU/Linux is installed on an i386 computer, the configuration and management of the start up process, happens mainly in one of the following modes:

587.4.2   Kernel

The kernel, as the name suggests, is the hazel of the operating system. The programs use the kernel for their activities and in this way they do not need to act directly on the CPU. Usually it is made by a single file, whose name could be vmlinuz (or zImage, bzImage or similar), but it can include also additional modules, to manage specific hardware components that must be activated and deactivated when the system is active.

When the kernel is started (by the boot process), it executes some diagnostic checks on the hardware components for which it has been enabled, then mounts (execute the mount) the main file system (root) and finallt starts the system initialization procedure (Init).

587.4.3   File system

The file system is the organization of the data within a disk or one of its partitions. On the Unix systems, it is not possible to distringuish among storage usits, as it happens with Dos, which distinguishes each disk or partition with a letter of the alpahabet (A:, B:, C:). On the Unix, systems all file systems that are available are concatenated together, so that they appear as a single global file system.

When a Unix system is started, the main file system, or root is activated, then other file systems can be connected to a directory or subdirectory of the main one. To access the data of a file system that is not the main one, it is necessary to link it, similarly to remove the storage unit that contains this file system, it is necessary to unlink it. This means that, on the Unix systems, it is not possible to mount a disketted, access it immediately and then unmount it as one wishes. One must tell the system to link the file system of the diskette, then one can use it as a part of the unique global file system. Finally the link must be interrupted and only then the diskette can be removed.

Image 587.1. Connection of a secondary file system at a link point (or mount point).

figure/a2-grafo-mount

The operation used to link a secondary file system to the global file system is called mount, this is the reason why normally the verb mount is used; to describe it. The opposite operation is called unmount and therefore the verb unmount is used. The directory where the other file system is mounted is called mount point.

587.4.4   Initialisation and process management

GNU/Linux, as all the Unix systems, works in multiprogramming, or multitasking, i.e. it can execute multiple programs, or computation processes, together. To achieve this, there is a manager of the computation processes: Init, implemented in pactice by the executable init, that is started immediately after the activation of the main file system, to execute the system initialisation procedure. In practice, it executes a series of instructions required to configure correctly the particular system that is starting up.

587.4.5   Daemon

Many services are performed by programs that are started during the system initialisation phase and silently execute their activities. Programs of this type are called daemon and this term should be considered as equivalent to ``server'' or ``expert''.

587.4.6   Network Services Management

On the Unix systems, the management of network services is an essential element and is normally present. The network services are executed by some daemons activated during the system initialisation phase. On the GNU/Linux systems, the network services are controlled by three main daemons:

A very important service in the local networks allows to share parts of the file system from and with other connected computers. This is obtained with the NFS protocol that allows therefore to use network file system.

587.4.7   Printing Management

All the operating system in multiprogramming (multitasking) have a system of output queues (spool). GNU/Linux normally uses the daemon lpd that is also capable of accepting remote print requests and of sending print requests to remote computers.

587.4.8   Logging and Access Control

The Unix systems, are not only in multiprogramming, the are also multi-user, i.e. may be used by multiple users at the same time. This characteristic of multi-user access on the Unix systems can be considered in the largest possible way, because it is possible to access the computer from the console, local terminals connected to serial ports, local terminal connected to the local area network and remote terminals connected via modem.

In these conditions, the system usage control is essential. Therefore every user that accesses the system, must have been previously authorized with a name and a password.

The phase when a user is recognised and is allowed to access the system, is called login. Similarly, the termination of the user activity is called logout.

587.4.9   Shell: command interpreter

What allows a user to interact with the operating system is the shell, that is in charge of interpreting and executing the user commands.

Practically, the usage of a Unix system is highly dependent on the used shell, consequently the choice of a shell is pretty important. The standard shell for the GNU/Linux system is called Bash (the program is bash).

A normal Unix shell performs the follwing main activities:

587.4.10   Service Programs for the system management

The internal commands of a shell are not sufficient to manage all system activities. The service programs, usually small size programs, are meant to be used for specific tasks of system administration or even just common activities.

The common usage service programs are usually found in the /bin/ and /usr/bin/ directories. Those reserved for usage by the system administrator, the root user, are normally contained in the /sbin/ and /usr/sbin/ directories where the starting letter ``s'', stands for superuser, with a clear reference to the administrator.

587.4.11   Software development tools

All the operating systems are a tool to produce software. The Unix operating system in particular, must be capable of compiling programs written in C/C++. The developmenmt tools of the GNU/Linux system, composed by a compiler for the C/C++ languages and other support programs are fundamental to install software distributed as not compiled sources.

587.5   System halting and re-starting

Every operating system in multiprogramming, the more so if it is also multiuser, must have a procedure to stop the system that must close all current activities before allowing the physical switching off of the computer.

GNU/Linux allows only the root user to start the procedure to stop the system with the following command:

shutdown -h now

Theoretically, on the i386 computers, it is possible to use the combination [Ctrl+Alt+Canc] to restart the system, but it is always preferable to call explicitely the procedure to stop the system, by specifying that a re-start is requested.

shutdown -r now

Usually, the only way for a common user to stop and re-start the system, is that of using the combination [Ctrl+Alt+Canc]. It is not elegant, but it is the better way the solve the problem.

587.6   Devices

The various hardware components of a computer, are represented in a Unix system as a device file, normally found in the /dev/ directory (device). When one wants to access directly a device, one can do that by using the name of the corresponding device file.

587.6.1   Tipi

There are two fundamental categories of devices:

The typical character device is the console or the serial port, whereas the typical block device is the disk unit. As an example, the table 587.1 shows the names of some GNU/Linux devices.

Table 587.1. Names of some GNU/Linux devices.

device description
/dev/fd0 the first diskette unit
/dev/fd0u1440 diskette unit with an explicit format specification: 1 440 Kibyte
/dev/hda the first ATA (IDE)fixed disk
/dev/hda1 the first partition of the first ATA (IDE) fixed disk
/dev/hdb the second ATA (IDE) fixed disk
/dev/sda the first SCSI fixed disk
/dev/sda1 the first partition of the first SCSI fixed disk
/dev/lp0 the first parallel port from the GNU/Linux point of view
/dev/lp1 the second parallel port from the GNU/Linux point of view
/dev/ttyS0 the first serial port

Some device file do not refer to real hardware components. The best known is /dev/null used as source for ``nothing'' or garbage.

587.6.2   Names

The names used for the device files have been chosen according to some mnemmonic approach or to the more frequent usage. However the device can be called in different ways.

On this point of view the GNU/Linux distributions are not all the same: anyone interprets those name in some way. For example, the device corresponding to the diskette unit for 1 440 Kibyte disketted, can be called with the following different names:

Things are even more complex if one looks at different Unix systems. Therefore: pay attention.

587.6.3   Dischi

The disk storage units are devices as all other ones, but may be used in two different ways according to the situatins: the disks, or their partitions can be considered as large files or as file containers (file system).

This distinction is important because often one happens to use diskettes that do not have any data structure because they have been used just as a unique file. The more common example is the boot diskettes that contain only the kernel: They are not diskettes that contain the kernel, but they are instead the kernel. (3)

The current view of storage units containing files and directories is an abstraction managed automatically by the operating system. This abstraction is called file system.

587.7   Organization of a file system Unix

Everything that is contained in a Unix file system is considered a file: also a directory is a file.

587.7.1   Regular File

When one wants to refer to a file in the strict meaning of the term, i.e. an archive of data, if one wants to avoid ambiguities should use the term regular file.

587.7.2   Directory

A directory is a special file containing references to other files. The data contained in a file system are organized as a hierarchy that may be presented through a tree, i.e. s special type of oriented graph that starts from a root and develops into branches and nodes. The image 587.2 shows an example of a tree.

Image 587.2. Tree.

        branch
       .----->o
       |            .------>o
       |    branch  |
root o----------->o-------->o node
       | 
       `------->o node

The root is the main node of this oriented graph, the branches represent the connections of the following nodes (child) with the origin (parent). The root correponds to a directory, whereas the following nodes can be either a directory, a data file or some other type of file.

To identify a node (file or directory) within this hierarchy, one can define the (path). The path is expressed as a sequence of node names that can be traversed, separated by a slash (/). The path hydrogen/carbon/hoxigen represents the traversal of nodes hydrogen, carbon and hoxigen.

Since a graph of this type has an starting node corresponding to the root, it is possible to distinguish two types of path: relative and absolute.

The root node has not a name like the other ones: it is represented by a forward slash (/), consequnetly a path that begins with that sysmbol, is an absolute path. For example, /cloro/sodio means an absolute path that starts from the root and then traverses cloro to finally reach sodio.

A tree is an oriented graph, because the branches have a direction (oriented arcs), i.e. every node has a parent node and may have child nodes with the root node representing the origin. When in a path one wants to go batch towards the parent, one can use instead of its name a special symbol represented by two dots in sequence (..). For example, ../potassio represents a relative path in which the final node, potassio, is reached by first going back to the parent node of the current position.

In some cases, to avoid misunderstandings, it is useful to identify explicetely the node corresponding to the current position. The symbol used for this purpose is the single dot (.). For this reason, the path hydrogen/carbon/hoxigen is exactly equal to ./hydrogen/carbon/hoxigen.

587.7.3   Links

A tree is correctly defined as such provided that there is a unique path from the root to any other node. In the Unix file system this is not always true; therefore they can be drawn as oriented graphs, but not necessaraly as trees. It is actually possible to insert additional connections, or link, which allow alternative paths. It is possible to have two different types of link: symbolic or physical (hard).

Generally it is preferable to use a symbolic link to distinguish the reality (or better the origin) from the fiction. By using a symbolic link one openly declares a secondary path and does not confuse it with the original path.

587.7.4   File names

There is no general rule to establish which characters can be used in a file name. There is just one way to avoid problems: the symbol / cannot be used because it is the way in which files are separated within a path; moreover it is wise to just use the letters of the english alphabet without accents, the numbers, the doti and the underscore.

By convention, on the Unix systems, the files that start with a dot are classified as hidden, because they are shown and used only when this is explicitely requested.

These files, i.e. those that start with a dot, are hidden for a good reason: the purpose is to avoid that,by using wildcard characters, one refers to the current directory (.) or to the parent directory (..). In a similar way one must pay attention when one wants to refer to these hidden files. The command rm -r .* does not only remove the file and the directory that start with a dot, but removes also . and .., i.e. at the end, the full file system!

587.7.5   Permessions

The files of a Unix file system are owned at the same time by a user and a user group. For this reason, one speak of an owner user and an owner group, or simply of an ownwr and a group.

The user that owns the files may modify the access permissions to his files, maybe by liniting the access to just himself/herself. There three types of access: read, write, execution. The meaning of the access type depends on the file.

For a regular files:

For a directory:

The file permissions allow to assign different provileges to different users, according to their class as file owner, users of the owner group (4), or other users. Therefore, the user of each file, may be in one of the categories: owner, group or other user.

It is possible to express the permessions in two different ways: by using an alphabetic string or a number.

587.7.5.1   Permessions expressed in the string format

The permissions can be represented by using a string of nine characters in which one can use the letters r, w, x, or a dash (-). The presence of the letter r means a read permission, the letter w means a write permission and the letter x means an execute permission.

The first three characters of the string represent the privileges of the owner, the following three characters represent the privileges of the users in the same group and the last three characters represent the privileges of the other users.

Examples

rw-r--r--

The owner user can access it for reading and writing, whereas the users of the group and the other users can access it only for read.

rwxr-x---

The owner user can access it for read, write and execute; the users of the group can access it for read and execute and the other users have no access at all.

rw-------

The owner user can access it for reading and writing, whereas any other user cannot access it at all.

587.7.5.2   Permessions expressed in numeric form

The permissions can be represented as a sequence of three numeric digits with the first one representing the privileges of the owner user, the second one representin the privileges of the group and the third representing the privileges of the othe users. The read permission corresponds the number four, the write permission corresponds to the number two and the execute permission corresponds to the number one. The number which represents the full permission for each type of user is obtained by summing up the numbers corresponding to the allowed privileges.

Examples

644

The owner user can access it for read and write (4+2), whereas the group members and the other users can access it for read only.

750

The owner user can access it for read, write and execute (4+2+1); the group members can access it for read and execute (4+1); the other users have no access at all.

600

The owner user can access it for read and write (4+2), whereas all other users cannot access it at all.

587.7.5.3   S-bit

The file permissions are stored as a sequence of 9 bit, where each group of three represents the permissions for a user category (the owner, the group, the others).

Together to these 9 bit there are three more ones, stored at the beginning, that allow to identify corresponding modes: SUID (Set user identifier), SGID (Set group identifier) e Sticky (Save text image). They are special attributes that are mainly use for the executable files. Usually they are not used and common users ignore their existence.

This explains why the permission expressed in the numeric format (octal) have four digits, with the first one being normally zero (this subject will be re-examined in the chapter ##en-capitolo-permessi##).

For example, the mode 0644 represents the permission for the user access for read and write, whereas all other users can access it only for read.

The presence of the special bits can be added also in the string representation. The following list shows the octal number and the corresponding code.

As you may notice, this coding replaces the execution permit. If the execution permit is not activated, the letter(s or t) is written in upper case.

587.7.6   Dates

Among the file attributes there is also the date-time indication:

587.8   Users and access

Once a Unix system is started, before displaying the prompt of the shell, it is necessary for the system to recognise the user through the access procedure (login). It requests the entry of a user name (as previously registered) and the password (password) for that user. Exceptionally the user might not have a password, as it happens for the mini systems based on diskettes, created to allow special maintenance operations.

There are two types of users: the administrator, whose name is root, and the other common users. The root user's actions are not limited in any way, the other users depend on the permissions assigned to the files (and directories) in addition to the limits directly requred by some programs.

Theoretically, it is possible to use a personal computer just as root user. In practice, this is not advisable because one misses the meaning of the file and directory permissions, and most of all does not use the security systems that exist to prevent errors. To understand this concept, it is sufficient to think about what happens in a Dos system, when one uses a command such as the following:

C:\> DEL *.*

Before starting the deletion, the Dos requires a confirmation because there is no other type of control. In a Unix system, usually that is not done: the deletion starts immediately without requesting any confirmation. If the permission allow the deletion of files only to the root users, a different user cannot make damages.

In conclusion, the root user must pay a lot of attention to what is doing because he can access any function or file of the system, moreover the system does not object to his behaviour. A common user is insetad limited by the file permission and by programs, that can stop him from some activities, consequently he can work with less attention.

587.8.1   adduser o useradd

Usually the GNU/Linux distributions include the service program called adduser, or useradd, which allows the root user to add a new user. The user name must not have more than eight characters and all the other requested data can just be left with the default value. After the first installation of a GNU/Linux system, it is important to create a personal user that can access the system without the privileges of the administrator.

587.8.2   exit

The shell usually includes the command exit that terminates its execution. If it is a shell started automatically by the system, the system will automatically start again the access procedure.

587.9   Command interpretation

As already discussed, the command interpretation is performed by the shell. The command interpretation implies the substitution of some symbols that have a special meaning.

587.9.1   File globbing

The glob (or globbing) is the method that allows, through a symbolic model, to specify a group of file names. It is similar to the use of wildcard characters in Dos, with the fundamental difference that their substitution is done by the shell and not the programs. Usually following symbols can be used:

Since it is the shell that executes the substitution of wildcard charcters, a typical syntax of a service program is as follows:

program [options] [file...]

In the Dos systems, often the opposite convention is used, with the file name written before the options. On a logical point of view, the Dos approach might look more correct: first the object target of the action is written and then the mode is written. However by doing thar, one gets some disadvantages:

In practice, the simplification used by Dos it is the source of many complications for the programmers and the users.

587.9.2   Tilde

Usually, the shell is in charge of executing the substitution of the tilde character (~). In the Unix systems, every user has a personal directory, commonly known as home directory. The symbol ~ alone is substituted by the shell with the personal directory of the current user, whereas a user name precededed by the symbol ~, is replaced by the shell with the personal directory of the specified user.

587.9.3   Environment Variables

The environment variables are managed by the shell and constitute one of the modes used to configure the system. The programs can read some variables that are required and modify their behaviour according to their content.

A command line can refer to an environment variable: the shell works at changing the reference with its content.

587.10   Redirection and pipeline

The programs, when they are executed, can use some standard channels for the data stream (input/output). They are: standard input, standard output and standard error.

The standard input is usually represented by data coming from the terminal keyboard. The standard output and the standard error are normally produced on the terminal display.

By using the shell it is possible to redirect these data streams, for instance by attaching the standard output of a program to the standard input of another one, thus creating a pipeline.

587.10.1   Redirection of the standard input

program < data_file

The standard input is redirected by using the ``less than'' sysmbol (<) followed by the alternative data source. The program to the left of the symbol < receives as standard input the content of the file written to ther right.

Esempi

sort < list.txt

It displays the content of the file list.txt after sorting it.

587.10.2   Redirection of the standard output

program > data_file

The standard output is redirected by using the ``greater than'' sysmbol (>) followed by the alternative data destination. The program on the left of the symbol > sends its standard output into the file written at the right and created for this purpose.

The standard output can be added to an existing file; in this case the symbol >> is used.

Examples

ls > list.txt

It creates the file list.txt with the result of the execution of ls.

ls >> list.txt

It adds to the file list.txt the result of the execution of ls.

587.10.3   Redirection of the standard error

program 2> data_file

The standard error is redirected by using the symbol 2> followed by the alternative data destination. The program to the left of the symbol 2> sends its standard error into the file listed to the right which is created for this purpose.

The standard error may be added to an existing file; in this case the symbol 2>> is used.

Examples

validate 2> errors.txt

It creates the file errors.txt with the result of the execution of the hypothetical program validate.

validate 2>> errors.txt

It adds to the file errors.txt the results of the execution of the hypothetical program validate.

587.10.4   Pipeline

program1 | program2 [ | program3...]

The standard output of a program is redirected into the standard input of another program, by using the vertical bar symbol (|). The program to the left of the symbol | sends its standard output into the standard input of the program to the right.

In the program syntax diagram, this symbol normally has the meaning of a choice among alternative options, keywords or other arguments. In this case it is used to construct a pipeline.

Examples

ls | sort

It reorders the result of the command ls.

ls | sort | less

It reorders the result of the command ls and then it uses the program less to show it on the screen.

587.11   Common Usage Commands and service programs

Generally, the term comando should refer to the internal commands of a shell, whereas the term utility, or simply program, should refer to the executable programs that are external to the shell. In practice, since a program is started by using a shell command, with this term (command) one refers often to both internalshell commands or (if they are missing) to external commands or service programs.

Naturally, this approach is valid provided that we refer to common usage service programs, not too complex, that use a basic input/output system. It would not be correct to define command a report program or an Internet browser.

587.11.1   Syntax Interpretation

The syntax of a program or commands is based on pretty simple rules.

Naturally, it can happen that symbols used to represent the sysntax, are needed in the arguments of a command or a program. The clearest examples are:

It is necessary to pay attention to the context, in order to interpret correctly the meaning of a syntax, and to observe the possible proposed examples.

587.11.2   Typical organization

The typical service program has the following syntax:

program [options] [file...]

In this case the program name is actually program.

Options

Normally one or more possible options are accepted by using a letter of the alphabet preceded by a dash (-a, -b,...). These may be used separately or grouped together by a single dash followed by all the option letters that one wants to use. Therefore:

program -a -b

can be translated in the following command:

program -ab

The more recent programs include descriptive options preceded by two slashes. When this type of options are used, one is not allowed to use aggregation as seen above.

Some options require the additional presence of another argument.

File

Most of the service programs perform some processing of files and then produces a result, which is normally writtem to the standard output. often when no file is included in the arguments, the input is obtained from the standard input.

Some programs allow to use a dash (-) to replace the reference to the input or output file name, in order to refer to the standard input and to the standard output.

587.12   Executable program

Generally, when the term ``program'' is used, one does not clarify its real extension. The term can be used to identify something composed by a single executable file, or a small system composed by mutiple components, with a single front end system.

Often, especially within this document, when we want to make a reference to a program consisting of a set of components, or to some abstraction for which it is not important to know the way in which it is started, we refer to it with a name without special enphasis generally starting with an upper case letter. For example, if we look to the shell Bash, which we have already mentioned, the name of the executable program is in reality bash.

To avoid ambigouities, when one wants to refer to an executable program, one should specify that it is actually this, i.e. an ``executable'' and should show it, by using enphatic typing and by writing the name exactly in the same way used to start it.

587.13   The ABC of the GNU/Linux commands

In the following sections you will find a summary description of some fundamental service programs. The example are based on the Bash shell that currently is standard for GNU/Linux.

It is important to notice that in the examples a different prompt is used if it refers to a commmand entered by a normal user or from the administrator: the dollar ($) represents an action of a normal userr, whereas the sysmbol # represents an action of the root user.

If you wish, you can look at the table 587.2, at the end of the chapter, to get an idea of the GNU/Linux commands compared to the corresponding ones of Dos.

587.13.1   ls

ls [opzioni] [file...]

It produces a list of the files in a directory.

Examples

ls

It produces a list of the current directory.

ls -l *.doc

It lists all files which end with the suffix .doc and that exist in the current directory. The list is more detailed becaused of the option -l.

587.13.2   cd

cd [directory]

It changes the current directory.

Examples

cd /tmp

It changes the current directory, by making it /tmp/.

cd ciao

It changes the current directory, by moving to the directory ciao/ which is a descendent of the current one.

cd ~

It changes the current directory, by moving to the personal directory of the user.

cd ~daniele

It changes the current directory, by moving to the personal directory of the user daniele.

587.13.3   mkdir

mkdir [opzioni] directory...

It creates a new directory.

Examples

mkdir cloro

It creates the directory cloro/, as a descendent of the current one.

mkdir /sodio/cloro

It creates the directory cloro/, as adescendent of the /sodio/.

mkdir ~/cloro

It creates the directory cloro/, as a descendent of the personal directory of the current user.

587.13.4   cp

cp [opzioni] origin... destination

It copies one or more files (possibly a directory) to a unique destination.

The copy in the Unix systems does not work in the same way as in the Dos systems mainly because of two factors: the wildcard characters (i.e. the file globbing) are expanded by the shell before executing the command and the Unix file system can use symbolic links.

If only names of regular files are specified, the first is copies onto the second one, i.e the copied files has the name written as a destination. If the second name is a directory, the file is copied to the directory with the same name as the origin. If multiple files are listed, the last name must be a directory and all listed files are copied to the destination directory. Consequently, when wildcard characters are used, the destination must be a directory. If no special options are used, directories are not copied.

If you have used Dos you might have used the command COPY to copy a group of files into another group with the names partially changed, as in the following example: COPY *.bak *.doc. This approach, with the Unix systems, cannot work.

The files listed in the origin might actually be symbolic links. If no additional options are used, they are copied as if they were regular files; i.e the copy is produced from the original file and no copy of the links will be produced.

Some options

-a

It is equivalent to -dpR, it is useful to store or copy the symbolic links as they are.

-d

It copies the symbolic links as they are, instead of copying the file to which the links refer.

-f

It is used to overwrite the destination file.

-l

It creates a hard link instead of copying the file.

-p

It keeps the original properties and permissions.

-r

It copies files and directories in a recorsive way (including subdirectories), by considering everything that is not a directory as a regular file.

-R

It copies files and directories in a recorsive way (including subdirectories).

Examples

cp -r /test/* ~/test1

It copies the content of the directory /test/ into ~/test1/ by copying also possible subdirectories included in /test/.

If ~/prova exists already and if it is not a directory, this file is overwritten, and its original content is lost.

cp -r /test ~/test1

It copies the directory /test/ into ~/test1/ (by adding test/ to ~/test1/) by copying also possible subdirectories included in /test/.

cp -dpR /test ~/test1

It copies the directory /test/ into ~/test1/ (by adding test/ to ~/test1/) by copying also possible subdirectories included in /test/, by keeping the original permissions and by reproducing the possible symbolic links eventuali.

587.13.5   ln

ln [options] origin... destination

It creates one or more links of files (including directories) to a unique destination.

The creation of a link is an action similar to a copy. Therefore the same considerations made about the command cp, on the different behaviour between Unix and Dos, apply also in this case.

If only two regular files are specified, the second one becomes a link of the first one. If the second name is a directory, it will be used to store as many links as the files and directories specified as the orgin. The names will be the same as those of the origin. If multiple files are listed, the last name must correspond to a directory.

It is acceptable to create links that refer to other links.

It is possible to create two different types: physical links and symbolic links. The latter ones are preferable (unless there are good reasons to use physical links). Unless it is requested differently by using options, physical links are generated instead of symbolic links.

Some options

-s

It creates a symbolic link.

-f

It forces the overwriting of files or links that exist already in the destination.

Examples

ln -s /test/* ~/test1

It creates, in the destination ~/test1/, a nunber of symbolic links corresponding to all files and directories that are found within /test/.

ln -s /test ~/test1

It creates, in the destination ~/test1, a symbolic link corresponfing to the file or directory /test. If the ~/test1 is a directory, the link ~/test1/test; is created, if the ~/test1 does not exist, the link ~/test1 is created.

587.13.6   rm

rm [options] name...

It removes the files listed as arguments. If no required options are included, the directories are not removed.

Some options

-r | -R

It removes the contents of the directory in recorsive mode.

Examples

rm test

It removes the file test.

rm ./-r

It removes the file -r whose name starts with a dash, without confusing it with the option -r (recorsion).

rm -r ~/various

It removes the directory various/ which is found within the personal directory, together with all possible subdirectories.

Watch out

rm -r .*

It removes all files and directories starting from the roor directory! Actually it removes everything.

This is a typical error when one wants to delete all hidden directories (i.e. those starting with a dot) contained within the current directory. The disaster happens because in the Unix systems, .* represents also the current directory (.) and the previous or parent directory precedente is (..).

587.13.7   mv

mv [options] origin... destination

It moves the files and directories. If only two names are listed (file or directory), the first one is moved and renamed in order to obtain what is listed as destination. if more elements (files or directories) are listed, the last attribute must be a directory: all listed elements are moved in the destination directory. If different file systems are involved, only the regular files are moved (therefore: no links and no directories).

In the Unix systems it is not possible to simply rename a file or a directory as it happens with Dos. If one needs to change a name, he must move it. This has also some implications in the management of the directory permissions.

Examples

mv test test1

It changes the name of the file (or directory) test into test1.

mv * /tmp

It moves into /tmp/, all files and directories that exist in the current directory.

587.13.8   cat

cat [options] [file...]

It catenates files and directs their contents to the standard output. The command outputs in sequence the files listed as arguments by using the standard output (i.e to the screen), in practice in a similar way to the command TYPE of Dos. If no file name is includes, the standard input is used for input.

Table 587.2. Comparaison of some Dos commands and the corresponding ones for GNU/Linux by using examples.

Dos GNU/Linux
DIR ls -l
DIR /W ls
MD PIPPO mkdir pippo
CD PIPPO cd pippo
RD PIPPO rmdir pippo
COPY *.* \PROVA cp * /prova
XCOPY *.* \PROVA /E /S cp -dpR * /prova
REN ARTICOLO LETTERA mv articolo lettera
MOVE *.* \PROVA mv * /prova
DEL ARTICOLO rm articolo
DELTREE TEMP rm -R temp
TYPE LETTERA cat lettera
TYPE LETTERA | MORE cat lettera | more
HELP DIR man ls
FORMAT A: /N:18 /T:80 fdformat /dev/fd0u1440
FORMAT A: /N:9 /T:80 fdformat /dev/fd0u720
DISKCOPY A: B: cp /dev/fd0 /dev/fd1
DISKCOPY A: A: cp /dev/fd0 /tmp/pippo ; cp /tmp/pippo /dev/fd0
KEYB IT loadkeys it
CLS clear
BACKUP C:\DATI\*.* A: /S tar cvf /dev/fd0 -L 1440 -M /dati
FIND "saluti" PRIMO.DOC grep "saluti" primo.doc
FOR %A IN (*.DOC) DO FIND "saluti" %A grep "saluti" *.doc
MEM free
Examples

cat test test1

It displays the content of the test and test1 files.

cat test test1 > test2

It produces the file test2 as the sequential catenation of the test and test1 files.

Appunti di informatica libera 2003.06.29 --- Copyright © 2000-2003 Daniele Giacomini -- daniele @ swlibero.org


1) Translation last update on 2003.06.19 from Mario Pesce mario @ datamission.co.uk (original chapter was 5).

2) The substitution of the characters, or metacharacters, is the process used to translate some special characters in a list of files and corresponding directories. In the Unix environments the term globbing is used to refer to this concept.

3) It is also possible to have boot diskettes organized with a file system, but this particular type of diskettes is described later on.

4) The owner group is the group of the owner user.


It should be possible to link to this page also with the name introduction_to_gnu_linux.html

[next] [previous] [top] [last] [indice generale] [violazione GPL] [translators] [docinfo] [indice analitico]


aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - bcl - be - be_x_old - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - co - cr - crh - cs - csb - cu - cv - cy - da - de - diq - dsb - dv - dz - ee - el - eml - en - eo - es - et - eu - ext - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gan - gd - gl - glk - gn - got - gu - gv - ha - hak - haw - he - hi - hif - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kaa - kab - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mdf - mg - mh - mi - mk - ml - mn - mo - mr - mt - mus - my - myv - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - quality - rm - rmy - rn - ro - roa_rup - roa_tara - ru - rw - sa - sah - sc - scn - sco - sd - se - sg - sh - si - simple - sk - sl - sm - sn - so - sr - srn - ss - st - stq - su - sv - sw - szl - ta - te - tet - tg - th - ti - tk - tl - tlh - tn - to - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu -