You are on page 1of 34

Unix Essentials

The Linux Filesystem

Instructor
Luis Felipe Londoño Muñoz
Centro de Servicios y gestión empresarial
Teleinformática
Detalles de archivos
OPCIONES DEL COMANDO ls
Switch Effect
-a, --all Incluye archivos que comienzan con .
Si el archivo es un directorio, lista la
-d, --directory información propia del directorio y no del
contenido del mismo.
Añade al final del nombre de cada archivo los
-F, --classify caracteres *, /, =, @, or | para indicar el tipo
de archivo.
Usa abreviaciones "humanamente legibles"
-h, --human-readable
cuando reporta la longitud de los archivos.
-i, --inode Lista el inodo de cada archivo
-l Usa el formato de listado extendido
Detalles de archivos
OPCIONES DEL COMANDO ls
Switch Effect
Usa UIDs and GIDs numericos en vez de
-n, --numeric-uid-gid
usernames y groupnames.
-r, --reverse Organiza en orden inverso
-R, --recursive Lista subdirectorios recursivamente
Report (or sort by) time specified by WORD
--time=WORD instead of mtime. WORD may be one of
"atime", "access", "ctime", or "status".
-t Ordena por fecha de modificación
Detalles de archivos
• OPCIONES DEL COMANDO ls
• Ejemplo:
[madonna@station madonna]$ ls –l /usr/games/
total 28
drwxr-xr-x 3 root root 4096 Jan 29 09:40 chromium

Permisos Grupo Fecha de


modificacion Filename
propietario
Usuario Longitud en
Contador de propietario Bytes
enlaces
Enlaces simbólicos
SINTAXIS:
ln –s TARGET [LINK]
NOTA: Crea el enlace LINK referenciando al archivo TARGET.
Ejemplo: ln -s mitextooriginal mienlacealtexto

ln –s TARGET... [DIRECTORY]
NOTA: Crea enlaces a los archivos TARGET en el directorio
DIRECTORY
Enlaces simbólicos
EJEMPLOS:
[blondie@station blondie]$ ln -s rhyme soft_link
[blondie@station blondie]$ ls –li
total 8
246085 -rw-rw-r-- 1 blondie blondie 29 Jul 18 15:25 rhyme
250186 lrwxrwxrwx 1 blondie blondie 5 Jul 18 15:26 soft_link -> rhyme
542526 drwxrwxr-x 2 blondie blondie 4096 Jul 18 15:25 stuff
Enlaces simbólicos
EJEMPLOS:
[einstein@station einstein]$ ln -s /usr/share/doc docs
[einstein@station einstein]$ ls -il
10513 lrwxrwxrwx 1 einstein einstein 14 Mar 18 20:31 docs -> /usr/share/doc
10512 -rw-rw---- 2 einstein einstein 949 Mar 18 20:10 hard_link
55326 drwxrwxr-x 2 einstein einstein 1024 Mar 18 20:28 stuff
Ubicando archivos con locate y
find
• El comando locate usa una base de datos para
localizar archivos rapidamente en el sistema
usando como patrón el nombre del archivo.
• El comando find realiza una búsqueda en tiempo
real en el sistema de archivos.
• El comando find puede realizar búsquedas
basadas en la información del inodo.
• El comando find puede ejecutar comandos
arbitrariamente sobre los archivos encontrados.
Ubicando archivos con locate y
find
• EJEMPLOS
[blondie@station blondie]$ locate umount
/bin/umount
/sbin/umount.cifs
/sbin/umount.nfs
/sbin/umount.nfs4
/usr/bin/gnome-umount

NOTA: El comando locate acepta metacacteres *, ?, y [...]
Ubicando archivos con locate y find
• EJEMPLOS
[blondie@station ~]$ locate "*fish*.png“
/usr/share/backgrounds/tiles/fish.png
/usr/share/gnome/help/fish/C/figures/fish_applet.png …
Ubicando archivos con locate y find
• SINTAXIS DEL COMANDO find
find (Directorio Raíz) (Criterio) (Acción)

Directorio a partir Criterio de


del cual se llevará a búsqueda Acción que se
cabo la búsqueda ejecutara sobre
los archivos
encontrados
Ubicando archivos con locate y find
EJEMPLOS find
[madonna@station madonna]$ find /etc -name "*.conf“
/etc/gdm/securitytokens.conf
/etc/gdm/custom.conf
/etc/gssapi_mech.conf Criterio de
... búsqueda
Ubicando archivos con locate y find
Criterios de búsqueda
switch specification
The file is a directory or regular file, and is
-empty
empty.
-group gname The file is group owned by gname.
-inum n The file has an inode number n.
-links n The file has n links.
-mmin n The file was last modified n minutes ago.
-mtime n The file was last modified n days ago.
-name pattern The file's name matches the file glob pattern.
Ubicando archivos con locate y find
Criterios de búsqueda
switch specification
-newer filename The file was modified more recently than filename.
-perm mode The file's permissions are exactly mode.
-perm -mode All of the permission bits mode are set for the file.
-perm +mode Any of the permission bits mode are set for the file.
-size n The file has a size of n.
The file is of type c, where c is "f" (regular file), "d"
-type c (directory), or "l" (symbolic link). See the man page for
more details.
-user uname File is owned by the user uname.
Ubicando archivos con locate y find
EJEMPLOS find
[elvis@station ~]$ find /usr/bin -type l
/usr/bin/lastb
[elvis@station ~]$ ls -l /usr/bin/lastb
lrwxrwxrwx 1 root root 4 Aug 22 15:36 /usr/bin/lastb -> last
Comprimiendo archivos: gzip y bzip2

• La compresión de archivos puede ahorrar


espacio en disco.
• El comando de compresión más utilizado es el
gzip.
• El comando bzip2 es más reciente, y
proporciona la compresión más eficiente.
Comprimiendo archivos: gzip y bzip2
EJEMPLO COMANDO gzip
[elvis@station elvis]$ ls -sh termcap
725K termcap
[elvis@station elvis]$ gzip termcap Se realiza la compresión
[elvis@station elvis]$ ls -sh termcap*
234K termcap.gz
[elvis@station elvis]$ gunzip termcap
[elvis@station elvis]$ ls -sh termcap* Se realiza la descompresión

725K termcap
Comprimiendo archivos: gzip y bzip2
EJEMPLO COMANDO bzip2
[elvis@station elvis]$ ls -sh termcap
725K termcap
[elvis@station elvis]$ bzip2 termcap Se realiza la compresión
[elvis@station elvis]$ ls -sh termcap*
185K termcap.bz2
[elvis@station elvis]$ bunzip2 termcap
[elvis@station elvis]$ ls -sh termcap* Se realiza la descompresión
725K termcap
empaquetando varios archivos con tar
• Archivar permite que una estructura de
directorio entera sea almacenada en un
archivo único.
• Los archivos son creados, listados y extraidos
con el comando tar.
• Los archivos que son archivados a menudo
también son comprimidos.
empaquetando varios archivos con tar
• El comando tar

Switch Effect
-c, --create Create an archive file
-x, --extract Extract an archive file
-t, --list List the contents of an archive file

[prince@station prince]$ tar -cf report.tar report


NOTA: La opción f se usa para especificar el nombre del archivo
report.tar
empaquetando varios archivos con tar
• El comando tar
EJEMPLOS:

[prince@station prince]$ tar -xf report.tar


NOTA: extrae el archivo report.tar

[prince@station prince]$ tar cvf net.tar /etc/sysconfig/


NOTA: La opción v muestra una lista de los archivos que han
sido procesados
empaquetando varios archivos con tar
• Comprimiendo y descomprimiendo archivos
EJEMPLOS:

[prince@station prince]$ tar czf /tmp/prince.tar.gz /home/prince .

NOTA: LA opción c crea el archivo, la opción f especifica el nombre del archivo a


crear y la opción z comprime el archivo recién creado, usando el comando gzip.

[prince@station prince]$ tar xvzf /tmp/prince.tar.gz

NOTA: LA opción x extrae el archivo, la opción f especifica el nombre del


archivo tar.gz que se va a descomprimir, la opción z usa la utilidad gzip para
la descompresión.
Reconocimiento de discos y
particionamiento
• La utilidad fdisk es usada para mostrar y editar
la tabla de particiones.
• Los discos pueden tener hasta 4 particiones
• Una partición primaria puede ser usada con
una partición extendida
• Las particiones extendidas son usadas como
contenedores para múltiples particiones
lógicas.
Reconocimiento de discos y
particionamiento
• ¿Cómo se refiere Linux a las particiones?
– La primera partición del drive /dev/hda es
reconocida como /dev/hda1.
– La séptima partición en el drive /dev/sdc son
referidos como /dev/sdc7.
Reconocimiento de discos y
particionamiento
• The first block (512 bytes) of every disk is reserved for the
Master Boot Record, or MBR. The MBR contains the
following items:
– Bootloader: On bootable disks, a low level executable referred
to as a bootloader resides in the MBR. When booting, BIOS
passes control to the bootloader, which is then responsible for
loading and passing control to the appropriate operating
system.
– Partition Table: On every disk, 64 bytes of the Master Boot
Record is reserved for the disk's partition table. This small
amount of space records information for up to 4 partitions,
referred to as primary partitions. For each partition, a starting
location, an ending location, and a partition type is recorded.
Reconocimiento de discos y
particionamiento
Tipos de Particiones
– Partición primaria: Son las divisiones crudas o primarias del disco,
solo puede haber 4 de éstas o 3 primarias y una extendida.
– Partición extendida: También conocida como partición secundaria
es otro tipo de partición que actúa como una partición primaria;
sirve para contener infinidad de unidades lógicas en su interior.
– Partición lógica: Ocupa una porción de la partición extendida o la
totalidad de la misma, la cual se ha formateado con un tipo
específico de sistema de archivos (FAT32, NTFS, ext2,...) y se le ha
asignado una unidad, así el sistema operativo reconoce las
particiones lógicas o su sistema de archivos.
Reconocimiento de discos y
particionamiento
Utilidad fdisk
• Su uso más simple es para listar particiones
conocidas.

NOTA: El siguiente comando es otra alternativa


[root@station root]# cat /proc/partitions
Utilidad fdisk
Column Function
The device node which references the partition, commonly
Device used as the "name" of the partition.
Identifies the "bootable" partition. On each disk, one of the
primary partitions may be labeled "bootable". Although not
Boot used by Linux (it is used by the MS/DOS bootloader), fdisk
does report and allow the user to set the bootable partition.
Start and End The starting and ending cylinder of the partition.
A 2 digit hexadecimal number representing the partition's
Id type Id.
Utilidad fdisk
The size of the partition, in "blocks" of 1024 bytes (i.e, 1k). Usually, this is
redundant (albeit convenient) information, as it can be calculated from
cylinder boundaries. For example, for the partition /dev/hda2, multiplying
the number of cylinders by the number of kilobytes per cylinder yields
20480040 exactly.
Blocks Sometimes, especially when examining disks partitioned by some utility
other than fdisk, cylinders do not fall exactly on cylinder boundaries. For
example, when performing similar math on the first partition (/dev/hda1),
the reported number of bytes is exactly 32 kilobytes short. In such
situations, fdisk flags the reported number of blocks with an appended
"+".
Id A 2 digit hexadecimal number representing the partition's type Id.
System A text name for the partition type, as defined by the Id.
Opciones fdisk
Command Function
m list command (m)enu
p (p)rint partition table
n create (n)ew partition
d (d)elete partition
t change partition (t)ype (Id)
q (q)uit without saving changes
w (w)rite changes and exit
Montando filesystems
• The mount command is used to attach the root directories
of filesystems to already existing directories in the directory
tree.
• The pre-existing directory is referred to as the mount point of
the mount.
• The umount command is used to detach filesystems (which
are not busy) from the directory tree.
• Various mount options can be used to qualify the capabilities
of mounted filesystems.
• The remount mount option can be used to associate new
options with already existing mounts.
Montando filesystems
• Mauricio va a explicar:
– Montaje de un dispositivo sda en el directorio
/var/www
– Montaje de un dispositivo USB (Usando una
consola virtual TTY)

You might also like