Command line tricks
SOME TIPS TO DO USEFUL TRICKS
These programs, scripts and commands have been tested on Ubuntu/Debian distributions of Linux. Feel free to contact me at fgonzalez[at]lpmd.cl
MANIPULATING TEXT FILES/DATA
MANIPULATING PHOTOS/VIDEOS/PDF
- Trim/crop images (eliminate borders)
- Merge/join many pics (jpg or png) in a single image
- Reduce the file size of a PDF
- Create a
gif
image from a video - Scale images or photos
- Merge/join many PDF files (or images) in a single PDF
- Extract images from a PDF
- MENCODER / FFMPEG: Manipulating videos
INTERNET
- rsync: Synchronize files between two computers
- SCP: Copy files from one computer to another
- Download multiple files from internet with a single command
- Convert videos from YouTube to Mp3
- Connect to internet from the command line
OPERATIVE SYSTEM
- Convert .rpm and .tar.gz to .deb
- Mount Pen-Drives
- Burn a DVD
- Change the screen background on Ubuntu 10.04 from command line
GNUPLOT
MANIPULATING TEXT FILES/DATA
July 28, 2021
November 29, 2010
MANIPULATING PHOTOS/VIDEOS/PDF
MANIPULATING PHOTOS/VIDEOS/PDF
- Trim/crop images (eliminate borders)
- Merge/join many pics (jpg or png) in a single image
- Reduce the file size of a PDF
- Create a
gif
image from a video - Scale images or photos
- Merge/join many PDF files (or images) in a single PDF
- Extract images from a PDF
- MENCODER / FFMPEG: Manipulating videos
December 12, 2021
January 23, 2016
January 23, 2016
REDUCE THE FILE SIZE OF A PDF |
If we want to save space in the hard drive, we can make a PDF lighter, looking exactly the same, but using less resolution. We can do it using the program gs -sDEVICE=pdfwrite -g10000x14151 -dNOPAUSE -dBATCH -dPDFFitPage -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -sOutputFile=reduced-pdf.pdf original-file.pdf We can change the resolution by changing -g10000x14151 to different page geometries, or simply use -sPAPERSIZE=a4. If the #!/bin/bash # The PDF file is an argument of the program for myPDF in "$1" #*.pdf do folder=$(echo $myPDF|sed -e 's/.pdf//') mkdir -p "$folder" cd "$folder" cp ../"$myPDF" . pdfimages -j "$myPDF" myimages for i in myimages*ppm; do convert -geometry 800 "$i" "$i".jpg; done for f in myimages*.jpg;do sam2p -j:quiet "$f" PDF: "$f".pdf ; done rm "$myPDF" myimages*ppm myimages*jpg pdftk myimages*.pdf cat output newfile.pdf rm myimages*pdf pages_new=$(pdfinfo newfile.pdf | grep Pages|awk '{print $2}') pages_old=$(pdfinfo "../$myPDF" | grep Pages|awk '{print $2}') size_new=$(pdfinfo newfile.pdf | grep "File size"|awk '{print $3}') size_old=$(pdfinfo "../$myPDF" | grep "File size"|awk '{print $3}') if [ $pages_new == $pages_old ]; then # echo "They have" $pages_new "pages both" if [ $size_new -lt $size_old ]; then #echo "The new one is lighter:" $size_new "vs antiguos" $size_old echo "The new $myPDF is lighter." mv newfile.pdf "../$(echo $myPDF|sed -e 's/.pdf/_v2.pdf/')" else echo "The new $myPDF is heavier than before. Reducction did not work. Erasing new one..." rm newfile.pdf fi else echo "WARNING: the amount pages is not the same" fi cd .. rmdir "$folder" done |
March 21, 2022
30 de Octubre, 2015
October 30, 2015
June 10, 2013
November 29, 2010
INTERNET
- rsync: Synchronize files between two computers
- SCP: Copy files from one computer to another
- Download multiple files from internet with a single command
- Convert videos from YouTube to Mp3
- Connect to internet from the command line
July 28, 2021
|
The Bring files to your computer If you are logged in to a remote computer (host), like a computer cluster, and your username is rsync -avuz myname@host:Fe* . If you type the same command immediately after, the files will not be copied again, because the program detects that the sources files are identical as the destination files. The program generates a list of files to copy that then copies. Here, we are using -a (file mode) -v (increased verbosity) -u (omit files that already exist in the destination and have a more recent time stamp than the source file) and -z (compress during transfer). Generate the list of files to copy (debug) Sometimes it is very useful to obtain the list of files that are going to be copied before actually transferring them, just to verify that those are actually the files we want to copy. Thus, we avoid replacing files by mistake. What we do, is simply omitting the destination: rsync -avuz myname@host:Fe* This command looks almost identical to the one above, but we have removed the dot ( . ) that represent the current destination directory (the one from which we are typing the command). The program prints the list of files that would have been transferred if we had gave it the destination directory. Copy only certain files from the source rsync -avuz --include='*/' --include='*.dat' --exclude='*' --prune-empty-dirs myname@host:Fe* . In this case, we are synchronizing the same directories as above, but we are copying only the files in them that end in .dat with the directories. For further informations about how to write patters of files, read the rsync manual. Copy everything, EXCEPT... rsync -avuz --exclude='XDATCAR' --exclude='OUTCAR' --exclude='*.xml' myname@host:Fe* . In this example, we are copying all the directories with all their files, except those ones that are named "XDATCAR", "OUTCAR," and those whose name ends in ".xml". This is particularly useful for VASP users. Copy only small files rsync -avuz --max-size=200kb --prune-empty-dirs myname@host:Fe* . Here, we are copying all directories that start with You can find and compress (simultaneously) all the big (heavier) files before transferring them using find . -type f -and -not -name "*.gz" -size +200k -exec gzip -v -f {} + Check out the Releasing space: remove files from the source after copying them rsync -avuz --prune-empty-dirs --remove-source-files myname@host:Fe* . This will copy all the files to the destination and delete them from the source, where they are being copied from. It will still leave empty folders behind in your source, which you can delete using rmdir */*; rmdir * or find . -type d -empty -delete I recommend executing the same command but without the More info about |
29 de Noviembre, 2010
29 de Noviembre, 2010
BAJAR VARIOS ARCHIVOS DE INTERNET SIMULTÁNEMENTE |
Digamos que tienes muchos archivos de fotos con extensión ".jpeg" en la pagina 'http://zeth.ciencias.uchile.cl/~mipagina'. Puedes bajar todos los archivos de esa carpeta (mipagina) con wget -e robots=off -r -l1 --no-parent -A.jpeg http://zeth.ciencias.uchile.cl/~mipagina NO SIRVE bajarlos con wget http://zeth.ciencias.uchile.cl/~mipagina/*.jpeg ya que esto solo funciona para sitios ftp. Obviamente puedes bajar otro tipo de archivos, cambiando "-A.jpeg" por "-A.pdf", "-A.gif" o lo que sea. |
29 de Noviembre, 2010
29 de Noviembre, 2010
SISTEMA OPERATIVO
- Convertir archivos .rpm y .tar.gz A un .deb
- Montar Pen-Drives
- Hacer DVD
- Cambiar el fondo de pantalla de bienvenida (Ubuntu 10.04)
29 de Noviembre, 2010
29 de Noviembre, 2010
MONTAR PEN-DRIVES |
mount -t vfat /dev/sdb1/ /media/nombre_de_la_carpeta |
29 de Noviembre, 2010
HACER DVD |
Escribir imagen .iso de DVD: readom dev=/dev/cdrom f=imagen.iso Quemar imagen .iso a DVD: growisofs -Z /dev/cdrom=imagen.iso |
29 de Noviembre, 2010