Linux File System (1)

Embed Size (px)

Citation preview

  • 8/8/2019 Linux File System (1)

    1/34

    Unix Essentials

    The Linux Filesystem

    Instructor

    Luis Felipe Londoo MuozCentro de Servicios y gestin empresarial

    Teleinformtica

  • 8/8/2019 Linux File System (1)

    2/34

    Detalles de archivosOPCIONES DEL COMANDOls

    Switch Effect

    -a, --all Incluye archivos que comienzan con .

    -d, --directory

    Si el archivo es un directorio, lista la

    informacin propia del directorio y no del

    contenido del mismo.

    -F, --classify

    Aade al final del nombre de cada archivo los

    caracteres *, /, =, @, or | para indicar el tipo

    de archivo.

    -h, --human-readableUsa abreviaciones "humanamente legibles"

    cuando reporta la longitud de los archivos.

    -i, --inode Lista el inodo de cada archivo

    -l Usa el formato de listado extendido

  • 8/8/2019 Linux File System (1)

    3/34

    Switch Effect

    -n, --numeric-uid-gidUsa UIDs and GIDs numericos en vez de

    usernames y groupnames.-r, --reverse Organiza en orden inverso

    -R, --recursive Lista subdirectorios recursivamente

    --time=WORD

    Report (or sort by) time specified by WORD

    instead of mtime. WORD may be one of"atime", "access", "ctime", or "status".

    -t Ordena por fecha de modificacin

    Detalles de archivosOPCIONES DEL COMANDOls

  • 8/8/2019 Linux File System (1)

    4/34

  • 8/8/2019 Linux File System (1)

    5/34

    Enlaces simblicos

    SINTAXIS:

    lns TARGET [LINK]

    NOTA: Crea el enlace LINK referenciando al archivo TARGET.

    Ejemplo: ln -s mitextooriginal mienlacealtexto

    lns TARGET... [DIRECTORY]

    NOTA: Crea enlaces a los archivos TARGET en el directorioDIRECTORY

  • 8/8/2019 Linux File System (1)

    6/34

    Enlaces simblicos

    EJEMPLOS:

    [blondie@station blondie]$ ln -s rhyme soft_link

    [blondie@station blondie]$ ls li

    total 8246085 -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

  • 8/8/2019 Linux File System (1)

    7/34

    Enlaces simblicos

    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/doc10512 -rw-rw---- 2 einstein einstein 949 Mar 18 20:10 hard_link

    55326 drwxrwxr-x 2 einstein einstein 1024 Mar 18 20:28 stuff

  • 8/8/2019 Linux File System (1)

    8/34

    Ubicando archivos con locate y

    find El comando locate usa una base de datos para

    localizar archivos rapidamente en el sistema

    usando como patrn el nombre del archivo.

    El comando findrealiza una bsqueda en tiempo

    real en el sistema de archivos.

    El comando findpuede realizar bsquedas

    basadas en la informacin del inodo.

    El comando findpuede ejecutar comandos

    arbitrariamente sobre los archivos encontrados.

  • 8/8/2019 Linux File System (1)

    9/34

    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 [...]

  • 8/8/2019 Linux File System (1)

    10/34

    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

  • 8/8/2019 Linux File System (1)

    11/34

    SINTAXIS DEL COMANDOfind

    find (Directorio Raz) (Criterio) (Accin)

    Ubicando archivos con locate y find

    Directorio a partir

    del cual se llevar a

    cabo la bsqueda

    Criterio de

    bsqueda Accin que se

    ejecutara sobre

    los archivosencontrados

  • 8/8/2019 Linux File System (1)

    12/34

    EJEMPLOS find[madonna@station madonna]$ find /etc -name "*.conf

    /etc/gdm/securitytokens.conf

    /etc/gdm/custom.conf

    /etc/gssapi_mech.conf

    ...

    Ubicando archivos con locate y find

    Criterio de

    bsqueda

  • 8/8/2019 Linux File System (1)

    13/34

    Criterios de bsqueda

    Ubicando archivos con locate y find

    switch specification

    -emptyThe file is a directory or regular file, and is

    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.

  • 8/8/2019 Linux File System (1)

    14/34

    Criterios de bsqueda

    Ubicando archivos con locate y find

    switch specification

    -newer filename The file was modified more recently thanfilename.

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

    -type c

    The file is of type c, where c is "f" (regular file), "d"

    (directory), or "l" (symbolic link). See the man page for

    more details.

    -user uname File is owned by the user uname.

  • 8/8/2019 Linux File System (1)

    15/34

    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

    Ubicando archivos con locate y find

  • 8/8/2019 Linux File System (1)

    16/34

    Comprimiendo archivos: gzip y bzip2

    La compresin de archivos puede ahorrar

    espacio en disco.

    El comando de compresin ms utilizado es elgzip.

    El comando bzip2 es ms reciente, y

    proporciona la compresin ms eficiente.

  • 8/8/2019 Linux File System (1)

    17/34

    Comprimiendo archivos: gzip y bzip2

    EJEMPLO COMANDO gzip

    [elvis@station elvis]$ ls -sh termcap

    725K termcap

    [elvis@station elvis]$ gzip termcap

    [elvis@station elvis]$ ls -sh termcap*

    234K termcap.gz

    [elvis@station elvis]$ gunzip termcap

    [elvis@station elvis]$ ls -sh termcap*

    725K termcap

    Se realiza la compresin

    Se realiza la descompresin

  • 8/8/2019 Linux File System (1)

    18/34

    Comprimiendo archivos: gzip y bzip2

    EJEMPLO COMANDO bzip2

    [elvis@station elvis]$ ls -sh termcap

    725K termcap

    [elvis@station elvis]$ bzip2 termcap

    [elvis@station elvis]$ ls -sh termcap*

    185K termcap.bz2

    [elvis@station elvis]$ bunzip2 termcap

    [elvis@station elvis]$ ls -sh termcap*

    725K termcap

    Se realiza la compresin

    Se realiza la descompresin

  • 8/8/2019 Linux File System (1)

    19/34

    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 extraidoscon el comando tar.

    Los archivos que son archivados a menudo

    tambin son comprimidos.

  • 8/8/2019 Linux File System (1)

    20/34

    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 reportNOTA: La opcin f se usa para especificar el nombre delarchivo report.tar

    empaquetando varios archivos con tar

  • 8/8/2019 Linux File System (1)

    21/34

    El comando tar

    EJEMPLOS:

    [prince@station prince]$ tar -xf report.tarNOTA: extrae el archivo report.tar

    [prince@station prince]$ tar cvf net.tar /etc/sysconfig/NOTA: La opcin v muestra una lista de los archivos quehan sido procesados

    empaquetando varios archivos con tar

  • 8/8/2019 Linux File System (1)

    22/34

    Comprimiendo y descomprimiendo archivos

    EJEMPLOS:

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

    NOTA: LA opcin c crea el archivo, la opcin f especifica el nombre delarchivo a crear y la opcin z comprime el archivo recin creado, usandoel comando gzip.

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

    NOTA: LA opcin x extrae el archivo, la opcin f especifica elnombre del archivo tar.gz que se va a descomprimir, la opcin z usala utilidad gzip para la descompresin.

    empaquetando varios archivos con tar

  • 8/8/2019 Linux File System (1)

    23/34

    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 particin primaria puede ser usada con

    una particin extendida

    Las particiones extendidas son usadas comocontenedores para mltiples particiones

    lgicas.

  • 8/8/2019 Linux File System (1)

    24/34

    Reconocimiento de discos y

    particionamiento Cmo se refiere Linux a las particiones?

    La primera particin del drive /dev/hda es

    reconocida como /dev/hda1. La sptima particin en el drive /dev/sdc son

    referidos como /dev/sdc7.

  • 8/8/2019 Linux File System (1)

    25/34

    Reconocimiento de discos y

    particionamiento The first block (512 bytes) of every disk is reserved forthe Master Boot Record, or MBR. The MBR containsthe following items: Bootloader: On bootable disks, a low level executable

    referred to as a bootloaderresides in the MBR. Whenbooting, BIOS passes control to the bootloader, which isthen responsible for loading and passing control to theappropriate operating system.

    Partition Table: On every disk, 64 bytes of the Master Boot

    Record is reserved for the disk's partition table. This smallamount of space records information for up to 4 partitions,referred to asprimarypartitions. For each partition, astarting location, an ending location, and a partition type isrecorded.

  • 8/8/2019 Linux File System (1)

    26/34

    Reconocimiento de discos y

    particionamientoTipos de Particiones Particin primaria: Son las divisiones crudas o primarias

    del disco, solo puede haber 4 de stas o 3 primarias y unaextendida.

    Particin extendida: Tambin conocida como particinsecundaria es otro tipo de particin que acta como unaparticin primaria; sirve para contener infinidad deunidades lgicas en su interior.

    Particin lgica: Ocupa una porcin de la particin

    extendida o la totalidad de la misma, la cual se haformateado con un tipo especfico de sistema de archivos(FAT32, NTFS, ext2,...) y se le ha asignado una unidad, asel sistema operativo reconoce las particiones lgicas o susistema de archivos.

  • 8/8/2019 Linux File System (1)

    27/34

    Reconocimiento de discos y

    particionamiento

  • 8/8/2019 Linux File System (1)

    28/34

    Utilidad fdisk Su uso ms simple es para listar particiones

    conocidas.

    NOTA: El siguiente comando es otra alternativa

    [root@station root]#cat /proc/partitions

  • 8/8/2019 Linux File System (1)

    29/34

  • 8/8/2019 Linux File System (1)

    30/34

    Utilidad fdisk

    Blocks

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

  • 8/8/2019 Linux File System (1)

    31/34

    Opciones fdisk

    Command Function

    m list command (m)enu

    p (p)rint partition tablen create (n)ew partition

    d (d)elete partition

    t change partition (t)ype (Id)

    q (q)uit without saving changesw (w)rite changes and exit

  • 8/8/2019 Linux File System (1)

    32/34

    Montando filesystems The mount command is used to attach the root

    directories of filesystems to already existing directoriesin the directory tree.

    The pre-existing directory is referred to as the mountpointof 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 thecapabilities of mounted filesystems.

    The remount mount option can be used to associatenew options with already existing mounts.

  • 8/8/2019 Linux File System (1)

    33/34

    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)

  • 8/8/2019 Linux File System (1)

    34/34