SlideShare una empresa de Scribd logo
1 de 24
Descargar para leer sin conexión
1
Suplemments

Capítulo 1 Escritura avanzada de shell
Conceptos clave
•
•

•
•
•
•

Linux utiliza el mecanismo de scripts, en donde los archivos de scripts de texto
pueden ser ejecutados por un intérprete especificado en la línea inicial.
Dentro de un script bash, los argumentos provistos al invocar un script están
disponibles como parámetros posicionales (por ejemplo, las variables $1, $2,
...).
El comando incorporado read se puede utilizar para leer la entrada desde la
"entrada estándar" del teclado.
La shell utiliza una sintaxis if ... then ... [else ...] fi para
implementar ramas condicionales.
El comando test suele utilizarse como comando condicional en ramas if ...
then.
La shell bash utiliza una sintaxis for ... in ... do ... done para
implementar bucles.

Escritura de shell
En capítulos anteriores a este cuaderno discutimos la creación de scripts simples de
shell. Estos scripts hacían algo más que ejecutar una serie de comandos, opcionalmente
aceptando la salida del usuario para definir variables.
Sin embargo, los scripts de shell son capaces de mucho más. Este capítulo agregará
algunas herramientas valiosas, permitiéndole a sus scripts tomar decisiones
si/entonces/otro, en inglés if/then/else, y retroalimentar una serie de acciones de modo
indefinido.
Ramas: if ... then ... [else ...] fi
Sintaxis Bash para ramas
Al programar, las ramas le permiten a los programas escoger entre una o dos (o más)
rutas alternas de ejecución. La shell bash, al igual que la mayoría de los lenguajes de
programación, utiliza la palabra si, en inglés if, para significar una rama. Más
formalmente, bash utiliza la siguiente sintaxis.
if condición
then
comando(s)
...
fi

o
if condición
then
2
Suplemments

comando(s)
...
else
comando(s)
...
fi

Los comandos en estas estrofas se ejecutan si la condición tiene "éxito".
Los comandos en la estrofa se ejecutan si la condición "fracasa".
Al utilizar esta sintaxis, los retornos de carro son importantes (por ejemplo, el if y then
deben presentarse en líneas separadas), pero las sangrías no lo son.
¿Qué espera bash como condición? A diferencia de la mayoría de los lenguajes de
programación, bash no tiene sintaxis interna para hacer comparaciones (¿tales como $
A == apple, o $B >25). En su lugar, bash se concentra en la razón de su diseño inicial:
la ejecución de comandos. Cualquier comando se puede utilizar para la condición. La
shell bash ejecutará el comando y examinará su valor de retorno. Si el comando tiene
"éxito"(devuelve un valor de retorno de 0), la primera estrofa de comandos se ejecutará.
Si el comando fracasa (devuelve un valor de retorno no igual a cero), la segunda estrofa
de comandos se ejecutará (si existe).
La siguiente modificación para el script de elvis shut sirve de ejemplo.
[elvis@station elvis]$ ls
example.sh shut
[elvis@station elvis]$ cat shut
#!/bin/bash
# the first argument should be the name of the file to shut.
if ls $1
then
chmod 600 $1
else
echo "The file $1 does not exist."
fi
[elvis@station elvis]$ ./shut example.sh
example.sh
[elvis@station elvis]$ ./shut foo
ls: foo: No such file or directory
The file foo does not exist.

En el primer caso, el comando ls tiene "éxito" (porque el archivo example.sh existe, el
valor de retorno del comando ls es 0). Como resultado, la primera estrofa de la cláusula
if ... then ... else ... fi se ejecuta. En el segundo caso, el archivo foo no
existe, por lo tanto la segunda estrofa (otro) de la cláusula se ejecutó.
El comando test
El ejemplo anterior es bastante raro. El comando ls se ha forzado a realizar una labor
para la cual no está diseñado: probar si existe un archivo. Aunque puede hacer esto, los
mensajes que imprime distraen la atención. Si el archivo especificado existe, su nombre
3
Suplemments

se imprime en la pantalla. Si el archivo no existe, entonces un mensaje de error se
imprimirá en pantalla. Si solo hubiera un comando que comprobara la existencia del
archivo y retornara el código de retorno apropiado, sin emitir otros mensajes...
Lo hay. El comando se llama test. El comando test fue diseñado específicamente para
este propósito: para ser un comando condicional en frases bashif ... then. Más
específicamente, el comando test está diseñado para comparar cadenas de texto,
números enteros y atributos de archivo. Nunca genera salida, en cambio, se comunica
mediante su valor de retorno. El comando test retorna 0 si la expresión que evalúa es
verdadera y un valor de no cero si no lo es.
La mayoría de argumentos de test se parecen a las opciones de la línea de comandos.
Por ejemplo, -e examina si existe un archivo. El guión anterior podría mejorarse
remplazando ls con test -e.
[elvis@station elvis]$ cat shut
#!/bin/bash
# the first argument should be the name of the file to shut.
if test -e $1
then
chmod 600 $1
else
echo "The file $1 does not exist."
fi
[elvis@station elvis]$ ./shut example.sh
[elvis@station elvis]$ ./shut foo
The file foo does not exist.

Observe que el comando test examina la existencia de un archivo, pero no genera
mensajes para distraer la atención del usuario.
El siguiente cuadro lista algunas de las opciones más comunes para examinar los
atributos de los archivos.
Table 1. Expresiones de test para examinar atributos de archivos
Expresión

Condición

-d ARCHIVO

El ARCHIVO existe y es un directorio.

-e ARCHIVO

El ARCHIVO existe

-f ARCHIVO

El ARCHIVO existe y es un archivo regular.

-r ARCHIVO

El ARCHIVO existe y es leíble.

-w ARCHIVO

El ARCHIVO existe y es escribible.

-x ARCHIVO

El ARCHIVO existe y es ejecutable.

FILE1

-nt ARCHIVO2 El FILE1 en más reciente que ARCHIVO2.
4
Suplemments

Table 2. Expresiones de test para comparar cadenas de texto
Expresión

Condición

[-n] CADENA DE TEXTO la longitud de CADENA DE TEXTO es mayor que cero.
-z CADENA DE TEXTO

la longitud de CADENA DE TEXTO es cero.

CADENA1

= CADENA2

CADENA1

y CADENA2 son iguales.

CADENA1

!= CADENA2

CADENA1

y CADENA2 no son iguales.

Por último, el siguiente cuadro lista las expresiones que permiten al comando test
utilizar una lógica compuesta.
Table 3. Expresiones lógicas para el comando test
Expresión

Condición

EXPRESIÓN1

-a EXPRESIÓN2 Tanto EXPRESIÓN1 como EXPRESIÓN2 son verdaderas.

EXPRESIÓN1

-o EXPRESIÓN2 EXPRESIÓN1 o EXPRESIÓN2 es cierta.

! EXPRESIÓN

EXPRESIÓN

es falsa.

Estos cuadros ofrecen al estudiante una serie de expresiones útiles. Para obtener una
lista completa, consulte la página de manual test(1).
Expresión alterna para test: [ expresión ]
Como el comando test es tan utilizado en scripts bash se ha desarrollado una sintaxis
más corta. Las siguientes dos expresiones son equivalentes.
test expresión
[ expresión ]

A manera de ejemplo, el script de elvis shut se puede reescribir así:
[elvis@station elvis]$ cat shut
#!/bin/bash
# the first argument should be the name of the file to shut.
if [ -e $1 ]
then
chmod 600 $1
else
echo "The file $1 does not exist."
fi

Observe que el comando test se ha remplazado con la sintaxis alterna [ ... ].
5
Suplemments

Al utilizar la sintaxis alterna, se debe tener cuidado de incluir un espacio después de
abrir el paréntesis y antes de cerrarlo.[1] Por ejemplo, las siguientes dos construcciones
del comando test están erradas.
[-e foo.sh ]
[ -e foo.sh]

La siguiente construcción está realmente errada.
[-e foo.sh]

Bucles: for ... in ... do ... done
Sintaxis bash para bucles
Los bucles son quizás la estructura de programación más útil para automatizar trabajos
convencionales. Los bucles permiten la repetición de una serie de comandos,
usualmente con leves variaciones en cada iteración. Estas variaciones se suelen ejecutar
mediante una variable conocida como un iterator. Para cada iteración del bucle, la
variable toma un valor diferente. Por ejemplo, elvis pudo utilizar el siguiente guión para
afirmar su afecto por su colección de mascotas domésticas.
[elvis@station elvis]$ cat nice
#!/bin/bash
for PET in kitty doggy gerbil newt
do
echo "nice $PET."
done
[elvis@station elvis]$ ./nice
nice kitty.
nice doggy.
nice gerbil.
nice newt.

En este script, la variable de shell PET se utiliza como iterador. Con cada iteración del
bucle, la variable adquiere un valor diferente.
Más formalmente los bucles for ... in ... do ... done en bash utilizan la
siguiente sintaxis.
for iterador in lista
do
comando(s)
...
done

Para cada repetición del bucle, la variable iterator evaluará las palabras individuales
en la expresión lista.
6
Suplemments

Para un ejemplo más práctico, revisitaremos el guión de elvis shut. El usuario elvis
desearía modificar su guión, con el fin de poder especificar archivos múltiples en la
línea de comandos. Para implementar este cambio, esencialmente toma su guión
anterior y lo delimita dentro de un bucle for ... in .. do ... done. En lugar de
utilizar el primer parámetro posicional ($1) directamente, elvis utiliza un iterador a
través de todos los argumentos provistos en la línea de comandos.
[elvis@station elvis]$ cat shut
#!/bin/bash
# the first argument should be the name of the file to shut.
for FILE in $*
do
if [ -e $FILE ]
then
chmod 600 $FILE
else
echo "The file $FILE does not exist."
fi
done

A continuación, elvis utiliza el guión para modificar los permisos en los archivos
example.sh y nice.
[elvis@station elvis]$ ls -l
total 12
-rwxr-xr-x
1 elvis
elvis
212 Sep 3
-rwxr-xr-x
1 elvis
elvis
77 Sep 4
-rwxrwxr-x
1 elvis
elvis
188 Sep 4
[elvis@station elvis]$ ./shut example.sh biz nice
The file biz does not exist.
The file baz does not exist.
[elvis@station elvis]$ ls -l
total 12
-rw------1 elvis
elvis
212 Sep 3
-rw------1 elvis
elvis
77 Sep 4
-rwxrwxr-x
1 elvis
elvis
188 Sep 4

10:56 example.sh
12:16 nice
12:31 shut
baz

10:56 example.sh
12:16 nice
12:31 shut

Observe el uso de la variable $* para generar la lista. El siguiente cuadro sugiere otros
trucos del oficio.
Table 1. Técnicas comunes para generar listas iterativas
Cuando utilice...

...$i itera a través de ...

for i in $*

los argumentos de línea de comando del script

for i in /etc/*.conf

el del archivo coincidente con el comodín /etc/*.conf

for i in $(command)

las palabras devueltas por el comando command.

Ejemplos
7
Suplemments

Un script para "empacar" directorios
El usuario elvis se da cuenta que a menudo está "tarring up" (archivando) directorios
que no está utilizando. Decide crear un guión llamado pack, el cual le ayudará a
archivar directorios más rápidamente.
El script pack espera que uno o más directorios sean listados como argumentos. Para
cada directorio, el script creará un archivo llamado como el directorio con la extensión
.tgz agregada. Sólo si la creación del archivo tiene éxito, el script eliminará el
directorio original.
Como elvis considera detenidamente los directorios que los usuarios pueden especificar,
se da cuenta que los directorios . y .. pueden causar problemas (¿por qué?), entonces
les agrega una exclusión.
[elvis@station elvis]$ cat pack
#!/bin/bash
for DIR in $*; do
if [ -d $DIR ]
then
if [ "$DIR" == "." -o "$DIR" == ".." ]
then
echo "skipping directory $DIR"
else
tar cvzf $DIR.tgz $DIR && rm -fr $DIR
fi
else
echo "skipping non directory $DIR"
fi
done

El guión recorre todos los argumentos de línea de comandos provistos.
El guión confirma que el argumento existe y que se refiere a un directorio.
El guión aquí comprueba que el usuario no tiene el directorio . o .. especificado.
En la práctica, hay aún algunos nombres de directorios que pueden causar
problemas. ¿Puede usted pensar en alguno?
Por último, aquí hay una línea que trabaja duro. Observe que el directorio original
se elimina sólo si el comando tar tiene éxito.
Él ensaya su script en estos dos directorios de prueba.
[elvis@station elvis]$ mkdir test{1,2}
[elvis@station elvis]$ touch test{1,2}/{one,two,three,four}
[elvis@station elvis]$ ls -R
.:
pack test1 test2
./test1:
four one

three

two
8
Suplemments

./test2:
four one three two
[elvis@station elvis]$ ./pack test1 test2
test1/
test1/one
test1/two
test1/three
test1/four
test2/
test2/one
test2/two
test2/three
test2/four
[elvis@station elvis]$ ls -R
.:
pack test1.tgz test2.tgz

Los directorios de prueba se han "empacado".
Ejercicios en línea
Lab Exercise
Objetivo: Utilizar scripts shell para automatizar la rotación de imágenes.
Estimated Time: 30 mins.
Especificaciones
Crear un script llamado rotate_cw que sirva para rotar imágenes 90 grados. Para
realizar la rotación, debería utilizar el comando convert (analice la página de manual
convert(1) y preste mucha atención a la opción rotate). A continuación presentamos un
ejemplo de uso del comando convert para rotar una imagen.
[elvis@station elvis]$ cp /usr/share/pixmaps/redhat-main-menu.png .
[elvis@station elvis]$ convert -rotate 90 redhat-main-menu.png
/tmp/redhat-mainmenu.png

El archivo /tmp/redhat-main-menu.png es la misma imagen de redhat-mainmenu.png rotada 90 grados.
El script debe esperar como argumentos múltiples nombres de archivo de las imágenes
que van a ser rotadas. Debe asumir que los nombres de archivo no contienen
componentes de directorio (por ejemplo, se referirán a archivos en el directorio actual).
El guión debe generar un nuevo archivo de la imagen rotada y si la nueva imagen se
genera correctamente, remplace la imagen original con la imagen rotada (dando la
apariencia de rotar imágenes "en su lugar".
Abandone el guión en su directorio de inicio y asegúrese que tiene permisos ejecutables.
9
Suplemments

Deliverables
Question 1

1. Un script bash ejecutable llamado ~/rotate_cw, el cual rotará imágenes en el
directorio local cuyos nombres de archivo (sin componentes de directorio) pasan
como argumentos.

Capítulo 2 Codificación de caracteres e internacionalización
Conceptos clave
•
•

•
•

•

When storing text, computers transform characters into a numeric
representation. This process is referred to as encoding the text.
In order to accommodate the demands of a variety of languages, several
different encoding techniques have been developed. These techniques are
represented by a variety of character sets.
La técnica más sofisticada de codificación se conoce como el Conjunto
Universal de Caracteres (UCS)
La técnica de codificación en Linux de Red Hat Enterprise se conoce como
UTF-8, la cual permite la flexibilidad de Unicode y a su vez retiene la
compatibilidad de ASCII.
La variable de entorno LANG se utiliza para especificar un lenguaje preferido del
usuario y la codificación de caracter.

¿Qué son archivos?
Linux, like most operating systems, stores information that needs to be preserved
outside of the context of any individual process in files. (In this context, and for most of
this Workbook, the term file is meant in the sense of regular file). Linux (and Unix)
files store information using a simple model: information is stored as a single, ordered
array of bytes, starting from at first and ending at the last. The number of bytes in the
array is the length of the file. [1]
What type of information is stored in files? Here are but a few examples.
•

•
•

The characters that compose the book report you want to store until you can
come back and finish it tomorrow are stored in a file called (say)
~/bookreport.txt.
The individual colors that make up the picture you took with your digital camera
are stored in the file (say) /mnt/camera/dcim/100nikon/dscn1203.jpg.
The characters which define the usernames of users on a Linux system (and their
home directories, etc.) are stored in the file /etc/passwd.
10
Suplemments
•

The specific instructions which tell an x86 compatible CPU how to use the
Linux kernel to list the files in a given directory are stored in the file /bin/ls.

What is a Byte?
At the lowest level, computers can only answer one type of question: is it on or off?
What is it? When dealing with disks, it is a magnetic domain which is oriented up or
down. When dealing with memory chips, it is a transistor which either has current or
doesn't. Both of these are too difficult to mentally picture, so we will speak in terms of
light switches that can either be on or off. To your computer, the contents of your file is
reduced to what can be thought of as an array of (perhaps millions of) light switches.
Each light switch can be used to store one bit of information (is it on, or is it off).
Using a single light switch, you cannot store much information. To be more useful, an
early convention was established: group the light switches into bunches of 8. Each
series of 8 light switches (or magnetic domains, or transistors, ...) is a byte. More
formally, a byte consists of 8 bits. Each permutation of ons and offs for a group of 8
switches can be assigned a number. All switches off, we'll assign 0. Only the first
switch on, we'll assign 1; only the second switch on, 2; the first and second switch on, 3;
and so on. How many numbers will it take to label each possible permutation for 8 light
switches? A mathematician will quickly tell you the answer is 2^8, or 256. After
grouping the light switches into groups of eight, your computer views the contents of
your file as an array of bytes, each with a value ranging from 0 to 255.
Data Encoding
In order to store information as a series of bytes, the information must be somehow
converted into a series of values ranging from 0 to 255. Converting information into
such a format is called data encoding. What's the best way to do it? There is no single
best way that works for all situations. Developing the right technique to encode data,
which balances the goals of simplicity, efficiency (in terms of CPU performance and on
disk storage), resilience to corruption, etc., is much of the art of computer science.
As one example, consider the picture taken by a digital camera mentioned above. One
encoding technique would divide the picture into pixels (dots), and for each pixel,
record three bytes of information: the pixel's "redness", "greenness", and "blueness",
each on a scale of 0 to 255. The first three bytes of the file would record the information
for the first pixel, the second three bytes the second pixel, and so on. A picture format
known as "PNM" does just this (plus some header information, such as how many
pixels are in a row). Many other encoding techniques for images exist, some just as
simple, many much more complex.

Codificación de texto
11
Suplemments

Perhaps the most common type of data which computers are asked to store is text. As
computers have developed, a variety of techniques for encoding text have been
developed, from the simple in concept (which could encode only the Latin alphabet
used in Western languages) to complicated but powerful techniques that attempt to
encode all forms of human written communication, even attempting to include historical
languages such as Egyptian hieroglyphics. The following sections discuss many of the
encoding techniques commonly used in Red Hat Enterprise Linux.
ASCII
One of the oldest, and still most commonly used techniques for encoding text is called
ASCII encoding. ASCII encoding simply takes the 26 lowercase and 26 uppercase
letters which compose the Latin alphabet, 10 digits, and common English punctuation
characters (those found on a keyboard), and maps them to an integer between 0 and 255,
as outlined in the following table.
Table 1. ASCII Encoding of Printable Characters
Integer Range Caracter
33-47

Puntuación: !"#$%&;*(*+,-./

48-57

Los dígitos de 0 a 9

58-64

Puntuación: :;<=?>@

65-90

Letras mayúsculas de la A hasta la Z

91-96

Puntuación: []^_`

97-122

Letras minúsculas de la a hasta la z

123-126

Puntuación: {|}~

What about the integers 0 - 32? These integers are mapped to special keys on early
teletypes, many of which have to do with manipulating the spacing on the page being
typed on. The following characters are commonly called "whitespace" characters.
Table 2. Codificación ASCII de caracteres de espacio en blanco
Número entero Caracter Nombre común Representación común
'b'
8
Backspace
BS
9

HT

Tab

't'

10

LF

Nueva línea

'n'

12

FF

Form Feed

'f'

13

CR

Carriage Return 'r'

32

SPACE Space Bar
Delete
DEL

127
12
Suplemments

Others of the first 32 integers are mapped to keys which did not directly influence the
"printed page", but instead sent "out of band" control signals between two teletypes.
Many of these control signals have special interpretations within Linux (and Unix).
Table 3. ASCII Encoding of Control Signals
Número
entero

Caracter

Nombre común

4

EOT

End of Transmission

7

BEL

Campana
terminal

27

audible

Representación común

de 'a'

Escape
ESC
Generating Control Characters from the Keyboard
Control and whitespace characters can be generated from the terminal
keyboard directly using the CTRL key. For example, an audible bell can
be generated using CTRL-G, while a backspace can be sent using
CTRL-H, and we have already mentioned that CTRL-D is used to
generate an "End of File" (or "End of Transmission"). Can you
determine how the whitespace and control characters are mapped to the
various CTRL key combinations? For example, what CTRL key
combination generates a tab? What does CTRL-J generate? As you
explore various control sequences, remember that the reset command
will restore your terminal to sane behavior, if necessary.

What about the values 128-255? ASCII encoding does not use them. The ASCII
standard only defines the first 128 values of a byte, leaving the remaining 128 values to
be defined by other schemes.
Unicode (UCS)
In order to overcome the limitations of ASCII and ISO 8859 based encoding techniques,
a Universal Character Set has been developed, commonly referred to as UCS, or
Unicode. The Unicode standard acknowledges the fact that one byte of information,
with its ability to encode 256 different values, is simply not enough to encode the
variety of glyphs found in human communication. Instead, the Unicode standard uses 4
bytes to encode each character. Think of 4 bytes as 32 light switches. If we were to
again label each permutation of on and off for 32 switches with integers, the
mathematician would tell you that you would need 4,294,967,296 (over 4 billion)
integers. Thus, Unicode can encode over 4 billion glyphs (nearly enough for every
person on the earth to have their own unique glyph; the user prince would approve).
What are some of the features and drawbacks of Unicode encoding?
Scale
13
Suplemments

The Unicode standard will easily be able to encode the variety of glyphs used in
human communication for a long time to come.
Simplicidad
The Unicode standard does have the simplicity of a sledgehammer. The number
of bytes required to encode a set of characters is simply the number of characters
multiplied by 4.
Desperdicio
While the Unicode standard is simple in concept, it is also very wasteful. The
ability to encode 4 billion glyphs is nice, but in reality, much of the
communication that occurs today uses less than a few hundred glyphs. Of the 32
bits (light switches) used to encode each character, the first 20 or so would
always be "off".
ASCII Non-compatibility
For better or for worse, a huge amount of existing data is already ASCII
encoded. In order to convert fully to Unicode, that data, and the programs that
expect to read it, would have to be converted.
The Unicode standard is an effective standard in principle, but in many respects it is
ahead of its time, and perhaps forever will be. In practice, other techniques have been
developed which attempt to preserve the scale and versatility of Unicode, while
minimizing waste and maintaining ASCII compatibility. What must be sacrificed?
Simplicity.
Formato de transformación Unicode (UTF-8)
UTF-8 encoding attempts to balance the flexibility of Unicode, and the practicality and
pervasiveness of ASCII, with a significant sacrifice: variable length encoding. With
variable length encoding, each character is no longer encoded using simply 1 byte, or
simply 4 bytes. Instead, the traditional 127 ASCII characters are encoded using 1 byte
(and, in fact, are identical to the existing ASCII standard). The next most commonly
used 2000 or so characters are encoded using two bytes. The next 63000 or so
characters are encoded using three bytes, and the more esoteric characters may be
encoded using from four to six bytes. Details of the encoding technique can be found in
the utf-8(7) man page. With full backwards compatibility to ASCII, and the same
functional range of pure Unicode, what is there to lose? ISO 8859 (and similar)
character set compatibility.
UTF-8 attempts to bridge the gap between ASCII, which can be viewed as the primitive
days of text encoding, and Unicode, which can be viewed as the utopia to aspire toward.
Unfortunately, the "intermediate" methods, the ISO 8859 and other alternate character
sets, are as incompatible with UTF-8 as they are with each other.
14
Suplemments

Additionally, the simple relationship between the number of characters that are being
stored and the amount of space (measured in bytes) it takes to store them is lost. How
much space will it take to store 879 printed characters? If they are pure ASCII, the
answer is 879. If they are Greek or Cyrillic, the answer is closer to twice that much.
Text Encoding and the Open Source Community
In the traditional development of operating systems, decisions such as what type of
character encoding to use can be made centrally, with the possible disadvantage that the
decision is wrong for some community of the operating system's users. In contrast, in
the open source development model, these types of decisions are generally made by
individuals and small groups of contributers. The advantages of the open source model
are a flexible system which can accommodate a wide variety of encoding formats. The
disadvantage is that users must often be educated and made aware of the issues involved
with character encoding, because some parts of the assembled system use one technique
while others parts use another. The library of man pages is an excellent example.
When contributors to the open source community are faced with decisions involving
potentially incompatible formats, they generally balance local needs with an
appreciation for adhering to widely accepted standards where appropriate. The UTF-8
encoding format seems to be evolving as an accepted standard, and in recent releases
has become the default for Red Hat Enterprise Linux.
The following paragraph, extracted from the utf-8(7) man page, says it well:
It can be hoped that in the
foreseeable
future,
UTF-8
will
replace ASCII
and
ISO
8859 at all levels as the common character
encoding on POSIX systems, leading to a significantly richer
environment for handling plain text.

Internacionalización (i18n)
As this Workbook continues to discuss many tools and techniques for searching,
sorting, and manipulating text, the topic of internationalization cannot be avoided. In the
open source community, internationalization is often abbreviated as i18n, a shorthand
for saying "i-n with 18 letters in between". Applications which have been
internationalized take into account different languages. In the Linux (and Unix)
community, most applications look for the LANG environment variable to determine
which language to use.
At the simplest, this implies that programs will emit messages in the user's native
language.
[elvis@station elvis]$ echo $LANG
en_US.UTF-8
[elvis@station elvis]$ chmod 666 /etc/passwd
chmod: changing permissions of `/etc/passwd': Operation not permitted
15
Suplemments
[elvis@station elvis]$ export LANG=de_DE.utf8
[elvis@station elvis]$ chmod 666 /etc/passwd
chmod: Beim Setzen der Zugriffsrechte fr /etc/passwd: Die Operation
ist nicht erlaubt

More subtly, the choice of a particular language has implications for sorting orders,
numeric formats, text encoding, and other issues.
The LANG environment variable
The LANG environment variable is used to define a user's language, and possibly the
default encoding technique as well. The variable is expected to be set to a string using
the following syntax:
LL_CC.enc

The variable context consists of the following three components.
Table 1. Components of LANG environment variable
Componente

Función

LL

Código de lenguaje ISO 639 de dos letras

CC

(Optional) Two letter ISO 3166 Country Code

enc

(Optional) Character Encoding Code Set

The locale command can be used to examine your current configuration (as can echo
$LANG), while locale -a will list all settings currently supported by your system. The
extent of the support for any given language will vary.
The following tables list some selected language codes, country codes, and code set
specifications.
Table 2. Códigos de lenguaje seleccionados ISO 639
Código Lenguaje
de
Alemán
el

Griego

en

Inglés

es

Español

fr

Francés

ja

Japonés

zh

Chino

Table 3. Selected ISO 3166 Country Codes
16
Suplemments

Código
País
CA
Canadá
CN

China

DE

Alemania

ES

España

FR

Francia

GB

Britain (UK)

GR

Grecia

JP

Japón

NG

Nigeria

US

Estados Unidos

Table 4. Selected Character Encoding Code Sets
Código
utf8

País
UTF-8

iso88591 ISO 8859-1 (Latín 1)
iso885915 ISO 8859-15 (Latín 10)
iso88596 ISO 8859-6 (Árabe)
iso88592 ISO 8859-2 (Latín 2)
See the gettext info pages (info gettext, or pinfo gettext) for a complete listing.
¿Necesito saber todo esto?
We have tried to introduce the major concepts and components which affect how text is
encoded and stored within Linux. After reading about character sets and language
codes, one might be led to wonder, do I really need to know about all of this? If you are
using simple text, restricted to the Latin alphabet of 26 characters, the answer is no. If
you are asking the question 10 years from now, the answer will hopefully be no. If you
do not fit into one of these two categories, however, you should have at least an
acquaintance with the concept of internationalization, character sets, and the role of the
LANG environment variable.
Hopefully, as the open source community converges on a single encoding technique
(currently UTF-8 seems the most likely), most of these issues will disappear. Until then,
these are some key points to remember.
1. Un archivo ASCII ya es válido en uno de los conjuntos de caracteres ISO 8559.
2. Un archivo ASCII ya es válido en UTF-8.
17
Suplemments

3. A file encoded in one of the ISO 8559 character sets is not valid in UTF-8, and
must be converted.
4. Using UTF-8, There is a one to one mapping between characters and bytes if
and only if all of the characters are pure ASCII characters.
If you are interested in more information, several man pages provide a more detailed
introduction to the concepts outlined above. Start with charsets(7), and then follow
with ascii(7), iso_8859_1(7), unicode(7) and utf-8(7). Additionally, the iconv
command can be used to convert text files from one form of encoding to another.
Capítulo 3 El Administrador de paquetes RPM
Conceptos clave
•
•
•

El comando rpm se utiliza para agregar o quitar programas desde su sistema.
Usted debe tener privilegios de root para agregar y quitar programas con rpm.
Cualquiera puede solicitar paquetes instalados o archivos de paquetes.

RPM: El administrador de paquetes de Red Hat
El administrador de paquete de Red Hat probablemente es el elemento que mejor define
la distribución de Red Hat Enterprise Linux. El administrador de paquete ofrece a los
desarrolladores una forma de construir y distribuir programas, a los administradores una
forma de instalar y mantener programas y a todos los usuarios una forma de solicitar
información y verificar la integridad de programas instalados.
La necesidad de administración de paquetes
Antes de que la administración de paquetes se convirtiera en un concepto técnico, los
programas se distribuyeron principalmente como "tarballs" (por ejemplo, archivos
comprimidos tar) y sólo en forma de origen. Cualquiera que esté utilizando un producto
de código abierto necesitará desempacar el tarball, compilar los ejecutables (esperando
que sus sistema tenga las bibliotecas correctas para soportarlo), e instalar el producto en
su sistema, a menudo con componentes en directorios múltiples (tales como /etc,
/var/lib, /usr/bin/ y /usr/lib).
Por lo general, los guiones distribuídos con código abierto realizan cada uno de estos
pasos más fácilmente, pero incluso ellos no tratan dos problemas fundamentales. El
primero es el problema de dependencia. A menudo, los productos de fuente abierta
reutilizan código distribuido en forma de una biblioteca. Si la biblioteca apropiada no
está instalada aún en el sistema, la aplicación que depende de ésta no servirá. El
segundo problema fundamental es el mantenimiento. ¿Qué sucede cuando, después de
seis meses lanzan una nueva versión del producto o alguien decide no querer más un
producto en particular? Se necesitaría rastrear y quitar o remplazar los archivos
individuales del producto.
RPM está diseñado para ayudar a resolver esos dos problemas fundamentales.
18
Suplemments

Los componentes RPM
Cuando la gente habla de RPM se refiere a tres componentes colectivamente: la base de
datos RPM, el ejecutable rpm y los archivos de paquete.
La base de datos RPM
La base de datos RPM es el centro del producto, proporciona la respuesta a los dos
problemas antes mencionados. Cada vez que el programa es instalado por RPM, se
crean las entradas de base de datos que representan cada archivo instalado. Debido a la
base de datos, los archivos se pueden quitar fácilmente desde el sistema más tarde.
Además, la base de datos mantiene una lista de dependencias requerida y provista por
varios paquetes. Al instalar una aplicación que requiere una biblioteca, por ejemplo, la
biblioteca se puede listar como dependencia específica y la base de datos puede
responder de modo inequívoco por la presencia (o ausencia) de la biblioteca.
La base de datos reside en el directorio /var/lib/rpm, pero aparte de saber que existe,
los usuarios estándar (o incluso el administrador) poco necesitarán acceder al directorio
directamente.
El ejecutable rpm
Los usuarios interactúan con la base de datos RPM a través del comando rpm. El
ejecutable es utilizado por administradores para instalar, modernizar o quitar paquetes
de programas y por el usuario para contestar preguntas acerca de los paquetes instalados
o verificar su integridad. Examinaremos las solicitudes de RPM en detalle más adelante.
Archivos de paquete
Los archivos de paquete son el medio por el cual se distribuyen los programas. Los
archivos de paquete suelen nombrarse mediante la siguiente convención.
nombre-versión-publicación.archivo.rpm

Por ejemplo, la primera publicación del archivo de paquete para versión 4.0.7 de la
aplicación zsh de código abierto compilado para la arquitectura Intel x86 (y compatible)
se llamaría convencionalmente zsh-4.0.7-1.i386.rpm.
Los archivos de paquete son esencialmente archivos tar (aunque más de cerca parecen
archivos cpio menos familiares) combinados con la información de encabezado, la cual
nombra versiones y dependencias de estados para el paquete. Cuando la gente se refiere
a la distribución de Red Hat, generalmente se refiere a la colección de archivos de
paquete RPM que componen el programa instalado en una máquina.
Realizar peticiones a la base de datos RPM
19
Suplemments

Cuando se invoca con -q como su primera opción, el comando rpm realizará peticiones
a la base de datos RPM (o algunas veces archivos de paquete RPM directamente).
Formulación de peticiones RPM
Cuando se presenta por primera vez a rpm, la sintaxis asociada con peticiones puede ser
un poco abrumadora. Ayuda a pensar que cada petición consta de dos preguntas:
(1)¿Qué paquetes estoy solicitando? (2)¿Qué pregunta estoy haciendo? Cada una de las
opciones relacionadas con peticiones del comando rpm entra en una de estas dos
categorías.
Table 1. Opciones para realizar peticiones RPM con el fin de especificar paquetes
Opción

Especificaciones

-a

todos los paquetes instalados

paquetenombre

el paquete nombre

-f filename

el paquete propietario del archivo filename

-p paquetearchivonombre

solicitud del archivo de paquete paquete-archivo-nombre
directamente. Esta opción es fundamentalmente diferente, pues todas
las otras opciones realizan una petición a la base de datos RPM de
paquetes instalados.

Table 2. Opciones de peticiones RPM para especificar información
Opción

Especificaciones

(por defecto)

nombre del paquete y versión

-i

encabezado de información del paquete

-l

lista de archivos pertenecientes al paquete

--queryformat str lista información especificada en cadena de texto de formato str
Al escoger una opción desde el primer cuadro y cero o más opciones desde el segundo
cuadro, los usuarios pueden formular preguntas específicas para la base de datos RPM.
Ejemplos de peticiones
Peticiones generales
Por ejemplo, la opción -a realiza una solicitud en todos los paquetes instalados. Si no se
hace otra pregunta, por defecto rpm retornará el nombre del paquete. Así rpm -qa
retornará una lista de todos los paquetes instalados.
[prince@station prince]$ rpm -qa
basesystem-8.0-2
20
Suplemments

expat-1.95.5-2
libacl-2.2.3-1
popt-1.8-0.69
rootfiles-7.2-6
cpio-2.5-3
gzip-1.3.3-9
...

Si se especifica un nombre de paquete, el rpm solicitará sólo aquel paquete. ¿Qué
información retorna? De nuevo, por defecto, retornará el nombre del paquete.
[prince@station prince]$ rpm -q bash
bash-2.05b-20.1

Aunque quizás no es la más informativa de las solicitudes, prince al menos recibe la
confirmación de la instalación del paquete, y un número de versión. Por lo general,
cuando se solicita el nombre del paquete se pide más información. Por ejemplo, al
agregar -i se generará un encabezado de información.
[prince@station prince]$ rpm -qi bash
Name
: bash
Relocations: /usr
Version
: 2.05b
Vendor: Red Hat, Inc.
Release
: 20.1
Build Date: Wed 09 Apr
2003 09:02:36 AM EDT
Install Date: Tue 08 Jul 2003 09:29:33 AM EDT
Build Host:
stripples.devel.redhat.com
Group
: System Environment/Shells
Source RPM: bash-2.05b20.1.src.rpm
Size
: 1619204
License: GPL
Signature
: DSA/SHA1, Mon 09 Jun 2003 06:45:19 PM EDT, Key ID
219180cddb42a60e
Packager
: Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla>
Summary
: The GNU Bourne Again shell (bash).
Description :
The GNU project Bourne Again shell (bash) is a shell or command
language interpreter that is compatible with the Bourne shell
(sh). Bash incorporates useful features from the Korn shell (ksh) and
the C shell (csh) and most sh scripts can be run by bash without
modification. Bash is the default shell for Red Hat Linux.

O añadiendo un -l se generará una lista de todos los archivos instalados.
[prince@station prince]$ rpm -ql bash
/bin/bash
/bin/bash2
/bin/sh
/etc/skel/.bash_logout
/etc/skel/.bash_profile
/etc/skel/.bashrc
/usr/bin/bashbug
/usr/lib/bash
/usr/share/doc/bash-2.05b
/usr/share/doc/bash-2.05b/CHANGES
...
21
Suplemments

Si se incluyen ambos en rpm -qil bash se generarían los dos.
Investigación de un paquete desconocido
¿Qué sucede si usted ha encontrado un archivo en el sistema de archivos y quiere
conocer a qué paquete de archivo pertenece? rpm -qf ...
[prince@station etc]$ rpm -qf /etc/aep.conf
hwcrypto-1.0-14

¿Quiere saber más acerca del paquete? Agregue un -i.
[prince@station etc]$ rpm -qf /etc/aep.conf -i
Name
: hwcrypto
Relocations: (not
relocateable)
Version
: 1.0
Vendor: Red Hat, Inc.
Release
: 14
Build Date: Tue 04 Feb
2003 06:20:37 AM EST
Install Date: Tue 01 Apr 2003 11:27:43 AM EST
Build Host:
sylvester.devel.redhat.com
Group
: System Environment/Base
Source RPM: hwcrypto-1.014.src.rpm
Size
: 711506
License: GPL
Signature
: DSA/SHA1, Mon 24 Feb 2003 01:25:46 AM EST, Key ID
219180cddb42a60ePackager
: Red Hat, Inc.
<http://bugzilla.redhat.com/bugzilla>
Summary
: Hardware cryptographic accelerator support.
Description :
This package contains the shared libraries used to interface with
hardware cryptographic accelerators under Linux.

¿Existe documentación en el sistema que pueda dar mayor información acerca de esto?
Agregue -l para listar los archivos relacionados con /etc/aep.conf.
[prince@station etc]$ rpm -qf /etc/aep.conf -l
/etc/aep
/etc/aep.conf
/etc/aep/aeptarg.bin
/etc/aeplog.conf
...
/usr/sbin/aepversion
/usr/share/doc/hwcrypto-1.0
/usr/share/doc/hwcrypto-1.0/hwcrypto.txt
/usr/share/doc/hwcrypto-1.0/readme.snmp
/usr/share/snmp/mibs/cnStatTrap.mib

En este caso, no mucho, pero quizás /usr/share/doc/hwcyrpto.txt ayudará un poco.
Muchos paquetes incluyen páginas de man que se pueden leer o navegar. Al menos
usted puede ubicar algunos archivos de configuración que quiera hojear para averiguar
un poco más.
Investigación de un archivo de paquete desconocido
22
Suplemments

¿Qué sucede si usted se encuentra un archivo de paquete que aún no ha sido instalado en
su sistema? El comando rpm permite que los archivos de paquete sean solicitados con
la opción -p.
[prince@station RPMS]$ rpm -qil -p xsri-2.1.0-5.i386.rpm
Name
: xsri
Relocations: (not
relocateable)
Version
: 2.1.0
Vendor: Red Hat, Inc.
Release
: 5
Build Date: Sat 25 Jan
2003 03:37:15 AM EST
Install Date: (not installed)
Build Host:
porky.devel.redhat.com
Group
: Amusements/Graphics
Source RPM: xsri-2.1.05.src.rpm
Size
: 27190
License: GPL
Signature
: DSA/SHA1, Mon 24 Feb 2003 12:40:17 AM EST, Key ID
219180cddb42a60ePackager
: Red Hat, Inc.
<http://bugzilla.redhat.com/bugzilla>
Summary
: A program for displaying images on the background for X.
Description :
The xsri program allows the display of text, patterns, and images in
the root window, so users can customize the XDM style login screen
and/or the normal X background.
Install xsri if you would like to change the look of your X login
screen and/or X background. It is also used to display the default
background (Red Hat logo).
/usr/bin/xsri
/usr/share/doc/xsri-2.1.0
/usr/share/doc/xsri-2.1.0/README

Como se mencionó en el cuadro anterior, este es fundamentalmente un tipo diferente de
solicitud. El archivo de paquete, el cual podría o no ser instalado, está entregando la
información no la base de datos RPM.
Formatear información específica
¿Qué sucedería si usted quisiera generar una lista de los 10 paquetes más grandes
instalados en su sistema? Con el rpm -qai se vería el encabezado de información para
cada paquete, el cual se podría buscar con grep sólo para los tamaños, pero entonces
necesitaría nombres. Podría agregar nombres, pero luego el nombre y el tamaño estarían
en líneas separadas. Usted capta la idea.
Afortunadamente, el comando rpm permite a los usuarios componer preguntas
específicas al especificar una cadena de formato de solicitud. La cadena está compuesta
por un texto ASCII, pero los símbolos de la forma %{fieldname} serán remplazados
por el campo de información relevante. ¿Qué se puede utilizar como nombres
archivados? Para los principiantes, cualquier campo hallado en un encabezado de
información de paquete, pero hay más. El comando rpm --querytags retornará una lista
completa (e intimidatoria) de los campos disponibles.
23
Suplemments

Para la tarea específica a la mano, prince realiza la siguiente solicitud, (observe que
necesita especificar explícitamente una nueva línea con n).
[prince@station RPMS]$ rpm -qa --queryformat "%{size} %{name}n"
0 basesystem
156498 expat
19248 libacl
111647 popt
1966 rootfiles
67679 cpio
162449 gzip
...

Justo la información que prince necesitaba. Con una sintaxis de %anchura{nombre de
campo} se puede especificar una anchura de campo opcional. Utilizando esto para
limpiar su salida, y entubándose a sort y a head, prince genera con facilidad una lista de
los 10 paquetes más grandes en su sistema.
[prince@station RPMS]$ rpm -qa --queryformat "%10{size} %{name}n" |
sort -rn |
head
170890527 kernel-source
131431309 openoffice-i18n
100436356 openoffice-libs
84371104 gnucash
80018678 openoffice
75838208 rpmdb-redhat
55166532 Omni
54674111 tetex-doc
41939971 glibc-common
36762653 xorg

Ejercicios en línea
Lab Exercise
Objetivo: Familiarizarse con peticiones RPM
Tiempo estimado: 15 minutos.
Especificaciones
1. Cree el archivo ~/bash_files que contenga una lista de todos los archivos
pertenecientes al paquete bash listando un archivo por línea mediante referencias
absolutas.
2. Cree el archivo ~/sshd_man, que liste los tres archivos que contengan las
páginas de manual asociadas con el paquete openssh-server, un archivo por línea
mediante referencias absolutas.
3. En el archivo incluya la palabra que mejor complete la siguiente oración. La
biblioteca /lib/libcap.so.1.* se utiliza para obtener y establecer POSIX.1e
__________. (No se preocupe si no entiende del todo la respuesta).
24
Suplemments

4. Cree el archivo ~/license_counts que presenta el número de ocurrencias de
paquetes que tienen licencia bajo una licencia determinada para las 5 licencias
más utilizadas, clasificadas en orden numérico descendente. Si se realiza
correctamente, su archivo debería estar formateado como el siguiente. (No se
preocupe si las cuentas reales o nombres de licencia son diferentes. También,
usted podría notar lógicamente licencias similares, tales como LGPL/GPL y
GPL/LGPL. No intente combinarlas en una sola entrada).
5.
[prince@station prince]$ cat license_counts
6.
355 GPL
7.
147 LGPL
8.
53 BSD
9.
47 distributable
10.
18 xorg

Deliverables
Question 1

1. El archivo ~/bash_files, que contiene una lista de todos los archivos
pertenecientes al paquete bash, un archivo por línea, mediante referencias
absolutas.
2. El archivo ~/sshd_man que contiene una lista de los tres archivos que
proporcionan páginas de manual para el paquete openssh-server, uno por línea,
mediante referencias absolutas.
3. El archivo ~/whatis_libcap que contiene la respuesta de una palabra para lo
que la biblioteca obtiene y establece.
4. El archivo ~/license_counts que presenta varias licencias bajo las cuales se
distribuyen los paquetes, seguido por el número de paquetes a los cuales se
aplica la licencia, clasificados en orden numérico descendente.

Más contenido relacionado

La actualidad más candente

Comandos básicos para la terminal de ubuntu
Comandos básicos para la terminal de ubuntuComandos básicos para la terminal de ubuntu
Comandos básicos para la terminal de ubuntuMonchitocm Cuemtz
 
Guia basica de comandos ubuntu
Guia basica de comandos ubuntuGuia basica de comandos ubuntu
Guia basica de comandos ubuntussxdan
 
Introducción a shell script
Introducción a shell scriptIntroducción a shell script
Introducción a shell scriptPablo Macon
 
Comandosbasicoslinux ubuntu
Comandosbasicoslinux ubuntuComandosbasicoslinux ubuntu
Comandosbasicoslinux ubuntuCarlos Robayo
 
Tutorial 18pag
Tutorial 18pagTutorial 18pag
Tutorial 18pageckoby
 
Comandos basicos linux
Comandos basicos linuxComandos basicos linux
Comandos basicos linuxmaomaq
 
Tuberías (PIPES). EN GNU-LINUX-CENTOS ::: http://leymebamba.com
Tuberías (PIPES).  EN GNU-LINUX-CENTOS  ::: http://leymebamba.comTuberías (PIPES).  EN GNU-LINUX-CENTOS  ::: http://leymebamba.com
Tuberías (PIPES). EN GNU-LINUX-CENTOS ::: http://leymebamba.com{|::::::. ELDAVAN .:::::::|}
 
Introduction to linux for bioinformatics
Introduction to linux for bioinformaticsIntroduction to linux for bioinformatics
Introduction to linux for bioinformaticsAlberto Labarga
 
Taller de Shell Scripting
Taller de Shell ScriptingTaller de Shell Scripting
Taller de Shell ScriptingEnrique Verdes
 
Comandos básicos ubuntu
Comandos básicos ubuntuComandos básicos ubuntu
Comandos básicos ubunturobertoiglesias
 

La actualidad más candente (15)

Comandos básicos para la terminal de ubuntu
Comandos básicos para la terminal de ubuntuComandos básicos para la terminal de ubuntu
Comandos básicos para la terminal de ubuntu
 
Guia basica de comandos ubuntu
Guia basica de comandos ubuntuGuia basica de comandos ubuntu
Guia basica de comandos ubuntu
 
17 comandos basicoslinuxasoitson
17 comandos basicoslinuxasoitson17 comandos basicoslinuxasoitson
17 comandos basicoslinuxasoitson
 
Tutorial0
Tutorial0Tutorial0
Tutorial0
 
Linux comandos 1
Linux comandos 1Linux comandos 1
Linux comandos 1
 
Introducción a shell script
Introducción a shell scriptIntroducción a shell script
Introducción a shell script
 
Comandosbasicoslinux ubuntu
Comandosbasicoslinux ubuntuComandosbasicoslinux ubuntu
Comandosbasicoslinux ubuntu
 
Tutorial 18pag
Tutorial 18pagTutorial 18pag
Tutorial 18pag
 
6 la shell bash
6 la shell bash6 la shell bash
6 la shell bash
 
Shell comandosbasicos
Shell comandosbasicosShell comandosbasicos
Shell comandosbasicos
 
Comandos basicos linux
Comandos basicos linuxComandos basicos linux
Comandos basicos linux
 
Tuberías (PIPES). EN GNU-LINUX-CENTOS ::: http://leymebamba.com
Tuberías (PIPES).  EN GNU-LINUX-CENTOS  ::: http://leymebamba.comTuberías (PIPES).  EN GNU-LINUX-CENTOS  ::: http://leymebamba.com
Tuberías (PIPES). EN GNU-LINUX-CENTOS ::: http://leymebamba.com
 
Introduction to linux for bioinformatics
Introduction to linux for bioinformaticsIntroduction to linux for bioinformatics
Introduction to linux for bioinformatics
 
Taller de Shell Scripting
Taller de Shell ScriptingTaller de Shell Scripting
Taller de Shell Scripting
 
Comandos básicos ubuntu
Comandos básicos ubuntuComandos básicos ubuntu
Comandos básicos ubuntu
 

Destacado

10 network applications
10 network applications10 network applications
10 network applicationscyberleon95
 
7 standard io and pipes
7 standard io and pipes7 standard io and pipes
7 standard io and pipescyberleon95
 
3 users and groups
3   users and groups3   users and groups
3 users and groupscyberleon95
 
5 the linux filesystem
5 the linux filesystem5 the linux filesystem
5 the linux filesystemcyberleon95
 
2 filesystem basics
2 filesystem basics2 filesystem basics
2 filesystem basicscyberleon95
 
4 file ownerships and permissions
4 file ownerships and permissions4 file ownerships and permissions
4 file ownerships and permissionscyberleon95
 
Configuracion servidores linux-20131029-octubre
Configuracion servidores linux-20131029-octubreConfiguracion servidores linux-20131029-octubre
Configuracion servidores linux-20131029-octubrecyberleon95
 
Manual de referencia
Manual de referenciaManual de referencia
Manual de referenciacyberleon95
 
Repositorio grafico
Repositorio graficoRepositorio grafico
Repositorio graficocyberleon95
 
Gestión del Talento Humano
Gestión del Talento HumanoGestión del Talento Humano
Gestión del Talento Humanocyberleon95
 
Contratación de Tecnología para Call Center
Contratación de Tecnología para Call CenterContratación de Tecnología para Call Center
Contratación de Tecnología para Call Centercyberleon95
 
Configuración Script Usuarios Masivos Windows Server 2012 R2
Configuración Script Usuarios Masivos Windows Server 2012 R2Configuración Script Usuarios Masivos Windows Server 2012 R2
Configuración Script Usuarios Masivos Windows Server 2012 R2cyberleon95
 
Instalación Windows Server 2012
Instalación Windows Server 2012Instalación Windows Server 2012
Instalación Windows Server 2012cyberleon95
 
Instalación y Configuración de Exchange 2013 en Windows Server 2012 R2
Instalación y Configuración de Exchange 2013 en Windows Server 2012 R2Instalación y Configuración de Exchange 2013 en Windows Server 2012 R2
Instalación y Configuración de Exchange 2013 en Windows Server 2012 R2cyberleon95
 
Manual configuración GPO
Manual configuración GPOManual configuración GPO
Manual configuración GPOcyberleon95
 

Destacado (20)

10 network applications
10 network applications10 network applications
10 network applications
 
1 quick tours
1 quick tours1 quick tours
1 quick tours
 
7 standard io and pipes
7 standard io and pipes7 standard io and pipes
7 standard io and pipes
 
3 users and groups
3   users and groups3   users and groups
3 users and groups
 
5 the linux filesystem
5 the linux filesystem5 the linux filesystem
5 the linux filesystem
 
2 filesystem basics
2 filesystem basics2 filesystem basics
2 filesystem basics
 
4 file ownerships and permissions
4 file ownerships and permissions4 file ownerships and permissions
4 file ownerships and permissions
 
Se linux
Se linuxSe linux
Se linux
 
Configuracion servidores linux-20131029-octubre
Configuracion servidores linux-20131029-octubreConfiguracion servidores linux-20131029-octubre
Configuracion servidores linux-20131029-octubre
 
Manual linux
Manual linuxManual linux
Manual linux
 
Manual de referencia
Manual de referenciaManual de referencia
Manual de referencia
 
Repositorio grafico
Repositorio graficoRepositorio grafico
Repositorio grafico
 
Softlibre
SoftlibreSoftlibre
Softlibre
 
Actividad ITIL
Actividad ITIL Actividad ITIL
Actividad ITIL
 
Gestión del Talento Humano
Gestión del Talento HumanoGestión del Talento Humano
Gestión del Talento Humano
 
Contratación de Tecnología para Call Center
Contratación de Tecnología para Call CenterContratación de Tecnología para Call Center
Contratación de Tecnología para Call Center
 
Configuración Script Usuarios Masivos Windows Server 2012 R2
Configuración Script Usuarios Masivos Windows Server 2012 R2Configuración Script Usuarios Masivos Windows Server 2012 R2
Configuración Script Usuarios Masivos Windows Server 2012 R2
 
Instalación Windows Server 2012
Instalación Windows Server 2012Instalación Windows Server 2012
Instalación Windows Server 2012
 
Instalación y Configuración de Exchange 2013 en Windows Server 2012 R2
Instalación y Configuración de Exchange 2013 en Windows Server 2012 R2Instalación y Configuración de Exchange 2013 en Windows Server 2012 R2
Instalación y Configuración de Exchange 2013 en Windows Server 2012 R2
 
Manual configuración GPO
Manual configuración GPOManual configuración GPO
Manual configuración GPO
 

Similar a 11 suplemments

Similar a 11 suplemments (20)

Estructuras de control 1
Estructuras de control 1Estructuras de control 1
Estructuras de control 1
 
Estructuras de control 1
Estructuras de control 1Estructuras de control 1
Estructuras de control 1
 
Estructuras de control 1.0
Estructuras de control 1.0Estructuras de control 1.0
Estructuras de control 1.0
 
Shell script
Shell scriptShell script
Shell script
 
Script
ScriptScript
Script
 
Curso Bash 2
Curso Bash 2Curso Bash 2
Curso Bash 2
 
El shell-bash
El shell-bashEl shell-bash
El shell-bash
 
Script presentacion
Script presentacionScript presentacion
Script presentacion
 
Semana 4 y 5 la shell bash guia de ejercicios resuelta
Semana 4 y 5  la shell bash guia de ejercicios resueltaSemana 4 y 5  la shell bash guia de ejercicios resuelta
Semana 4 y 5 la shell bash guia de ejercicios resuelta
 
Script Y Comandos De Linux
Script Y Comandos De LinuxScript Y Comandos De Linux
Script Y Comandos De Linux
 
Linux Programacion en Shell
Linux Programacion en ShellLinux Programacion en Shell
Linux Programacion en Shell
 
Semana 4 y_5_-_la_shell_bash
Semana 4 y_5_-_la_shell_bashSemana 4 y_5_-_la_shell_bash
Semana 4 y_5_-_la_shell_bash
 
Giseproi hacking ético - bash scripting
Giseproi   hacking ético - bash scriptingGiseproi   hacking ético - bash scripting
Giseproi hacking ético - bash scripting
 
6 la shell bash
6 la shell bash6 la shell bash
6 la shell bash
 
6 la shell bash
6 la shell bash6 la shell bash
6 la shell bash
 
Creacion de scripts en linux
Creacion de scripts en linuxCreacion de scripts en linux
Creacion de scripts en linux
 
Los scripts de linux
Los scripts de linuxLos scripts de linux
Los scripts de linux
 
Curso Bash 3
Curso Bash 3Curso Bash 3
Curso Bash 3
 
Shell script en linux
Shell script en linuxShell script en linux
Shell script en linux
 
11 PHP. PHP y HTML
11 PHP. PHP y HTML11 PHP. PHP y HTML
11 PHP. PHP y HTML
 

Más de cyberleon95

Configuración VPN Sitio a Sitio en ENDIAN
Configuración VPN Sitio a Sitio en ENDIANConfiguración VPN Sitio a Sitio en ENDIAN
Configuración VPN Sitio a Sitio en ENDIANcyberleon95
 
Configuración VPN de Acceso remoto con TMG
Configuración VPN de Acceso remoto con TMGConfiguración VPN de Acceso remoto con TMG
Configuración VPN de Acceso remoto con TMGcyberleon95
 
Instalación y Configuración Firewall ENDIAN
Instalación y Configuración Firewall ENDIANInstalación y Configuración Firewall ENDIAN
Instalación y Configuración Firewall ENDIANcyberleon95
 
Manual Instalación y Configuración Firewall TMG
Manual Instalación y Configuración Firewall TMGManual Instalación y Configuración Firewall TMG
Manual Instalación y Configuración Firewall TMGcyberleon95
 
Documentación ACL - Firewall ASA
Documentación ACL - Firewall ASADocumentación ACL - Firewall ASA
Documentación ACL - Firewall ASAcyberleon95
 
Plan de continuidad
Plan de continuidadPlan de continuidad
Plan de continuidadcyberleon95
 
Análisis de riesgos y vulnerabilidades
Análisis de riesgos y vulnerabilidades Análisis de riesgos y vulnerabilidades
Análisis de riesgos y vulnerabilidades cyberleon95
 
Manual PXE - RHEL 6.2
Manual PXE - RHEL 6.2Manual PXE - RHEL 6.2
Manual PXE - RHEL 6.2cyberleon95
 
Manual WDS - Windows Server 2008 R2
Manual WDS - Windows Server 2008 R2Manual WDS - Windows Server 2008 R2
Manual WDS - Windows Server 2008 R2cyberleon95
 
Manual WSUS - Windows Server 2008 R2
Manual WSUS - Windows Server 2008 R2Manual WSUS - Windows Server 2008 R2
Manual WSUS - Windows Server 2008 R2cyberleon95
 
Manual Monitoreo de Servidores
Manual  Monitoreo de ServidoresManual  Monitoreo de Servidores
Manual Monitoreo de Servidorescyberleon95
 
Teoría Plataformas de Monitoreo
Teoría  Plataformas de Monitoreo  Teoría  Plataformas de Monitoreo
Teoría Plataformas de Monitoreo cyberleon95
 
Autodiagnostico 5 Trimestre
Autodiagnostico 5 TrimestreAutodiagnostico 5 Trimestre
Autodiagnostico 5 Trimestrecyberleon95
 
Integración LDAP + SAMBA
Integración LDAP + SAMBAIntegración LDAP + SAMBA
Integración LDAP + SAMBAcyberleon95
 
Actividad Topologías VoIP
Actividad Topologías VoIPActividad Topologías VoIP
Actividad Topologías VoIPcyberleon95
 
Integración GNS3 - VirtualBox - Wireshark
Integración GNS3 - VirtualBox - WiresharkIntegración GNS3 - VirtualBox - Wireshark
Integración GNS3 - VirtualBox - Wiresharkcyberleon95
 
Instalación y Configuración SSH CentOS 6.5 / RHEL 6.2
Instalación y Configuración SSH CentOS 6.5 / RHEL 6.2Instalación y Configuración SSH CentOS 6.5 / RHEL 6.2
Instalación y Configuración SSH CentOS 6.5 / RHEL 6.2cyberleon95
 
Centos 6.5 Servidor Básico
Centos 6.5 Servidor BásicoCentos 6.5 Servidor Básico
Centos 6.5 Servidor Básicocyberleon95
 
Configuración DHCP - NAT
Configuración DHCP - NATConfiguración DHCP - NAT
Configuración DHCP - NATcyberleon95
 

Más de cyberleon95 (20)

Configuración VPN Sitio a Sitio en ENDIAN
Configuración VPN Sitio a Sitio en ENDIANConfiguración VPN Sitio a Sitio en ENDIAN
Configuración VPN Sitio a Sitio en ENDIAN
 
Configuración VPN de Acceso remoto con TMG
Configuración VPN de Acceso remoto con TMGConfiguración VPN de Acceso remoto con TMG
Configuración VPN de Acceso remoto con TMG
 
Instalación y Configuración Firewall ENDIAN
Instalación y Configuración Firewall ENDIANInstalación y Configuración Firewall ENDIAN
Instalación y Configuración Firewall ENDIAN
 
Manual Instalación y Configuración Firewall TMG
Manual Instalación y Configuración Firewall TMGManual Instalación y Configuración Firewall TMG
Manual Instalación y Configuración Firewall TMG
 
Documentación ACL - Firewall ASA
Documentación ACL - Firewall ASADocumentación ACL - Firewall ASA
Documentación ACL - Firewall ASA
 
Plan de continuidad
Plan de continuidadPlan de continuidad
Plan de continuidad
 
Análisis de riesgos y vulnerabilidades
Análisis de riesgos y vulnerabilidades Análisis de riesgos y vulnerabilidades
Análisis de riesgos y vulnerabilidades
 
Manual PXE - RHEL 6.2
Manual PXE - RHEL 6.2Manual PXE - RHEL 6.2
Manual PXE - RHEL 6.2
 
Manual WDS - Windows Server 2008 R2
Manual WDS - Windows Server 2008 R2Manual WDS - Windows Server 2008 R2
Manual WDS - Windows Server 2008 R2
 
Manual WSUS - Windows Server 2008 R2
Manual WSUS - Windows Server 2008 R2Manual WSUS - Windows Server 2008 R2
Manual WSUS - Windows Server 2008 R2
 
Manual Monitoreo de Servidores
Manual  Monitoreo de ServidoresManual  Monitoreo de Servidores
Manual Monitoreo de Servidores
 
Teoría Plataformas de Monitoreo
Teoría  Plataformas de Monitoreo  Teoría  Plataformas de Monitoreo
Teoría Plataformas de Monitoreo
 
Autodiagnostico 5 Trimestre
Autodiagnostico 5 TrimestreAutodiagnostico 5 Trimestre
Autodiagnostico 5 Trimestre
 
Integración LDAP + SAMBA
Integración LDAP + SAMBAIntegración LDAP + SAMBA
Integración LDAP + SAMBA
 
Actividad Topologías VoIP
Actividad Topologías VoIPActividad Topologías VoIP
Actividad Topologías VoIP
 
Conceptos VoIP
Conceptos VoIPConceptos VoIP
Conceptos VoIP
 
Integración GNS3 - VirtualBox - Wireshark
Integración GNS3 - VirtualBox - WiresharkIntegración GNS3 - VirtualBox - Wireshark
Integración GNS3 - VirtualBox - Wireshark
 
Instalación y Configuración SSH CentOS 6.5 / RHEL 6.2
Instalación y Configuración SSH CentOS 6.5 / RHEL 6.2Instalación y Configuración SSH CentOS 6.5 / RHEL 6.2
Instalación y Configuración SSH CentOS 6.5 / RHEL 6.2
 
Centos 6.5 Servidor Básico
Centos 6.5 Servidor BásicoCentos 6.5 Servidor Básico
Centos 6.5 Servidor Básico
 
Configuración DHCP - NAT
Configuración DHCP - NATConfiguración DHCP - NAT
Configuración DHCP - NAT
 

Último

Identificación de componentes Hardware del PC
Identificación de componentes Hardware del PCIdentificación de componentes Hardware del PC
Identificación de componentes Hardware del PCCesarFernandez937857
 
Estas son las escuelas y colegios que tendrán modalidad no presencial este lu...
Estas son las escuelas y colegios que tendrán modalidad no presencial este lu...Estas son las escuelas y colegios que tendrán modalidad no presencial este lu...
Estas son las escuelas y colegios que tendrán modalidad no presencial este lu...fcastellanos3
 
Metabolismo 3: Anabolismo y Fotosíntesis 2024
Metabolismo 3: Anabolismo y Fotosíntesis 2024Metabolismo 3: Anabolismo y Fotosíntesis 2024
Metabolismo 3: Anabolismo y Fotosíntesis 2024IES Vicent Andres Estelles
 
Flores Nacionales de América Latina - Botánica
Flores Nacionales de América Latina - BotánicaFlores Nacionales de América Latina - Botánica
Flores Nacionales de América Latina - BotánicaJuan Carlos Fonseca Mata
 
Estrategia de Enseñanza y Aprendizaje.pdf
Estrategia de Enseñanza y Aprendizaje.pdfEstrategia de Enseñanza y Aprendizaje.pdf
Estrategia de Enseñanza y Aprendizaje.pdfromanmillans
 
Marketing y servicios 2ºBTP Cocina DGETP
Marketing y servicios 2ºBTP Cocina DGETPMarketing y servicios 2ºBTP Cocina DGETP
Marketing y servicios 2ºBTP Cocina DGETPANEP - DETP
 
Introducción:Los objetivos de Desarrollo Sostenible
Introducción:Los objetivos de Desarrollo SostenibleIntroducción:Los objetivos de Desarrollo Sostenible
Introducción:Los objetivos de Desarrollo SostenibleJonathanCovena1
 
Plan Año Escolar Año Escolar 2023-2024. MPPE
Plan Año Escolar Año Escolar 2023-2024. MPPEPlan Año Escolar Año Escolar 2023-2024. MPPE
Plan Año Escolar Año Escolar 2023-2024. MPPELaura Chacón
 
codigos HTML para blogs y paginas web Karina
codigos HTML para blogs y paginas web Karinacodigos HTML para blogs y paginas web Karina
codigos HTML para blogs y paginas web Karinavergarakarina022
 
SINTAXIS DE LA ORACIÓN SIMPLE 2023-2024.pptx
SINTAXIS DE LA ORACIÓN SIMPLE 2023-2024.pptxSINTAXIS DE LA ORACIÓN SIMPLE 2023-2024.pptx
SINTAXIS DE LA ORACIÓN SIMPLE 2023-2024.pptxlclcarmen
 
Fundamentos y Principios de Psicopedagogía..pdf
Fundamentos y Principios de Psicopedagogía..pdfFundamentos y Principios de Psicopedagogía..pdf
Fundamentos y Principios de Psicopedagogía..pdfsamyarrocha1
 
programa dia de las madres 10 de mayo para evento
programa dia de las madres 10 de mayo  para eventoprograma dia de las madres 10 de mayo  para evento
programa dia de las madres 10 de mayo para eventoDiegoMtsS
 
OLIMPIADA DEL CONOCIMIENTO INFANTIL 2024.pptx
OLIMPIADA DEL CONOCIMIENTO INFANTIL 2024.pptxOLIMPIADA DEL CONOCIMIENTO INFANTIL 2024.pptx
OLIMPIADA DEL CONOCIMIENTO INFANTIL 2024.pptxjosetrinidadchavez
 
5° SEM29 CRONOGRAMA PLANEACIÓN DOCENTE DARUKEL 23-24.pdf
5° SEM29 CRONOGRAMA PLANEACIÓN DOCENTE DARUKEL 23-24.pdf5° SEM29 CRONOGRAMA PLANEACIÓN DOCENTE DARUKEL 23-24.pdf
5° SEM29 CRONOGRAMA PLANEACIÓN DOCENTE DARUKEL 23-24.pdfOswaldoGonzalezCruz
 
CULTURA NAZCA, presentación en aula para compartir
CULTURA NAZCA, presentación en aula para compartirCULTURA NAZCA, presentación en aula para compartir
CULTURA NAZCA, presentación en aula para compartirPaddySydney1
 
RAIZ CUADRADA Y CUBICA PARA NIÑOS DE PRIMARIA
RAIZ CUADRADA Y CUBICA PARA NIÑOS DE PRIMARIARAIZ CUADRADA Y CUBICA PARA NIÑOS DE PRIMARIA
RAIZ CUADRADA Y CUBICA PARA NIÑOS DE PRIMARIACarlos Campaña Montenegro
 

Último (20)

Repaso Pruebas CRECE PR 2024. Ciencia General
Repaso Pruebas CRECE PR 2024. Ciencia GeneralRepaso Pruebas CRECE PR 2024. Ciencia General
Repaso Pruebas CRECE PR 2024. Ciencia General
 
Identificación de componentes Hardware del PC
Identificación de componentes Hardware del PCIdentificación de componentes Hardware del PC
Identificación de componentes Hardware del PC
 
Estas son las escuelas y colegios que tendrán modalidad no presencial este lu...
Estas son las escuelas y colegios que tendrán modalidad no presencial este lu...Estas son las escuelas y colegios que tendrán modalidad no presencial este lu...
Estas son las escuelas y colegios que tendrán modalidad no presencial este lu...
 
Metabolismo 3: Anabolismo y Fotosíntesis 2024
Metabolismo 3: Anabolismo y Fotosíntesis 2024Metabolismo 3: Anabolismo y Fotosíntesis 2024
Metabolismo 3: Anabolismo y Fotosíntesis 2024
 
Flores Nacionales de América Latina - Botánica
Flores Nacionales de América Latina - BotánicaFlores Nacionales de América Latina - Botánica
Flores Nacionales de América Latina - Botánica
 
Estrategia de Enseñanza y Aprendizaje.pdf
Estrategia de Enseñanza y Aprendizaje.pdfEstrategia de Enseñanza y Aprendizaje.pdf
Estrategia de Enseñanza y Aprendizaje.pdf
 
Marketing y servicios 2ºBTP Cocina DGETP
Marketing y servicios 2ºBTP Cocina DGETPMarketing y servicios 2ºBTP Cocina DGETP
Marketing y servicios 2ºBTP Cocina DGETP
 
Introducción:Los objetivos de Desarrollo Sostenible
Introducción:Los objetivos de Desarrollo SostenibleIntroducción:Los objetivos de Desarrollo Sostenible
Introducción:Los objetivos de Desarrollo Sostenible
 
Plan Año Escolar Año Escolar 2023-2024. MPPE
Plan Año Escolar Año Escolar 2023-2024. MPPEPlan Año Escolar Año Escolar 2023-2024. MPPE
Plan Año Escolar Año Escolar 2023-2024. MPPE
 
Sesión de clase: Defendamos la verdad.pdf
Sesión de clase: Defendamos la verdad.pdfSesión de clase: Defendamos la verdad.pdf
Sesión de clase: Defendamos la verdad.pdf
 
codigos HTML para blogs y paginas web Karina
codigos HTML para blogs y paginas web Karinacodigos HTML para blogs y paginas web Karina
codigos HTML para blogs y paginas web Karina
 
SINTAXIS DE LA ORACIÓN SIMPLE 2023-2024.pptx
SINTAXIS DE LA ORACIÓN SIMPLE 2023-2024.pptxSINTAXIS DE LA ORACIÓN SIMPLE 2023-2024.pptx
SINTAXIS DE LA ORACIÓN SIMPLE 2023-2024.pptx
 
La Trampa De La Felicidad. Russ-Harris.pdf
La Trampa De La Felicidad. Russ-Harris.pdfLa Trampa De La Felicidad. Russ-Harris.pdf
La Trampa De La Felicidad. Russ-Harris.pdf
 
Fundamentos y Principios de Psicopedagogía..pdf
Fundamentos y Principios de Psicopedagogía..pdfFundamentos y Principios de Psicopedagogía..pdf
Fundamentos y Principios de Psicopedagogía..pdf
 
programa dia de las madres 10 de mayo para evento
programa dia de las madres 10 de mayo  para eventoprograma dia de las madres 10 de mayo  para evento
programa dia de las madres 10 de mayo para evento
 
Power Point: "Defendamos la verdad".pptx
Power Point: "Defendamos la verdad".pptxPower Point: "Defendamos la verdad".pptx
Power Point: "Defendamos la verdad".pptx
 
OLIMPIADA DEL CONOCIMIENTO INFANTIL 2024.pptx
OLIMPIADA DEL CONOCIMIENTO INFANTIL 2024.pptxOLIMPIADA DEL CONOCIMIENTO INFANTIL 2024.pptx
OLIMPIADA DEL CONOCIMIENTO INFANTIL 2024.pptx
 
5° SEM29 CRONOGRAMA PLANEACIÓN DOCENTE DARUKEL 23-24.pdf
5° SEM29 CRONOGRAMA PLANEACIÓN DOCENTE DARUKEL 23-24.pdf5° SEM29 CRONOGRAMA PLANEACIÓN DOCENTE DARUKEL 23-24.pdf
5° SEM29 CRONOGRAMA PLANEACIÓN DOCENTE DARUKEL 23-24.pdf
 
CULTURA NAZCA, presentación en aula para compartir
CULTURA NAZCA, presentación en aula para compartirCULTURA NAZCA, presentación en aula para compartir
CULTURA NAZCA, presentación en aula para compartir
 
RAIZ CUADRADA Y CUBICA PARA NIÑOS DE PRIMARIA
RAIZ CUADRADA Y CUBICA PARA NIÑOS DE PRIMARIARAIZ CUADRADA Y CUBICA PARA NIÑOS DE PRIMARIA
RAIZ CUADRADA Y CUBICA PARA NIÑOS DE PRIMARIA
 

11 suplemments

  • 1. 1 Suplemments Capítulo 1 Escritura avanzada de shell Conceptos clave • • • • • • Linux utiliza el mecanismo de scripts, en donde los archivos de scripts de texto pueden ser ejecutados por un intérprete especificado en la línea inicial. Dentro de un script bash, los argumentos provistos al invocar un script están disponibles como parámetros posicionales (por ejemplo, las variables $1, $2, ...). El comando incorporado read se puede utilizar para leer la entrada desde la "entrada estándar" del teclado. La shell utiliza una sintaxis if ... then ... [else ...] fi para implementar ramas condicionales. El comando test suele utilizarse como comando condicional en ramas if ... then. La shell bash utiliza una sintaxis for ... in ... do ... done para implementar bucles. Escritura de shell En capítulos anteriores a este cuaderno discutimos la creación de scripts simples de shell. Estos scripts hacían algo más que ejecutar una serie de comandos, opcionalmente aceptando la salida del usuario para definir variables. Sin embargo, los scripts de shell son capaces de mucho más. Este capítulo agregará algunas herramientas valiosas, permitiéndole a sus scripts tomar decisiones si/entonces/otro, en inglés if/then/else, y retroalimentar una serie de acciones de modo indefinido. Ramas: if ... then ... [else ...] fi Sintaxis Bash para ramas Al programar, las ramas le permiten a los programas escoger entre una o dos (o más) rutas alternas de ejecución. La shell bash, al igual que la mayoría de los lenguajes de programación, utiliza la palabra si, en inglés if, para significar una rama. Más formalmente, bash utiliza la siguiente sintaxis. if condición then comando(s) ... fi o if condición then
  • 2. 2 Suplemments comando(s) ... else comando(s) ... fi Los comandos en estas estrofas se ejecutan si la condición tiene "éxito". Los comandos en la estrofa se ejecutan si la condición "fracasa". Al utilizar esta sintaxis, los retornos de carro son importantes (por ejemplo, el if y then deben presentarse en líneas separadas), pero las sangrías no lo son. ¿Qué espera bash como condición? A diferencia de la mayoría de los lenguajes de programación, bash no tiene sintaxis interna para hacer comparaciones (¿tales como $ A == apple, o $B >25). En su lugar, bash se concentra en la razón de su diseño inicial: la ejecución de comandos. Cualquier comando se puede utilizar para la condición. La shell bash ejecutará el comando y examinará su valor de retorno. Si el comando tiene "éxito"(devuelve un valor de retorno de 0), la primera estrofa de comandos se ejecutará. Si el comando fracasa (devuelve un valor de retorno no igual a cero), la segunda estrofa de comandos se ejecutará (si existe). La siguiente modificación para el script de elvis shut sirve de ejemplo. [elvis@station elvis]$ ls example.sh shut [elvis@station elvis]$ cat shut #!/bin/bash # the first argument should be the name of the file to shut. if ls $1 then chmod 600 $1 else echo "The file $1 does not exist." fi [elvis@station elvis]$ ./shut example.sh example.sh [elvis@station elvis]$ ./shut foo ls: foo: No such file or directory The file foo does not exist. En el primer caso, el comando ls tiene "éxito" (porque el archivo example.sh existe, el valor de retorno del comando ls es 0). Como resultado, la primera estrofa de la cláusula if ... then ... else ... fi se ejecuta. En el segundo caso, el archivo foo no existe, por lo tanto la segunda estrofa (otro) de la cláusula se ejecutó. El comando test El ejemplo anterior es bastante raro. El comando ls se ha forzado a realizar una labor para la cual no está diseñado: probar si existe un archivo. Aunque puede hacer esto, los mensajes que imprime distraen la atención. Si el archivo especificado existe, su nombre
  • 3. 3 Suplemments se imprime en la pantalla. Si el archivo no existe, entonces un mensaje de error se imprimirá en pantalla. Si solo hubiera un comando que comprobara la existencia del archivo y retornara el código de retorno apropiado, sin emitir otros mensajes... Lo hay. El comando se llama test. El comando test fue diseñado específicamente para este propósito: para ser un comando condicional en frases bashif ... then. Más específicamente, el comando test está diseñado para comparar cadenas de texto, números enteros y atributos de archivo. Nunca genera salida, en cambio, se comunica mediante su valor de retorno. El comando test retorna 0 si la expresión que evalúa es verdadera y un valor de no cero si no lo es. La mayoría de argumentos de test se parecen a las opciones de la línea de comandos. Por ejemplo, -e examina si existe un archivo. El guión anterior podría mejorarse remplazando ls con test -e. [elvis@station elvis]$ cat shut #!/bin/bash # the first argument should be the name of the file to shut. if test -e $1 then chmod 600 $1 else echo "The file $1 does not exist." fi [elvis@station elvis]$ ./shut example.sh [elvis@station elvis]$ ./shut foo The file foo does not exist. Observe que el comando test examina la existencia de un archivo, pero no genera mensajes para distraer la atención del usuario. El siguiente cuadro lista algunas de las opciones más comunes para examinar los atributos de los archivos. Table 1. Expresiones de test para examinar atributos de archivos Expresión Condición -d ARCHIVO El ARCHIVO existe y es un directorio. -e ARCHIVO El ARCHIVO existe -f ARCHIVO El ARCHIVO existe y es un archivo regular. -r ARCHIVO El ARCHIVO existe y es leíble. -w ARCHIVO El ARCHIVO existe y es escribible. -x ARCHIVO El ARCHIVO existe y es ejecutable. FILE1 -nt ARCHIVO2 El FILE1 en más reciente que ARCHIVO2.
  • 4. 4 Suplemments Table 2. Expresiones de test para comparar cadenas de texto Expresión Condición [-n] CADENA DE TEXTO la longitud de CADENA DE TEXTO es mayor que cero. -z CADENA DE TEXTO la longitud de CADENA DE TEXTO es cero. CADENA1 = CADENA2 CADENA1 y CADENA2 son iguales. CADENA1 != CADENA2 CADENA1 y CADENA2 no son iguales. Por último, el siguiente cuadro lista las expresiones que permiten al comando test utilizar una lógica compuesta. Table 3. Expresiones lógicas para el comando test Expresión Condición EXPRESIÓN1 -a EXPRESIÓN2 Tanto EXPRESIÓN1 como EXPRESIÓN2 son verdaderas. EXPRESIÓN1 -o EXPRESIÓN2 EXPRESIÓN1 o EXPRESIÓN2 es cierta. ! EXPRESIÓN EXPRESIÓN es falsa. Estos cuadros ofrecen al estudiante una serie de expresiones útiles. Para obtener una lista completa, consulte la página de manual test(1). Expresión alterna para test: [ expresión ] Como el comando test es tan utilizado en scripts bash se ha desarrollado una sintaxis más corta. Las siguientes dos expresiones son equivalentes. test expresión [ expresión ] A manera de ejemplo, el script de elvis shut se puede reescribir así: [elvis@station elvis]$ cat shut #!/bin/bash # the first argument should be the name of the file to shut. if [ -e $1 ] then chmod 600 $1 else echo "The file $1 does not exist." fi Observe que el comando test se ha remplazado con la sintaxis alterna [ ... ].
  • 5. 5 Suplemments Al utilizar la sintaxis alterna, se debe tener cuidado de incluir un espacio después de abrir el paréntesis y antes de cerrarlo.[1] Por ejemplo, las siguientes dos construcciones del comando test están erradas. [-e foo.sh ] [ -e foo.sh] La siguiente construcción está realmente errada. [-e foo.sh] Bucles: for ... in ... do ... done Sintaxis bash para bucles Los bucles son quizás la estructura de programación más útil para automatizar trabajos convencionales. Los bucles permiten la repetición de una serie de comandos, usualmente con leves variaciones en cada iteración. Estas variaciones se suelen ejecutar mediante una variable conocida como un iterator. Para cada iteración del bucle, la variable toma un valor diferente. Por ejemplo, elvis pudo utilizar el siguiente guión para afirmar su afecto por su colección de mascotas domésticas. [elvis@station elvis]$ cat nice #!/bin/bash for PET in kitty doggy gerbil newt do echo "nice $PET." done [elvis@station elvis]$ ./nice nice kitty. nice doggy. nice gerbil. nice newt. En este script, la variable de shell PET se utiliza como iterador. Con cada iteración del bucle, la variable adquiere un valor diferente. Más formalmente los bucles for ... in ... do ... done en bash utilizan la siguiente sintaxis. for iterador in lista do comando(s) ... done Para cada repetición del bucle, la variable iterator evaluará las palabras individuales en la expresión lista.
  • 6. 6 Suplemments Para un ejemplo más práctico, revisitaremos el guión de elvis shut. El usuario elvis desearía modificar su guión, con el fin de poder especificar archivos múltiples en la línea de comandos. Para implementar este cambio, esencialmente toma su guión anterior y lo delimita dentro de un bucle for ... in .. do ... done. En lugar de utilizar el primer parámetro posicional ($1) directamente, elvis utiliza un iterador a través de todos los argumentos provistos en la línea de comandos. [elvis@station elvis]$ cat shut #!/bin/bash # the first argument should be the name of the file to shut. for FILE in $* do if [ -e $FILE ] then chmod 600 $FILE else echo "The file $FILE does not exist." fi done A continuación, elvis utiliza el guión para modificar los permisos en los archivos example.sh y nice. [elvis@station elvis]$ ls -l total 12 -rwxr-xr-x 1 elvis elvis 212 Sep 3 -rwxr-xr-x 1 elvis elvis 77 Sep 4 -rwxrwxr-x 1 elvis elvis 188 Sep 4 [elvis@station elvis]$ ./shut example.sh biz nice The file biz does not exist. The file baz does not exist. [elvis@station elvis]$ ls -l total 12 -rw------1 elvis elvis 212 Sep 3 -rw------1 elvis elvis 77 Sep 4 -rwxrwxr-x 1 elvis elvis 188 Sep 4 10:56 example.sh 12:16 nice 12:31 shut baz 10:56 example.sh 12:16 nice 12:31 shut Observe el uso de la variable $* para generar la lista. El siguiente cuadro sugiere otros trucos del oficio. Table 1. Técnicas comunes para generar listas iterativas Cuando utilice... ...$i itera a través de ... for i in $* los argumentos de línea de comando del script for i in /etc/*.conf el del archivo coincidente con el comodín /etc/*.conf for i in $(command) las palabras devueltas por el comando command. Ejemplos
  • 7. 7 Suplemments Un script para "empacar" directorios El usuario elvis se da cuenta que a menudo está "tarring up" (archivando) directorios que no está utilizando. Decide crear un guión llamado pack, el cual le ayudará a archivar directorios más rápidamente. El script pack espera que uno o más directorios sean listados como argumentos. Para cada directorio, el script creará un archivo llamado como el directorio con la extensión .tgz agregada. Sólo si la creación del archivo tiene éxito, el script eliminará el directorio original. Como elvis considera detenidamente los directorios que los usuarios pueden especificar, se da cuenta que los directorios . y .. pueden causar problemas (¿por qué?), entonces les agrega una exclusión. [elvis@station elvis]$ cat pack #!/bin/bash for DIR in $*; do if [ -d $DIR ] then if [ "$DIR" == "." -o "$DIR" == ".." ] then echo "skipping directory $DIR" else tar cvzf $DIR.tgz $DIR && rm -fr $DIR fi else echo "skipping non directory $DIR" fi done El guión recorre todos los argumentos de línea de comandos provistos. El guión confirma que el argumento existe y que se refiere a un directorio. El guión aquí comprueba que el usuario no tiene el directorio . o .. especificado. En la práctica, hay aún algunos nombres de directorios que pueden causar problemas. ¿Puede usted pensar en alguno? Por último, aquí hay una línea que trabaja duro. Observe que el directorio original se elimina sólo si el comando tar tiene éxito. Él ensaya su script en estos dos directorios de prueba. [elvis@station elvis]$ mkdir test{1,2} [elvis@station elvis]$ touch test{1,2}/{one,two,three,four} [elvis@station elvis]$ ls -R .: pack test1 test2 ./test1: four one three two
  • 8. 8 Suplemments ./test2: four one three two [elvis@station elvis]$ ./pack test1 test2 test1/ test1/one test1/two test1/three test1/four test2/ test2/one test2/two test2/three test2/four [elvis@station elvis]$ ls -R .: pack test1.tgz test2.tgz Los directorios de prueba se han "empacado". Ejercicios en línea Lab Exercise Objetivo: Utilizar scripts shell para automatizar la rotación de imágenes. Estimated Time: 30 mins. Especificaciones Crear un script llamado rotate_cw que sirva para rotar imágenes 90 grados. Para realizar la rotación, debería utilizar el comando convert (analice la página de manual convert(1) y preste mucha atención a la opción rotate). A continuación presentamos un ejemplo de uso del comando convert para rotar una imagen. [elvis@station elvis]$ cp /usr/share/pixmaps/redhat-main-menu.png . [elvis@station elvis]$ convert -rotate 90 redhat-main-menu.png /tmp/redhat-mainmenu.png El archivo /tmp/redhat-main-menu.png es la misma imagen de redhat-mainmenu.png rotada 90 grados. El script debe esperar como argumentos múltiples nombres de archivo de las imágenes que van a ser rotadas. Debe asumir que los nombres de archivo no contienen componentes de directorio (por ejemplo, se referirán a archivos en el directorio actual). El guión debe generar un nuevo archivo de la imagen rotada y si la nueva imagen se genera correctamente, remplace la imagen original con la imagen rotada (dando la apariencia de rotar imágenes "en su lugar". Abandone el guión en su directorio de inicio y asegúrese que tiene permisos ejecutables.
  • 9. 9 Suplemments Deliverables Question 1 1. Un script bash ejecutable llamado ~/rotate_cw, el cual rotará imágenes en el directorio local cuyos nombres de archivo (sin componentes de directorio) pasan como argumentos. Capítulo 2 Codificación de caracteres e internacionalización Conceptos clave • • • • • When storing text, computers transform characters into a numeric representation. This process is referred to as encoding the text. In order to accommodate the demands of a variety of languages, several different encoding techniques have been developed. These techniques are represented by a variety of character sets. La técnica más sofisticada de codificación se conoce como el Conjunto Universal de Caracteres (UCS) La técnica de codificación en Linux de Red Hat Enterprise se conoce como UTF-8, la cual permite la flexibilidad de Unicode y a su vez retiene la compatibilidad de ASCII. La variable de entorno LANG se utiliza para especificar un lenguaje preferido del usuario y la codificación de caracter. ¿Qué son archivos? Linux, like most operating systems, stores information that needs to be preserved outside of the context of any individual process in files. (In this context, and for most of this Workbook, the term file is meant in the sense of regular file). Linux (and Unix) files store information using a simple model: information is stored as a single, ordered array of bytes, starting from at first and ending at the last. The number of bytes in the array is the length of the file. [1] What type of information is stored in files? Here are but a few examples. • • • The characters that compose the book report you want to store until you can come back and finish it tomorrow are stored in a file called (say) ~/bookreport.txt. The individual colors that make up the picture you took with your digital camera are stored in the file (say) /mnt/camera/dcim/100nikon/dscn1203.jpg. The characters which define the usernames of users on a Linux system (and their home directories, etc.) are stored in the file /etc/passwd.
  • 10. 10 Suplemments • The specific instructions which tell an x86 compatible CPU how to use the Linux kernel to list the files in a given directory are stored in the file /bin/ls. What is a Byte? At the lowest level, computers can only answer one type of question: is it on or off? What is it? When dealing with disks, it is a magnetic domain which is oriented up or down. When dealing with memory chips, it is a transistor which either has current or doesn't. Both of these are too difficult to mentally picture, so we will speak in terms of light switches that can either be on or off. To your computer, the contents of your file is reduced to what can be thought of as an array of (perhaps millions of) light switches. Each light switch can be used to store one bit of information (is it on, or is it off). Using a single light switch, you cannot store much information. To be more useful, an early convention was established: group the light switches into bunches of 8. Each series of 8 light switches (or magnetic domains, or transistors, ...) is a byte. More formally, a byte consists of 8 bits. Each permutation of ons and offs for a group of 8 switches can be assigned a number. All switches off, we'll assign 0. Only the first switch on, we'll assign 1; only the second switch on, 2; the first and second switch on, 3; and so on. How many numbers will it take to label each possible permutation for 8 light switches? A mathematician will quickly tell you the answer is 2^8, or 256. After grouping the light switches into groups of eight, your computer views the contents of your file as an array of bytes, each with a value ranging from 0 to 255. Data Encoding In order to store information as a series of bytes, the information must be somehow converted into a series of values ranging from 0 to 255. Converting information into such a format is called data encoding. What's the best way to do it? There is no single best way that works for all situations. Developing the right technique to encode data, which balances the goals of simplicity, efficiency (in terms of CPU performance and on disk storage), resilience to corruption, etc., is much of the art of computer science. As one example, consider the picture taken by a digital camera mentioned above. One encoding technique would divide the picture into pixels (dots), and for each pixel, record three bytes of information: the pixel's "redness", "greenness", and "blueness", each on a scale of 0 to 255. The first three bytes of the file would record the information for the first pixel, the second three bytes the second pixel, and so on. A picture format known as "PNM" does just this (plus some header information, such as how many pixels are in a row). Many other encoding techniques for images exist, some just as simple, many much more complex. Codificación de texto
  • 11. 11 Suplemments Perhaps the most common type of data which computers are asked to store is text. As computers have developed, a variety of techniques for encoding text have been developed, from the simple in concept (which could encode only the Latin alphabet used in Western languages) to complicated but powerful techniques that attempt to encode all forms of human written communication, even attempting to include historical languages such as Egyptian hieroglyphics. The following sections discuss many of the encoding techniques commonly used in Red Hat Enterprise Linux. ASCII One of the oldest, and still most commonly used techniques for encoding text is called ASCII encoding. ASCII encoding simply takes the 26 lowercase and 26 uppercase letters which compose the Latin alphabet, 10 digits, and common English punctuation characters (those found on a keyboard), and maps them to an integer between 0 and 255, as outlined in the following table. Table 1. ASCII Encoding of Printable Characters Integer Range Caracter 33-47 Puntuación: !"#$%&;*(*+,-./ 48-57 Los dígitos de 0 a 9 58-64 Puntuación: :;<=?>@ 65-90 Letras mayúsculas de la A hasta la Z 91-96 Puntuación: []^_` 97-122 Letras minúsculas de la a hasta la z 123-126 Puntuación: {|}~ What about the integers 0 - 32? These integers are mapped to special keys on early teletypes, many of which have to do with manipulating the spacing on the page being typed on. The following characters are commonly called "whitespace" characters. Table 2. Codificación ASCII de caracteres de espacio en blanco Número entero Caracter Nombre común Representación común 'b' 8 Backspace BS 9 HT Tab 't' 10 LF Nueva línea 'n' 12 FF Form Feed 'f' 13 CR Carriage Return 'r' 32 SPACE Space Bar Delete DEL 127
  • 12. 12 Suplemments Others of the first 32 integers are mapped to keys which did not directly influence the "printed page", but instead sent "out of band" control signals between two teletypes. Many of these control signals have special interpretations within Linux (and Unix). Table 3. ASCII Encoding of Control Signals Número entero Caracter Nombre común 4 EOT End of Transmission 7 BEL Campana terminal 27 audible Representación común de 'a' Escape ESC Generating Control Characters from the Keyboard Control and whitespace characters can be generated from the terminal keyboard directly using the CTRL key. For example, an audible bell can be generated using CTRL-G, while a backspace can be sent using CTRL-H, and we have already mentioned that CTRL-D is used to generate an "End of File" (or "End of Transmission"). Can you determine how the whitespace and control characters are mapped to the various CTRL key combinations? For example, what CTRL key combination generates a tab? What does CTRL-J generate? As you explore various control sequences, remember that the reset command will restore your terminal to sane behavior, if necessary. What about the values 128-255? ASCII encoding does not use them. The ASCII standard only defines the first 128 values of a byte, leaving the remaining 128 values to be defined by other schemes. Unicode (UCS) In order to overcome the limitations of ASCII and ISO 8859 based encoding techniques, a Universal Character Set has been developed, commonly referred to as UCS, or Unicode. The Unicode standard acknowledges the fact that one byte of information, with its ability to encode 256 different values, is simply not enough to encode the variety of glyphs found in human communication. Instead, the Unicode standard uses 4 bytes to encode each character. Think of 4 bytes as 32 light switches. If we were to again label each permutation of on and off for 32 switches with integers, the mathematician would tell you that you would need 4,294,967,296 (over 4 billion) integers. Thus, Unicode can encode over 4 billion glyphs (nearly enough for every person on the earth to have their own unique glyph; the user prince would approve). What are some of the features and drawbacks of Unicode encoding? Scale
  • 13. 13 Suplemments The Unicode standard will easily be able to encode the variety of glyphs used in human communication for a long time to come. Simplicidad The Unicode standard does have the simplicity of a sledgehammer. The number of bytes required to encode a set of characters is simply the number of characters multiplied by 4. Desperdicio While the Unicode standard is simple in concept, it is also very wasteful. The ability to encode 4 billion glyphs is nice, but in reality, much of the communication that occurs today uses less than a few hundred glyphs. Of the 32 bits (light switches) used to encode each character, the first 20 or so would always be "off". ASCII Non-compatibility For better or for worse, a huge amount of existing data is already ASCII encoded. In order to convert fully to Unicode, that data, and the programs that expect to read it, would have to be converted. The Unicode standard is an effective standard in principle, but in many respects it is ahead of its time, and perhaps forever will be. In practice, other techniques have been developed which attempt to preserve the scale and versatility of Unicode, while minimizing waste and maintaining ASCII compatibility. What must be sacrificed? Simplicity. Formato de transformación Unicode (UTF-8) UTF-8 encoding attempts to balance the flexibility of Unicode, and the practicality and pervasiveness of ASCII, with a significant sacrifice: variable length encoding. With variable length encoding, each character is no longer encoded using simply 1 byte, or simply 4 bytes. Instead, the traditional 127 ASCII characters are encoded using 1 byte (and, in fact, are identical to the existing ASCII standard). The next most commonly used 2000 or so characters are encoded using two bytes. The next 63000 or so characters are encoded using three bytes, and the more esoteric characters may be encoded using from four to six bytes. Details of the encoding technique can be found in the utf-8(7) man page. With full backwards compatibility to ASCII, and the same functional range of pure Unicode, what is there to lose? ISO 8859 (and similar) character set compatibility. UTF-8 attempts to bridge the gap between ASCII, which can be viewed as the primitive days of text encoding, and Unicode, which can be viewed as the utopia to aspire toward. Unfortunately, the "intermediate" methods, the ISO 8859 and other alternate character sets, are as incompatible with UTF-8 as they are with each other.
  • 14. 14 Suplemments Additionally, the simple relationship between the number of characters that are being stored and the amount of space (measured in bytes) it takes to store them is lost. How much space will it take to store 879 printed characters? If they are pure ASCII, the answer is 879. If they are Greek or Cyrillic, the answer is closer to twice that much. Text Encoding and the Open Source Community In the traditional development of operating systems, decisions such as what type of character encoding to use can be made centrally, with the possible disadvantage that the decision is wrong for some community of the operating system's users. In contrast, in the open source development model, these types of decisions are generally made by individuals and small groups of contributers. The advantages of the open source model are a flexible system which can accommodate a wide variety of encoding formats. The disadvantage is that users must often be educated and made aware of the issues involved with character encoding, because some parts of the assembled system use one technique while others parts use another. The library of man pages is an excellent example. When contributors to the open source community are faced with decisions involving potentially incompatible formats, they generally balance local needs with an appreciation for adhering to widely accepted standards where appropriate. The UTF-8 encoding format seems to be evolving as an accepted standard, and in recent releases has become the default for Red Hat Enterprise Linux. The following paragraph, extracted from the utf-8(7) man page, says it well: It can be hoped that in the foreseeable future, UTF-8 will replace ASCII and ISO 8859 at all levels as the common character encoding on POSIX systems, leading to a significantly richer environment for handling plain text. Internacionalización (i18n) As this Workbook continues to discuss many tools and techniques for searching, sorting, and manipulating text, the topic of internationalization cannot be avoided. In the open source community, internationalization is often abbreviated as i18n, a shorthand for saying "i-n with 18 letters in between". Applications which have been internationalized take into account different languages. In the Linux (and Unix) community, most applications look for the LANG environment variable to determine which language to use. At the simplest, this implies that programs will emit messages in the user's native language. [elvis@station elvis]$ echo $LANG en_US.UTF-8 [elvis@station elvis]$ chmod 666 /etc/passwd chmod: changing permissions of `/etc/passwd': Operation not permitted
  • 15. 15 Suplemments [elvis@station elvis]$ export LANG=de_DE.utf8 [elvis@station elvis]$ chmod 666 /etc/passwd chmod: Beim Setzen der Zugriffsrechte fr /etc/passwd: Die Operation ist nicht erlaubt More subtly, the choice of a particular language has implications for sorting orders, numeric formats, text encoding, and other issues. The LANG environment variable The LANG environment variable is used to define a user's language, and possibly the default encoding technique as well. The variable is expected to be set to a string using the following syntax: LL_CC.enc The variable context consists of the following three components. Table 1. Components of LANG environment variable Componente Función LL Código de lenguaje ISO 639 de dos letras CC (Optional) Two letter ISO 3166 Country Code enc (Optional) Character Encoding Code Set The locale command can be used to examine your current configuration (as can echo $LANG), while locale -a will list all settings currently supported by your system. The extent of the support for any given language will vary. The following tables list some selected language codes, country codes, and code set specifications. Table 2. Códigos de lenguaje seleccionados ISO 639 Código Lenguaje de Alemán el Griego en Inglés es Español fr Francés ja Japonés zh Chino Table 3. Selected ISO 3166 Country Codes
  • 16. 16 Suplemments Código País CA Canadá CN China DE Alemania ES España FR Francia GB Britain (UK) GR Grecia JP Japón NG Nigeria US Estados Unidos Table 4. Selected Character Encoding Code Sets Código utf8 País UTF-8 iso88591 ISO 8859-1 (Latín 1) iso885915 ISO 8859-15 (Latín 10) iso88596 ISO 8859-6 (Árabe) iso88592 ISO 8859-2 (Latín 2) See the gettext info pages (info gettext, or pinfo gettext) for a complete listing. ¿Necesito saber todo esto? We have tried to introduce the major concepts and components which affect how text is encoded and stored within Linux. After reading about character sets and language codes, one might be led to wonder, do I really need to know about all of this? If you are using simple text, restricted to the Latin alphabet of 26 characters, the answer is no. If you are asking the question 10 years from now, the answer will hopefully be no. If you do not fit into one of these two categories, however, you should have at least an acquaintance with the concept of internationalization, character sets, and the role of the LANG environment variable. Hopefully, as the open source community converges on a single encoding technique (currently UTF-8 seems the most likely), most of these issues will disappear. Until then, these are some key points to remember. 1. Un archivo ASCII ya es válido en uno de los conjuntos de caracteres ISO 8559. 2. Un archivo ASCII ya es válido en UTF-8.
  • 17. 17 Suplemments 3. A file encoded in one of the ISO 8559 character sets is not valid in UTF-8, and must be converted. 4. Using UTF-8, There is a one to one mapping between characters and bytes if and only if all of the characters are pure ASCII characters. If you are interested in more information, several man pages provide a more detailed introduction to the concepts outlined above. Start with charsets(7), and then follow with ascii(7), iso_8859_1(7), unicode(7) and utf-8(7). Additionally, the iconv command can be used to convert text files from one form of encoding to another. Capítulo 3 El Administrador de paquetes RPM Conceptos clave • • • El comando rpm se utiliza para agregar o quitar programas desde su sistema. Usted debe tener privilegios de root para agregar y quitar programas con rpm. Cualquiera puede solicitar paquetes instalados o archivos de paquetes. RPM: El administrador de paquetes de Red Hat El administrador de paquete de Red Hat probablemente es el elemento que mejor define la distribución de Red Hat Enterprise Linux. El administrador de paquete ofrece a los desarrolladores una forma de construir y distribuir programas, a los administradores una forma de instalar y mantener programas y a todos los usuarios una forma de solicitar información y verificar la integridad de programas instalados. La necesidad de administración de paquetes Antes de que la administración de paquetes se convirtiera en un concepto técnico, los programas se distribuyeron principalmente como "tarballs" (por ejemplo, archivos comprimidos tar) y sólo en forma de origen. Cualquiera que esté utilizando un producto de código abierto necesitará desempacar el tarball, compilar los ejecutables (esperando que sus sistema tenga las bibliotecas correctas para soportarlo), e instalar el producto en su sistema, a menudo con componentes en directorios múltiples (tales como /etc, /var/lib, /usr/bin/ y /usr/lib). Por lo general, los guiones distribuídos con código abierto realizan cada uno de estos pasos más fácilmente, pero incluso ellos no tratan dos problemas fundamentales. El primero es el problema de dependencia. A menudo, los productos de fuente abierta reutilizan código distribuido en forma de una biblioteca. Si la biblioteca apropiada no está instalada aún en el sistema, la aplicación que depende de ésta no servirá. El segundo problema fundamental es el mantenimiento. ¿Qué sucede cuando, después de seis meses lanzan una nueva versión del producto o alguien decide no querer más un producto en particular? Se necesitaría rastrear y quitar o remplazar los archivos individuales del producto. RPM está diseñado para ayudar a resolver esos dos problemas fundamentales.
  • 18. 18 Suplemments Los componentes RPM Cuando la gente habla de RPM se refiere a tres componentes colectivamente: la base de datos RPM, el ejecutable rpm y los archivos de paquete. La base de datos RPM La base de datos RPM es el centro del producto, proporciona la respuesta a los dos problemas antes mencionados. Cada vez que el programa es instalado por RPM, se crean las entradas de base de datos que representan cada archivo instalado. Debido a la base de datos, los archivos se pueden quitar fácilmente desde el sistema más tarde. Además, la base de datos mantiene una lista de dependencias requerida y provista por varios paquetes. Al instalar una aplicación que requiere una biblioteca, por ejemplo, la biblioteca se puede listar como dependencia específica y la base de datos puede responder de modo inequívoco por la presencia (o ausencia) de la biblioteca. La base de datos reside en el directorio /var/lib/rpm, pero aparte de saber que existe, los usuarios estándar (o incluso el administrador) poco necesitarán acceder al directorio directamente. El ejecutable rpm Los usuarios interactúan con la base de datos RPM a través del comando rpm. El ejecutable es utilizado por administradores para instalar, modernizar o quitar paquetes de programas y por el usuario para contestar preguntas acerca de los paquetes instalados o verificar su integridad. Examinaremos las solicitudes de RPM en detalle más adelante. Archivos de paquete Los archivos de paquete son el medio por el cual se distribuyen los programas. Los archivos de paquete suelen nombrarse mediante la siguiente convención. nombre-versión-publicación.archivo.rpm Por ejemplo, la primera publicación del archivo de paquete para versión 4.0.7 de la aplicación zsh de código abierto compilado para la arquitectura Intel x86 (y compatible) se llamaría convencionalmente zsh-4.0.7-1.i386.rpm. Los archivos de paquete son esencialmente archivos tar (aunque más de cerca parecen archivos cpio menos familiares) combinados con la información de encabezado, la cual nombra versiones y dependencias de estados para el paquete. Cuando la gente se refiere a la distribución de Red Hat, generalmente se refiere a la colección de archivos de paquete RPM que componen el programa instalado en una máquina. Realizar peticiones a la base de datos RPM
  • 19. 19 Suplemments Cuando se invoca con -q como su primera opción, el comando rpm realizará peticiones a la base de datos RPM (o algunas veces archivos de paquete RPM directamente). Formulación de peticiones RPM Cuando se presenta por primera vez a rpm, la sintaxis asociada con peticiones puede ser un poco abrumadora. Ayuda a pensar que cada petición consta de dos preguntas: (1)¿Qué paquetes estoy solicitando? (2)¿Qué pregunta estoy haciendo? Cada una de las opciones relacionadas con peticiones del comando rpm entra en una de estas dos categorías. Table 1. Opciones para realizar peticiones RPM con el fin de especificar paquetes Opción Especificaciones -a todos los paquetes instalados paquetenombre el paquete nombre -f filename el paquete propietario del archivo filename -p paquetearchivonombre solicitud del archivo de paquete paquete-archivo-nombre directamente. Esta opción es fundamentalmente diferente, pues todas las otras opciones realizan una petición a la base de datos RPM de paquetes instalados. Table 2. Opciones de peticiones RPM para especificar información Opción Especificaciones (por defecto) nombre del paquete y versión -i encabezado de información del paquete -l lista de archivos pertenecientes al paquete --queryformat str lista información especificada en cadena de texto de formato str Al escoger una opción desde el primer cuadro y cero o más opciones desde el segundo cuadro, los usuarios pueden formular preguntas específicas para la base de datos RPM. Ejemplos de peticiones Peticiones generales Por ejemplo, la opción -a realiza una solicitud en todos los paquetes instalados. Si no se hace otra pregunta, por defecto rpm retornará el nombre del paquete. Así rpm -qa retornará una lista de todos los paquetes instalados. [prince@station prince]$ rpm -qa basesystem-8.0-2
  • 20. 20 Suplemments expat-1.95.5-2 libacl-2.2.3-1 popt-1.8-0.69 rootfiles-7.2-6 cpio-2.5-3 gzip-1.3.3-9 ... Si se especifica un nombre de paquete, el rpm solicitará sólo aquel paquete. ¿Qué información retorna? De nuevo, por defecto, retornará el nombre del paquete. [prince@station prince]$ rpm -q bash bash-2.05b-20.1 Aunque quizás no es la más informativa de las solicitudes, prince al menos recibe la confirmación de la instalación del paquete, y un número de versión. Por lo general, cuando se solicita el nombre del paquete se pide más información. Por ejemplo, al agregar -i se generará un encabezado de información. [prince@station prince]$ rpm -qi bash Name : bash Relocations: /usr Version : 2.05b Vendor: Red Hat, Inc. Release : 20.1 Build Date: Wed 09 Apr 2003 09:02:36 AM EDT Install Date: Tue 08 Jul 2003 09:29:33 AM EDT Build Host: stripples.devel.redhat.com Group : System Environment/Shells Source RPM: bash-2.05b20.1.src.rpm Size : 1619204 License: GPL Signature : DSA/SHA1, Mon 09 Jun 2003 06:45:19 PM EDT, Key ID 219180cddb42a60e Packager : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla> Summary : The GNU Bourne Again shell (bash). Description : The GNU project Bourne Again shell (bash) is a shell or command language interpreter that is compatible with the Bourne shell (sh). Bash incorporates useful features from the Korn shell (ksh) and the C shell (csh) and most sh scripts can be run by bash without modification. Bash is the default shell for Red Hat Linux. O añadiendo un -l se generará una lista de todos los archivos instalados. [prince@station prince]$ rpm -ql bash /bin/bash /bin/bash2 /bin/sh /etc/skel/.bash_logout /etc/skel/.bash_profile /etc/skel/.bashrc /usr/bin/bashbug /usr/lib/bash /usr/share/doc/bash-2.05b /usr/share/doc/bash-2.05b/CHANGES ...
  • 21. 21 Suplemments Si se incluyen ambos en rpm -qil bash se generarían los dos. Investigación de un paquete desconocido ¿Qué sucede si usted ha encontrado un archivo en el sistema de archivos y quiere conocer a qué paquete de archivo pertenece? rpm -qf ... [prince@station etc]$ rpm -qf /etc/aep.conf hwcrypto-1.0-14 ¿Quiere saber más acerca del paquete? Agregue un -i. [prince@station etc]$ rpm -qf /etc/aep.conf -i Name : hwcrypto Relocations: (not relocateable) Version : 1.0 Vendor: Red Hat, Inc. Release : 14 Build Date: Tue 04 Feb 2003 06:20:37 AM EST Install Date: Tue 01 Apr 2003 11:27:43 AM EST Build Host: sylvester.devel.redhat.com Group : System Environment/Base Source RPM: hwcrypto-1.014.src.rpm Size : 711506 License: GPL Signature : DSA/SHA1, Mon 24 Feb 2003 01:25:46 AM EST, Key ID 219180cddb42a60ePackager : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla> Summary : Hardware cryptographic accelerator support. Description : This package contains the shared libraries used to interface with hardware cryptographic accelerators under Linux. ¿Existe documentación en el sistema que pueda dar mayor información acerca de esto? Agregue -l para listar los archivos relacionados con /etc/aep.conf. [prince@station etc]$ rpm -qf /etc/aep.conf -l /etc/aep /etc/aep.conf /etc/aep/aeptarg.bin /etc/aeplog.conf ... /usr/sbin/aepversion /usr/share/doc/hwcrypto-1.0 /usr/share/doc/hwcrypto-1.0/hwcrypto.txt /usr/share/doc/hwcrypto-1.0/readme.snmp /usr/share/snmp/mibs/cnStatTrap.mib En este caso, no mucho, pero quizás /usr/share/doc/hwcyrpto.txt ayudará un poco. Muchos paquetes incluyen páginas de man que se pueden leer o navegar. Al menos usted puede ubicar algunos archivos de configuración que quiera hojear para averiguar un poco más. Investigación de un archivo de paquete desconocido
  • 22. 22 Suplemments ¿Qué sucede si usted se encuentra un archivo de paquete que aún no ha sido instalado en su sistema? El comando rpm permite que los archivos de paquete sean solicitados con la opción -p. [prince@station RPMS]$ rpm -qil -p xsri-2.1.0-5.i386.rpm Name : xsri Relocations: (not relocateable) Version : 2.1.0 Vendor: Red Hat, Inc. Release : 5 Build Date: Sat 25 Jan 2003 03:37:15 AM EST Install Date: (not installed) Build Host: porky.devel.redhat.com Group : Amusements/Graphics Source RPM: xsri-2.1.05.src.rpm Size : 27190 License: GPL Signature : DSA/SHA1, Mon 24 Feb 2003 12:40:17 AM EST, Key ID 219180cddb42a60ePackager : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla> Summary : A program for displaying images on the background for X. Description : The xsri program allows the display of text, patterns, and images in the root window, so users can customize the XDM style login screen and/or the normal X background. Install xsri if you would like to change the look of your X login screen and/or X background. It is also used to display the default background (Red Hat logo). /usr/bin/xsri /usr/share/doc/xsri-2.1.0 /usr/share/doc/xsri-2.1.0/README Como se mencionó en el cuadro anterior, este es fundamentalmente un tipo diferente de solicitud. El archivo de paquete, el cual podría o no ser instalado, está entregando la información no la base de datos RPM. Formatear información específica ¿Qué sucedería si usted quisiera generar una lista de los 10 paquetes más grandes instalados en su sistema? Con el rpm -qai se vería el encabezado de información para cada paquete, el cual se podría buscar con grep sólo para los tamaños, pero entonces necesitaría nombres. Podría agregar nombres, pero luego el nombre y el tamaño estarían en líneas separadas. Usted capta la idea. Afortunadamente, el comando rpm permite a los usuarios componer preguntas específicas al especificar una cadena de formato de solicitud. La cadena está compuesta por un texto ASCII, pero los símbolos de la forma %{fieldname} serán remplazados por el campo de información relevante. ¿Qué se puede utilizar como nombres archivados? Para los principiantes, cualquier campo hallado en un encabezado de información de paquete, pero hay más. El comando rpm --querytags retornará una lista completa (e intimidatoria) de los campos disponibles.
  • 23. 23 Suplemments Para la tarea específica a la mano, prince realiza la siguiente solicitud, (observe que necesita especificar explícitamente una nueva línea con n). [prince@station RPMS]$ rpm -qa --queryformat "%{size} %{name}n" 0 basesystem 156498 expat 19248 libacl 111647 popt 1966 rootfiles 67679 cpio 162449 gzip ... Justo la información que prince necesitaba. Con una sintaxis de %anchura{nombre de campo} se puede especificar una anchura de campo opcional. Utilizando esto para limpiar su salida, y entubándose a sort y a head, prince genera con facilidad una lista de los 10 paquetes más grandes en su sistema. [prince@station RPMS]$ rpm -qa --queryformat "%10{size} %{name}n" | sort -rn | head 170890527 kernel-source 131431309 openoffice-i18n 100436356 openoffice-libs 84371104 gnucash 80018678 openoffice 75838208 rpmdb-redhat 55166532 Omni 54674111 tetex-doc 41939971 glibc-common 36762653 xorg Ejercicios en línea Lab Exercise Objetivo: Familiarizarse con peticiones RPM Tiempo estimado: 15 minutos. Especificaciones 1. Cree el archivo ~/bash_files que contenga una lista de todos los archivos pertenecientes al paquete bash listando un archivo por línea mediante referencias absolutas. 2. Cree el archivo ~/sshd_man, que liste los tres archivos que contengan las páginas de manual asociadas con el paquete openssh-server, un archivo por línea mediante referencias absolutas. 3. En el archivo incluya la palabra que mejor complete la siguiente oración. La biblioteca /lib/libcap.so.1.* se utiliza para obtener y establecer POSIX.1e __________. (No se preocupe si no entiende del todo la respuesta).
  • 24. 24 Suplemments 4. Cree el archivo ~/license_counts que presenta el número de ocurrencias de paquetes que tienen licencia bajo una licencia determinada para las 5 licencias más utilizadas, clasificadas en orden numérico descendente. Si se realiza correctamente, su archivo debería estar formateado como el siguiente. (No se preocupe si las cuentas reales o nombres de licencia son diferentes. También, usted podría notar lógicamente licencias similares, tales como LGPL/GPL y GPL/LGPL. No intente combinarlas en una sola entrada). 5. [prince@station prince]$ cat license_counts 6. 355 GPL 7. 147 LGPL 8. 53 BSD 9. 47 distributable 10. 18 xorg Deliverables Question 1 1. El archivo ~/bash_files, que contiene una lista de todos los archivos pertenecientes al paquete bash, un archivo por línea, mediante referencias absolutas. 2. El archivo ~/sshd_man que contiene una lista de los tres archivos que proporcionan páginas de manual para el paquete openssh-server, uno por línea, mediante referencias absolutas. 3. El archivo ~/whatis_libcap que contiene la respuesta de una palabra para lo que la biblioteca obtiene y establece. 4. El archivo ~/license_counts que presenta varias licencias bajo las cuales se distribuyen los paquetes, seguido por el número de paquetes a los cuales se aplica la licencia, clasificados en orden numérico descendente.