Trabajos

Cookbook

Buscar todos los mp4 de carpetas «Archive-XXXX» y moverlas a otro directorio:

[j@localhost video]$ find . -path "./Archive*/*.mp4"
./Archive-2ec7/[AnimeParaTusSentidos] OGChan 01.mp4
./Archive-3a7c/[AnimeParaTusSentidos] OGChan 02.mp4
./Archive-90d2/[AnimeParaTusSentidos] OGChan 03.mp4
./Archive-9709/Oshiete! Galko-chan 04.mp4
./Archive-10a2/Oshiete! Galko-chan 05.mp4
./Archive-fdd2/Oshiete! Galko-chan 06.mp4
./Archive-c665/Oshiete! Galko-chan 07.mp4
./Archive-48f5/Oshiete! Galko-chan 01.mp4
./Archive-e4c6/Oshiete! Galko-chan 02.mp4
./Archive-44fe/Oshiete! Galko-chan 03.mp4
[j@localhost video]$ find . -path "./Archive*/*.mp4" -exec mv '{}' galko_chan/ ';'

Borrar directorios Archive-XXXX

[j@localhost video]$ find . -maxdepth 1 -type d -name "Archive*" -exec rm -rf '{}' ';'

Copiar ficheros ocultos (aquellos que empiezan por punto) del mi directorio HOME, profundidad máxima de 1 (necesitamos la opción de cp de GNU -t (–target-directory):

find /mnt/main/home/j -maxdepth 1 -name ".*" -exec cp -rp -t /mnt/datos/restaurar '{}' '+'

Deshabilitar comprobación de actualizaciones:

gsettings set org.gnome.software download-updates false

Listar ficheros regulares por orden de modificación y metérselos a sxiv. Primero find y después ls

find -maxdepth 1 -type f -exec ls -t {} + | sxiv -

En background:

( find -maxdepth 1 -type f -exec ls -t {} + | sxiv - & )

Como función «iv» («image viewer», me lo he inventado), pudiendo llamar iv a secas o iv <name>, donde <name> es lo que se pasa a find tal cual (incluyendo glob como por ejemplo *, por lo que necesitamos poner noglob con set -f para que el shell no las expanda antes).

iv() (
        # https://unix.stackexchange.com/a/388704
        local ret restore
        # set -x # activate debugging from here
        # https://stackoverflow.com/a/32279944
        # http://mywiki.wooledge.org/BashFAQ/050
        local name_option=()
        if [ "$1" ]; then
                name_option+=(-name "$1")
        else
                name_option+=(-regex '.*\(png\|jpg\|jpeg\|gif\|webp\|bmp\)$')
        fi
        set -f
        echo "$name_option"
        find -maxdepth 1 -type f "${name_option[@]}" -exec ls -t {} + | imv &
        ret=$?
        set +f
        # set +x # stop debugging from here
        return "$ret"
)

Otra forma, primero ls después find, inspirado en este enlace:

ls -tiQ1 | awk '{print $1}' | xargs -I X find -inum X -type f | sxiv -

Buscar todas las imágenes de un directorio y sumar su tamaño:

[j@furin ~]$ find Documents/ocio/img -type f -iregex '.*\.\(png\|jpg\|jpeg\|gif\|webp\|bmp\)$' -printf "%p\t%s\n" | awk '{ print; total += $2 }; END { print NR " files, total size: \t", total/2**30" GiB"}'
[...]
Documents/ocio/img/__oosaki_tenka_idolmaster_and_1_more_drawn_by_baretto_karasi07__90465cf2413c3ca859ddd2185f7fedbb.jpg	262351
Documents/ocio/img/unnamed_2.jpg	99101
Documents/ocio/img/unnamed (1).png	430740
Documents/ocio/img/Screenshot_2021-01-03 Active Otaku Channel.png	1026742
4874 files, total size: 	3.63792 GiB

Activar theme default_leftonly en powerline. De este modo se puede ver el exit code en un segmento al final:

sudo cp /etc/xdg/powerline/config.json ~/.config/powerline
sudo vim .config/powerline/config.json

Cambiar propiedad "shell"-> theme, de default a default_leftonly:

"shell": {
                        "colorscheme": "default",
                        "theme": "default_leftonly",
                        "local_themes": {
                                "continuation": "continuation",
                                "select": "select"
                        }
                },

Recargar:

powerline-daemon --replace

Mover todas las imágenes del directorio actual cuyo nombre consista en 13 dígitos al directorio 4chan:

find -maxdepth 1 -regextype posix-extended -regex '\./[[:digit:]]{13}\.(jpg|jpeg|png|gif|webm)$' -exec mv -t 4chan '{}' \+

Notas: podría ahorrarame el -maxdepth 1 porque ya lo buscamos en el regex, pero así es más eficiente. Si usamos exec con '{}' \; podríamos poner 4chan al final, pero con '{}' \+ tiene que ir antes. Para conseguirlo uso la opción -t de mv (sólo GNU).


Grabar de webcam sin que se desincronice el sonido, lo importante es la opción -preset ultrafast

ffmpeg -y -f v4l2 -input_format yuyv422 -video_size 640x480 -framerate 60 -i /dev/video0  -f alsa -i default  -c:v libx264 -preset ultrafast  -c:a aac  out_2.mkv

o con el MJPG nativo de la cámara:

ffmpeg -f v4l2 -input_format mjpeg -i /dev/video0 \
-f pulse -i alsa_input.usb-046d_Logitech_BRIO_69515057-02.analog-stereo -acodec pcm_s16le \
-c:v copy output.mkv

Aceleración gráfica en Firefox:

Habilitar en about:config

Reiniciar y comprobar en about:support

MOZ_ENABLE_WAYLAND=1 MOZ_LOG="PlatformDecoderModule:5" firefox 2>&1 | tee -a firefox_vaapi_platform_decoder_module.txt

MOZ_ENABLE_WAYLAND=1 MOZ_LOG="WidgetWayland:5" firefox 2>&1 | tee -a moz_enable_wayland_widget_wayland.txt

Ver también https://bugzilla.mozilla.org/show_bug.cgi?id=1619882 y https://bugzilla.mozilla.org/show_bug.cgi?id=1610199


Opciones para Steam, para cambiar entre DXVK y WINED3D:

PROTON_LOG=1 PROTON_NO_ESYNC=1 PROTON_USE_D9VK=0 RADV_PERFTEST=aco PROTON_USE_WINED3D=1 DXVK_HUD=full DXVK_LOG_LEVEL=none mangohud %command%

Modificar profile de multi monitor en XFCE: Applications -> Settings -> Settings Editor -> (Channel) displays -> Default, y activar o desactivar los monitores que queramos.


Copiar configuración generada por displays de Gnome a Gnome Display Manager:

sudo cp ~/.config/monitors.xml ~gdm/.config/

En un sistema pelado, podemos instalar la herramienta de display de Gnome con sudo pacman -S gnome-control-center


Ver archivos abiertos en un mountpoint (útil para umount: device is busy). Aquí:

lsof +f -- <mountpoint or device>

Listado de ventanas con títulos en X11:

xwininfo -root -children

-prune en find es una acción. Cuidado de añadir -o -print si queremos excluir el propio directorio excluído, y no sólo sus contenidos.


http://www.cyber-forensics.ch/acquiring-data-with-dd-dcfldd-dc3dd/

Crear md5 de una imagen con dd al vuelo:

dd if=/dev/sdb bs=65536 conv=sync,noerror | tee sdb_image.img | md5sum > sdb_image.md5

Comprobar ficheros con md5:

find -type f -exec md5sum "{}" + > checklist.chk
md5sum -c checklist.chk

Podemos guardar el resultado con:

md5sum -c checklist.md5 | tee checklist_result.txt

Creación de backup booteable de Arch (origen y destino en BTRFS):

mkfs.btrfs -L "Backup Arch" /dev/sdc1
mount /dev/sdc1 /mnt/backup_arch
btrfs subvolume create /mnt/backup_arch/.snapshots
btrfs send /.snapshots/23/snapshot/ | sudo btrfs receive /mnt/backup_arch/.snapshots/23
btrfs send -p /.snapshots/23/snapshot/ /.snapshots/26/snapshot/ | sudo btrfs receive /mnt/backup_arch/.snapshots/26/ # No nos interesan snapshots 24 y 25.
btrfs subvolume snapshot /mnt/backup_arch/.snapshots/26/snapshot /mnt/backup_arch/.snapshots/26_rw # Creamos un snapshot 26_rw a partir de 26, porque éste último es sólo de lectura.
btrfs subvolume list /mnt/backup_arch # Obtener ID de .snapshots/26_rw
btrfs subvolume set-default 296 /mnt/backup_arch

# Con pendrive de Arch...
mount /dev/sdc1 /mnt
arch-chroot /mnt
vim /etc/fstab # Cambiar UUID por el del disco que estamos usando para el backup, mirar con blkid. Comentar la línea de swap.
grub-mkconfig -o /boot/grub/grub.cfg
grub-install --target=i386-pc /dev/sdc
exit # o Ctr-D, para salir de chroot
umount /mnt

Mapear tecla Menu a Zenkaku/Hankaku de teclado japonés. Se puede hacer sólo con .Xmodmap así:

keycode 135 = Zenkaku_Hankaku NoSymbol Zenkaku_Hankaku

…pero en Chrome se registra tanto la tecla menú como la Zenkaku_Hankaku. Así que lo hago desde el kernel:

Obtenemos el scancode con

sudo evtest /dev/input/by-id/usb-Cypress_USB_Keyboard-event-kbd
Event: time 1618533578.401647, type 4 (EV_MSC), code 4 (MSC_SCAN), value 70065

En este caseo 70065

Creamos /etc/udev/hwdb.d/98-custom-keyboard.hwdb

evdev:input:b0003v04B4p0101*
 KEYBOARD_KEY_70065=zenkakuhankaku

sudo udevadm hwdb --update
sudo udevadm trigger --sysname-match="event*"

Comprobamos otra vez con evtest, debemos ver KEY_ZENKAKUHANKAKU:

Event: time 1618533638.809667, type 1 (EV_KEY), code 85 (KEY_ZENKAKUHANKAKU), value 0

Miramos con xev (code 85 del kernel + 8 = 93 de X):

state 0x10, keycode 93 (keysym 0x0 NoSymbol)

Creamos ~/.Xmodmap para asociar keycode 93 de X a keysym Zenkaku_Hankaku:

keycode 93 = Zenkaku_Hankaku NoSymbol Zenkaku_Hankaku NoSymbol Zenkaku_Hankaku

Hacemos:

j@furin ~ % xmodmap -v ~/.Xmodmap                                                                                                                                                                               [0]
! /home/j/.Xmodmap:
! 3:  keycode 93 = Zenkaku_Hankaku NoSymbol Zenkaku_Hankaku NoSymbol Zenkaku_Hankaku
        keycode 0x5d = Zenkaku_Hankaku BADKEYSYM Zenkaku_Hankaku BADKEYSYM Zenkaku_Hankaku
!
! executing work queue
!
        keycode 0x5d = Zenkaku_Hankaku BADKEYSYM Zenkaku_Hankaku BADKEYSYM Zenkaku_Hankaku

Volvemos a comprobar con xev:

state 0x10, keycode 93 (keysym 0xff2a, Zenkaku_Hankaku), same_screen YES,

https://askubuntu.com/a/94016

Borrar configuración de displays en XFCE:

j@furin ~ % killall xfconfd
j@furin ~ % rm -rf ~/.config/xfce4/xfconf/xfce-perchannel-xml/displays.xml                            [0]
j@furin ~ % xfce4-panel -r

Trabajar con ficheros que contengan dash:

j@bt ~ % ls -lah "--exclude" 
ls: unrecognized option '--exclude'
Try 'ls --help' for more information.
j@bt ~ % ls -lah -- "--exclude"
-rw-r--r-- 1 j j 52M Aug  5 21:49 --exclude

Use «–» to make rm stop parsing command line options, like this:
rm — –help

https://unix.stackexchange.com/a/1520

Ficheros de configuración bashrc de Gandi en /srv/data/etc/bash/bashrc

export TERM=xterm
set -o vi

alias log='vim /srv/data/var/log/apache/access.log'

Para php en /srv/data/etc/php/php-custom.ini:

; Only works with the release including php-5.4.4-7 or upper.
; You can not override all parameters.
; We keep the possibility to filter other parameters.
; Use this file with caution.
;
; Ne marche qu'avec la release comprenant php-5.4.4-7 ou supérieur.
; Vous ne pouvez pas remplacer tous les paramètres.
; Nous gardons la possibilité de filtrer d'autres paramètres.
; Utilisez ce fichier avec précaution.

Extraer con ffmpeg i-frames de un vídeo entre dos timestamps:

j@furin ~/Documents/ocio/img/akiba % ffmpeg -ss 00:01:26 -to 00:01:54 -i Japan__Night_videowalk_in_Akihabara_Tokyo_4K_\[2PqkuJMbHaw\].webm -vf "select='eq(pict_type,I)'" -vsync vfr -frame_pts true i_frames/pts_%d.jpeg

mput funciona con glob syntax:

ftp> mput *[0-9]*x[0-9]*.webp
mput 0_autorizacion_declinada-300x268.webp? ^C
Continue with mput? n
ftp> prompt
Interactive mode off.
ftp> mput *[0-9]*x[0-9]*.webp
local: 0_autorizacion_declinada-300x268.webp remote: 0_autorizacion_declinada-300x268.webp
227 Entering Passive Mode (109,61,89,53,114,110)
150 Opening Passive mode data transfer for STOR
226 Closing data connection, file transfer successful
[...]

cambiar path venv

Listamos sólo el nombre del fichero, recursivamente, ignorar binarios (-I):

j@arai ~/Pictures/0_manga/.venv % OLD_PATH="/mnt/media/Pictures/_manga/.venv"
j@arai ~/Pictures/0_manga/.venv % NEW_PATH="/mnt/media/Pictures/0_manga/.venv"
j@arai ~/Pictures/0_manga/.venv % grep -lrI "$OLD_PATH" | xargs sed -i "s|$OLD_PATH|$NEW_PATH|g"

Utilizar zip para juntar archivos sin comprimir, igual que tar. Útil para hacer ficheros CBZ con imágenes JPG/PNG que ya de por sí están comprimidas:

(.venv) j@arai ~/Pictures/0_manga/kodomo_no_jikan % zip --compression-method=store -r kodomo_no_jikan_jp_02.cbz 02
  adding: 02/ (stored 0%)
  adding: 02/00000.jpg (stored 0%)
  adding: 02/00001.jpg (stored 0%)