Categorías
hoy aprendí ...

… a recordar como montar un cdrom en linux

https://linuxconfig.org/how-to-mount-cdrom-in-linux

How to mount cdrom in Linux

15 October 2021 by Luke Reynolds

These days, CDs and DVDs are becoming less popular, in favor of flash drives and other convenient, portable media. However, you still may come across them every once in a while, and if your computer has a CD drive, you should be able to insert a disc and mount it on Linux.

In this tutorial, you’ll see the Linux commands necessary to mount a CDROM.

In this tutorial you will learn:

  • How to mount cdrom in Linux
CategoryRequirements, Conventions or Software Version Used
SystemAny Linux distro
SoftwareN/A
OtherPrivileged access to your Linux system as root or via the sudo command.
Conventions# – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Follow along with the steps below to mount a CD or DVD in Linux. Start off by inserting the disc into your computer, then run through these steps:

  1. First, try using the blkid command to see what device file your CD is using. Usually, this is going to be /dev/sr0, but it’s possible that yours is something different. You’ll know it’s the right one because it should say ISO9660Viewing device file path of cdrom in Linux
  2. Next, create a mount point for where you’d like to mount the CD to. Or, just pick an empty directory somewhere on your computer, if you already have a place in mind.$ sudo mkdir /mnt/cdrom
  3. Now we can use the mount command to map the device file to the directory we’ve just created.$ sudo mount /dev/sr0 /mnt/cdrom mount: /mnt/cdrom: WARNING: device write-protected, mounted read-only.
  4. Your CD or DVD should now be accessible in the directory which it was mounted to.$ cd /mnt/cdrom You can also verify that the mount was successful by using the mount command without further options.$ mount | grep cdrom Accessing a mounted cdrom in Linux
  5. When you are done, just unmount the CD and eject it from the disc tray.
    $ sudo umount /mnt/cdrom

Closing Thoughts

In this tutorial, we saw how to mount a CD or DVD rom on Linux systems. As you can see, the process is quite simple, and you will probably be able to do it in the future without a problem, now that you have done it once. Mounting and accessing a CDROM is pretty similar to mounting any other type of media.

Categorías
hoy aprendí ...

… a realizar chapucerías con caracteres y fórmulas en hojas de cálculo

Resulta que una tabla con nombres debía prepararla para ser procesada por PHP para generar contenido repetitivo. El nombre de la persona escrito de manera normal debia luego usarlo como nombre de archivo en el servidor web para cargar la foto, dejando todo en minúscula y reemplazando espacios con guión bajo, y acentos.

Ej:

Juan Pérez -> juan_perez

Resulta que en LibreOffice Calc (y asumo que en Excel también) hay una funciones para trabajar con strings (cadenas de caracteres).

=MINUSC(SUSTITUIR(B10;" ";"_"))

Básicamente logra pasar a minúscula y reemplazar los espacios.

Juan Pérez -> juan_pérez

La última parte de reemplazar los caracteres especiales de acentos, ñ, y apóstrofes lo terminé realizando en PHP con la ayuda de https://codigosdeprogramacion.com/2019/07/11/quitar-acentos-y-tildes-en-php/

function eliminar_acentos($cadena){

    //Reemplazamos la A y a
    $cadena = str_replace(
    array('Á', 'À', 'Â', 'Ä', 'á', 'à', 'ä', 'â', 'ª'),
    array('A', 'A', 'A', 'A', 'a', 'a', 'a', 'a', 'a'),
    $cadena
    );

    //Reemplazamos la E y e
    $cadena = str_replace(
    array('É', 'È', 'Ê', 'Ë', 'é', 'è', 'ë', 'ê'),
    array('E', 'E', 'E', 'E', 'e', 'e', 'e', 'e'),
    $cadena );

    //Reemplazamos la I y i
    $cadena = str_replace(
    array('Í', 'Ì', 'Ï', 'Î', 'í', 'ì', 'ï', 'î'),
    array('I', 'I', 'I', 'I', 'i', 'i', 'i', 'i'),
    $cadena );

    //Reemplazamos la O y o
    $cadena = str_replace(
    array('Ó', 'Ò', 'Ö', 'Ô', 'ó', 'ò', 'ö', 'ô'),
    array('O', 'O', 'O', 'O', 'o', 'o', 'o', 'o'),
    $cadena );

    //Reemplazamos la U y u
    $cadena = str_replace(
    array('Ú', 'Ù', 'Û', 'Ü', 'ú', 'ù', 'ü', 'û'),
    array('U', 'U', 'U', 'U', 'u', 'u', 'u', 'u'),
    $cadena );

    //Reemplazamos la N, n, C y c
    $cadena = str_replace(
    array('Ñ', 'ñ', 'Ç', 'ç'),
    array('N', 'n', 'C', 'c'),
    $cadena
    );

    //Reemplazamos apróstrofes ' ’ ` ´
    $cadena = str_replace(
    array("'", '’', '`', '´'),
    array('', '', '', ''),
    $cadena
    );

    return $cadena;
}

Y chau

Categorías
hoy aprendí ...

… a decirle a git que deje de darle bola al cambio de modo de los archivos

git config core.fileMode false

Encontrado en https://stackoverflow.com/a/1580644

Con una explicación muy buena:

Try:

git config core.fileMode false

From git-config(1):

core.fileMode
    Tells Git if the executable bit of files in the working tree
    is to be honored.

    Some filesystems lose the executable bit when a file that is
    marked as executable is checked out, or checks out a
    non-executable file with executable bit on. git-clone(1)
    or git-init(1) probe the filesystem to see if it handles the 
    executable bit correctly and this variable is automatically
    set as necessary.

    A repository, however, may be on a filesystem that handles
    the filemode correctly, and this variable is set to true when
    created, but later may be made accessible from another
    environment that loses the filemode (e.g. exporting ext4
    via CIFS mount, visiting a Cygwin created repository with Git
    for Windows or Eclipse). In such a case it may be necessary
    to set this variable to false. See git-update-index(1).

    The default is true (when core.filemode is not specified
    in the config file).

The -c flag can be used to set this option for one-off commands:

git -c core.fileMode=false diff

Typing the -c core.fileMode=false can be bothersome and so you can set this flag for all git repos or just for one git repo:

# this will set your the flag for your user for all git repos (modifies `$HOME/.gitconfig`)
git config --global core.fileMode false

# this will set the flag for one git repo (modifies `$current_git_repo/.git/config`)
git config core.fileMode false

Additionally, git clone and git init explicitly set core.fileMode to true in the repo config as discussed in Git global core.fileMode false overridden locally on clone

Warning

core.fileMode is not the best practice and should be used carefully. This setting only covers the executable bit of mode and never the read/write bits. In many cases you think you need this setting because you did something like chmod -R 777, making all your files executable. But in most projects most files don’t need and should not be executable for security reasons.

The proper way to solve this kind of situation is to handle folder and file permission separately, with something like:

find . -type d -exec chmod a+rwx {} \; # Make folders traversable and read/write
find . -type f -exec chmod a+rw {} \;  # Make files read/write

If you do that, you’ll never need to use core.fileMode, except in very rare environment.

Categorías
hoy aprendí ...

… a ordenar archivos en carpetas según el patrón de nombre

Descargando un montón de referencias desde Instagram usando esta maravillosa extensión, Instagram Download Button, me llené de archivos JPG y MP4 y se hacía necesario ordenarlos en carpetas.

El patrón es que todos los archivos tienen en la primer parte del nombre la perfil de Instagram y luego la fecha y hora original del posteo seguidos de un choclazo de números, así que tendría que ser «relativamente» sencillo poder encarpetarlos identificando el perfil.

nombre_perfil-YYYYMMDD_HHMMSS-XXXXXXXXX….. [jpg|mp4]

Buscando en encontré varias propuestas aproximadas para hacer algo como lo que quería

Y la opción ganadora

Extract part of a file name in bash

Específicamente esta respuesta que utiliza el comando SED. La única condición es que la primera parte no sean numeros.

El escenario

I have a folder with lots of files having a pattern, which is some string followed by a date and time:

BOS_CRM_SUS_20130101_10-00-10.csv (3 strings before date)
SEL_DMD_20141224_10-00-11.csv (2 strings before date)
SEL_DMD_SOUS_20141224_10-00-10.csv (3 strings before date)

I want to loop through the folder and extract only the part before the date and output into a file.

Output
BOS_CRM_SUS_
SEL_DMD_
SEL_DMD_SOUS_

La propuesta

Assuming you wont have numbers in the first part, you could use:

$ for i in *csv;do  str=$(echo $i|sed -r 's/[0-9]+.*//'); echo $str; done
BOS_CRM_SUS_
SEL_DMD_
SEL_DMD_SOUS_

Prueba

Cuando hice la prueba, solo mostrando el resultado del SED, funcionaba casi como lo deseaba, con el único tema que era que procesaba algunos archivos con otros patrón de nombre (que no eran necesarios) y los que si debía procesar dejaba el guión del medio.

Ejemplo:

almendromaestro-20220602_195749-285312905_1062446314350240_327302066906487345_n.jpeg

> almendromaestro-

Mi modificación a la RegExp

Agregar un guión que aparece antes de la regla para la fecha, así sólo busca los archivos que se aproximan al patrón.

sed -r 's/-[0-9]+.*//'

y pasó el testeo!

Script terminado

Básicamente hace un loop en todos los archivos que haya en la carpeta, separa el nombre y la almacena en STR (y lo mostramos para ir viendo el progreso), usa eso para verificar que si no existe una carpeta la crea, y luego mueve el archivo a la carpeta.

#!/bin/sh

for i in *.*
do
  str=$(echo $i|sed -r 's/-[0-9]+.*//'); 
  echo $str;
  if [ ! -d $str ]; then
      mkdir $str
  fi
  mv $i $str
done

Y chau!

Categorías
hoy aprendí ...

… a tener que escribir todo, incluso lo que ya sabía

Por que por más buena memoria que uno cree tener, a medida que el disco rígido se llena, cada vez es un esfuerzo mayúsculo tener que rememorar. Y a hacer limpieza!