Comandos útiles Linux

# simple way to make propagate "execute" permissions (X sets execute if x is already set in some of the classes)
chmod -R a+X start_dir

# account expiration -> chage
chage -l USER

# disable bell / beep in terminal
xset b off

# ssh tunnels
# basic: VNC tunnel for display :4
ssh -L 5904:localhost:5904 usr23@remote-desktop.atwork.com

# Scenario 1: final is behind NAT, firewall at work, gateway host
# at final, create a "reverse tunnel" T1 from gateway to final. You will connect to port 22 of final (standard SSH) through port 8022 at gateway
ssh -R  8022:final.atwork.com:22 usr2@gateway.atwork.com
# at L, create a tunnel T2 from your laptop L port 8122 to port 8022 of gateway
ssh -L 8122:gateway.atwork.com:8022 usr2@gateway.atwork.com
# at L, connect to final through T2
ssh -p 8122 usr3@localhost

# Scenario 2: "only" problem is that final is behind work firewall
# at final
ssh -R  8022:final.atwork.com:22 usr2@laptop.athome.com
# at L
ssh -p 8022 usr3@localhost

# nc
# send file to peano and exit (without -q 0, nc keeps waiting for more data)
cat file | nc peano 8765 -q 0

AUDIO

# extract audio from video as 44.1KHz,320Kb/s MP3 file
ffmpeg -i input.wmv -ar 44100 -b:a 320k output.mp3

# Reduce audio volume
sox input.wav output.wav gain -n -24
# change sample frequency
sox input.wav -r 44.1k output.wav
# Convert audio (m4a to ogg)
ffmpeg -i Gimme_Gimme.m4a -map 0:0 -c:a libvorbis Gimme_Gimme.m4a.ogg
# flac to MP3 320 kbps
ffmpeg -i input.flac -b:a 320k output.mp3
# Rip CD audio
abcde -o vorbis

# Grabar CD audio
# 1: convertir a formato red book (stereo, 44.1KHz, 16 bits)
for f in $(ls *.mp3); do ffmpeg -i "$f" -map 0:0 "$f.wav" ; done
# 2: renombrar segun orden deseado
# 3: tostar (cdrtools)
wodim  -v -pad dev=/dev/sr0 -dao -swab *.wav

VIDEO

# convertir video a formato compatible con Windows Media Player (ideal para incrustar videos en Powerpoint)
# @see https://trac.ffmpeg.org/wiki/Encode/WindowsMediaPlayer
ffmpeg -r 30 -i foo.flv -codec:v mpeg4 -flags:v +qscale -global_quality:v 0 -codec:a libmp3lame foo.avi

# split video (ffmpeg)
ffmpeg  -i input.avi -ss hh:mm:ss -to hh:mm:ss -c copy output.avi

# multiplex audio & video
ffmpeg -i audio.m4a -strict -2 -i video.mp4 -strict -2 -c:a copy -c:v copy final.mp4

# resize video (ffmpeg)
ffmpeg -i IN.MP4 -c:v libx264 -c:a copy -s 800x600 OUT.mp4

# convert mjpeg video (ffmpeg)
# we may need to specify audio frequency because input video uses a strange frequency which is not automatically adapted
ffmpeg -i MVI_6229.AVI -c:v h264  -c:a mp3 -ar 44100  MVI_6229.AVI.mp4

# rip dvd (simple title-oriented movie; you may try -t 0 to rip all titles)
# -a -> select audio track, -E -> audio encoding (copy, vorbis, mp3, flac24...)
HandBrakeCLI -i /dev/cdrom -t 1 -o ~/output.m4v -e x264 -E "copy:*"

# a more specific approach: rip VOB by VOB (-strict -2 is required since AAC codec is considered experimental...)
ffmpeg -i /mnt/cdrom/VIDEO_TS/VTS_12_1.VOB -strict -2 vob_12_1.m4v

Images and PDF

# Resize image (Imagemagick's convert)
# use mogrify to resize "overwriting" the input image
convert input.jpg -resize 25%  image_scaled.jpg

# Rotate image
jpegtran -rotate 90 -outfile output.jpg input.jpg

# It's good to sharpen to compensate from the scale softness
# -unsharp RadiusxSigma+Amount+Threshold
convert input.jpg -resize "600x" -unsharp 2x0.5+0.7+0 -quality 98 output.jpg

# Raster
# http://www.imagemagick.org/Usage/transform/
convert autotrace:heart.gif  heart_traced.gif

# Clean whiteboard
convert img.gif -morphology Convolve DoG:15,100,0 -negate -normalize -blur 0x1 -channel RBG -level 60%,91%,0.1 $2

# Visual image directory
display 'vid:*.jpg'

# OCR image 09.jpg into 09.txt asuming portuguese language
tesseract 09.jpg 09 -l por

# Spell check (aspell)
# Usar -a para pipes (en vez de ficheros)
aspell -t -d pt_BR -c etimologia.tex

# Capture screen
scrot

# Image to pdf
convert *.png output.pdf



# Unir varios PDF en uno - por defecto comprime, a costa de la calidad (queda granulado -> -dPDFSETTINGS=/screen por defecto)
# Para mejor calidad, usar -dPDFSETTINGS=/prepress
gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=proyecto.pdf -dBATCH proyecto-p*.pdf

# Dividir un PDF en varios (uno por página)
gs -q -o proyecto-p%02d.pdf -sDEVICE=pdfwrite proyecto.pdf 

# Extraer un subconjunto de paginas del PDF
gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -dFirstPage=2 -dLastPage=6 -sOutputFile=proyecto.pdf original.pdf

# Reduce PDF size (gs): use maximum 150 dpi for images
gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dEmbedAllFonts=true -dSubsetFonts=true -dAutoRotatePages=/None -dColorImageDownsampleType=/Bicubic -dColorImageResolution=150 -dGrayImageDownsampleType=/Bicubic -dGrayImageResolution=150 -dMonoImageDownsampleType=/Bicubic -dMonoImageResolution=150 -sOutputFile=t.pdf input.pdf

# Convert PDF to JPG
# 200 DPI
gs -q -o output_p%04d.jpg -sDEVICE=jpeg -dPDFFitPage -r200 input.pdf

# Thumbnail of first page
gs -q -o output.jpg -sDEVICE=jpeg -dPDFFitPage -dLastPage=1 -g200x300 input.pdf

# Convert JPGs to single PDF
convert page1.jpg page1.pdf

Imprimir – Artículo relacionado: Comandos configuración CUPS

# Opciones más habituales de Cups: -n copies / -P page-list / -o sides=[one-sided|two-sided-long-edge|two-sided-short-edge]
# -o number-up=2
# <a href="https://www.cups.org/documentation.php/options.html">Listado completo de opciones Cups</a>
lp -d printer -o fit-to-page -o landscape XX.pdf
lp -d printer -o fit-to-page -o sides=two-sided-long-edge XX.pdf

# Añadir impresora
# PPDs from http://www.openprinting.org/printers
lpadmin -p name -E -v lpd://printer.localdomain/`hostname` -P xerox8560.ppd || exit 1
lpadmin -d $DEFAULT
lpoptions -p name -o Duplex=DuplexNoTumble -o PageSize=A4

# Lista colas
lpstat -a

# Imposicion (organizar paginas para folleto A5)
# pstops -> psutils
# Es importante especificar el tamaño de papel en ps2pdf, para que no se lie con la salida apaisada de pstops
pdftops input.pdf - | pstops -pa4 '4:-3L@.7(21cm,0)+0L@.7(21cm,14.85cm),1L@.7(21cm,0)+-2L@.7(21cm,14.85cm)' | ps2pdf -sPAPERSIZE=a4 - output.pdf
# Si las páginas de entrada ya están en A5, no hace falta escalarlas:
pdftops input.pdf - | pstops -pa4 '4:-3L(21cm,0)+0L(21cm,14.85cm),1L(21cm,0)+-2L(21cm,14.85cm)' | ps2pdf -sPAPERSIZE=a4 - output.pdf
# Unir dos páginas a5 en una página A4
pdftops INPUT - | psnup -pa4 -Pa5  -2 | ps2pdf -sPAPERSIZE=a4 - OUTPUT
# Más ejemplos de pstops: https://twiki.cern.ch/twiki/bin/view/Main/AVFedotovHowToPstops
# Crontab Fields
#minute hour day_of_month month day_of_week user  command
#/first 5 fields can be replaced by a special string, like/ @daily (run every midnigh), or @reboot (run once after reboot)
#List: 1,3,5,7,9. Range: 1-9/2 (2 is the step, optional)

# sudoers y sudoers.d/* tiene que tener permisos 440
# El orden importa, la ultima regla tiene precedencia sobre las anteriores
# Syntax: user/group doing sudo, host=(target user) [NOPASSWD:] comma list of commands (absolute path)
nagios  ALL=(ALL) NOPASSWD: /usr/cmd1,/usr/cmd2

# text conversion: UTF16 -> ascii
iconv -f utf16 fichero

# Calculators
bc
qcalc

# strace
# Opciones interesantes:
# -fp: conectarse a un proceso. Los descriptores de fichero se pueden consultar con lsof
# -c: contar número llamadas. Util para ver donde gasta el tiempo un proceso
# -T: cronometrar cada llamada al sistema

tcpdump

# Listar solicitudes DHCP
tcpdump  -s 1500 '((port 67 or port 68) and (udp[8:1] = 0x1))'
# Mostrar paquetes ARP
tcpdump -vvv arp
# Mostrar solicitudes a DNS de Google
tcpdump -n "dst host 8.8.8.8 and dst port 53"

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *