Mostrando entradas con la etiqueta terminal. Mostrar todas las entradas
Mostrando entradas con la etiqueta terminal. Mostrar todas las entradas

20121102

Comparar ficheros binarios en GNU/Linux - Compare binary files in GNU/Linux

Muchos usamos el comando diff para comparar ficheros de texto, pero qué pasa con los binarios? Para comparar ficheros binarios en GNU/Linux existen varios métodos (como para casi todo). Aquí comento alguno de ellos.
cmp:
bdispatcher@laptop:~$ cmp file1 file2
file1 file1 are different: byte 1, line 1

md5sum:
bdispatcher@laptop:~$ md5sum file1 file2
2fb1a6b293505c585a4fd75435dbf9a6  file1
e16c85c2851b2bee7a57167dbf05872b  file2

To compare two text files we can use the command diff, but what about the binary files? As we know, there are some different ways in GNU/Linux to achieve our objetive. Those are just two of them:

cmp:
bdispatcher@laptop:~$ cmp file1 file2
file1 file1 are different: byte 1, line 1

md5sum:
bdispatcher@laptop:~$ md5sum file1 file2
2fb1a6b293505c585a4fd75435dbf9a6  file1
e16c85c2851b2bee7a57167dbf05872b  file2

PS. I know, I know. My English is not good enought but, the more you help me, the more I learn.

20120718

Centos 6: desactivar barra de progreso en el arranque - Centos 6: disable progress bar at boot

A veces hay mejoras que a mi personalmente no me lo parecen tanto. El sustituir el arranque tradicional en el que ves como todo el proceso y los posibles fallos que puedan ocurrir, por una barra de progreso en una distro orientada a servidores, me parece una de estas mal llamadas mejoras, y es lo que ha sucedido en CentOS 6.
Para volver a ver el arranque tradicional, debemos editar el fichero de configuración de Grub /etc/grub.conf y borrar el parámetro rhgb en todas las líneas en las que aparezca (una por cada uno de los kernels que tengamos disponibles).
Si además queremos que el arranque sea más detallado todavía, borraremos también la palabra quiet.

There are some improvements that are not. The fact of changing the traditional and verbose boot to a newer but simpler one is one of them, and this is what has happend on the CentOS 6 distro.
To back to the old-style but more usefull and verbose boot process we have to edit the Grub configuration file, /etc/grub, and delete the word rhgb in all of owr kernel lines. If we want more info at boot time, we can delete the word quite too.

PS. I know, I know. My English is not good enought but, the more you help me, the more I learn.

20120620

GNU/Linux: Renombrar interfaz de red - GNU/Linux: Rename network interface

Hoy he clonado una máquina con VMWare para montar un cluster, y resulta que en la máquina resultante las interfaces tenían los nombres eth2 y eth3. Para poder aprovechar en lo posible la configuración de la máquina origen de la clonación, he procedido a cambiar los nombres de las interfaces con el siguiente comando:
ip link set dev nombre_actual name nuevo_nombre

Así, en mi caso sería:
ip link set dev eth2 name eth0
ip link set dev eth3 name eth1

Si lo que queremos es que los cambios se mantengan después de reiniciar el sistema, sólo debemos editar el siguiente fichero de configuración:
/etc/udev/rules.d/70-persistent-net.rules

Donde únicamente podemos cambiar el valor de la etiqueta NAME según indica un cometnario en el mismo fichero.
A que mola!!


Today I cloned a machine using VMWare to set up a cluster and at the destination machine had eth2 and eth3 as network interfaces name instead of eth0 and eth1. As I want to use the source machine configuration as much as possible I have changed the interfaces name with the following command:
ip link set dev current_name name new_name

So in this case I have typed:
ip link set dev eth2 name eth0
ip link set dev eth3 name eth1

If we want to make these changes permanent after a reboot, we have to edit the following config file:
/etc/udev/rules.d/70-persistent-net.rules

where we can only change the NAME key as is warned in the file.
Cool!!

PS. I know, I know. My English is not good enought but, the more you help me, the more I learn.

20120522

Vi: dividir la pantalla - Vi: split the window

Si vosotros sois también de esos chalaos que disfrutáis con el uso de Vi seguro este tip os será de utilidad. Si queremos dividir la pantalla de edición para editar otro archivo, o situarnos en dos puntos distintos del mismo archivo, sólo tenemos que teclear en modo comando lo siguiente:
:split

Con esto conseguiremos dividir la pantalla horizontalmente. Si lo que queremos es dividirla en vertical, teclearemos:
:vsplit

Complejo, eh!
Podemos ejecutar estas órdenes, combinándolas, tantas veces como queramos (no se si tiene límite) dividiendo una y otra vez la pantalla.

Si queremos abrir otro archivo, añadimos la ruta de este:
:split file_path
:vsplit file_path

O si lo que queremos es dividirla creando un archivo nuevo, añadiremos una n:
:split n
:vsplit n

Siempre y cuando no exista un fichero de nombre n en nuestro directorio de trabajo.
Para navegar entre las diferentes divisiones creadas, podemos utilizar:
CTRL+W W para pasar de una sección a otra hacia adelante.
CTRL+W tecla de dirección para pasar al siguiente marco en esa dirección. Podemos usar tanto las flechas como hjkl

También podemos redimensionar cada sección pulsando:
n CRTL+W + que hará crecer la sección en n líneas
n CRTL+W - que reducirá la sección en n líneas

Para cerrar cada una de ellas, como siempre :q :qw :x, etc.
Y esto es sólo el principio. Que lo disfrutéis.
:qw


If you are on of those geeks who enjoy typing and text editing with Vi I'm sure you'll find the following tip as useful as me.
You can split the the editor window typing the following while you're in command mode:
:split

To split it vertically, just type:
:vsplit

As easy as that! And we can repeat this command as many times as we like.

We can open other file on a new window typing:
:split file_path
:vsplit file_path

To create a new empty window:
:split n
:vsplit n

If there is a file called n on the working dvimirectory the previous command will open it instead of a new one :p
To navigate between the diferent divisions, we could type:
CTRL+W W to go forward to the next division
CTRL+W arroy key or khjkl to switch between windows on any direction.

We can algo change the window size typing:
n CRTL+W + qwhich will make the window grow n lines
n CRTL+W - which will srink the window n lines

And finally to close them,  :q :qw :x, etc.
This is just a piece of everything we can do with Vi. Enjoy it.
:qw

PS. I know, I know. My English is not good enought but, the more you help me, the more I learn.

20111119

Forzar chequeo de disco al reiniciar - Force check disk on next boot

Estos días he querido realizar un chequeo de los discos de un servidor GNU/Linux con particiones ext4, principalmente porque lo he pasado de físico a virtual y quería comprobar la integridad de estos.
Para hacerlo he utilizado la herramienta tune2fs que permite ajustar determinados parámetros de los sistemas de archivos ext2/ext3/ext4.
Normalmente el chequeo de discos se produce por los siguientes motivos:
 - se detecta algún problema y se chequea para eliminar inconsistencias
 - se ha alcanzado el tiempo máximo entre chequeo y chequeo (Check interval)
 - se ha alcanzado el número máximo de montajes (Maximun mount count)

Para ver estos parámetros introducimos lo siguiente en la consola, siendo /dev/sda1 nuestro fylesystem:
bdispatcher@server:~$ sudo tune2fs -l /dev/sda1

Lo que nos devuelve la información del sistema de archivos /dev/sda1 y que entre otras cosas contiene:
tune2fs 1.41.11 (14-Mar-2010)
Filesystem volume name:   <none>
Last mounted on:          /
Filesystem UUID:          3c30b294-a5f9-43d5-a679-ec12fee8f013
Filesystem magic number:  0xEF53
Default mount options:    (none)
Filesystem state:         clean
Filesystem OS type:       Linux
Mount count:              8
Maximum mount count:      34
Last checked:             Sat Oct 29 12:44:27 2011
Check interval:           15552000 (6 months)
Next check after:         Thu Apr 26 12:44:27 2012

Así que para forzar el chequeo en el próximo reinicio podemos cambiar cualquiera de esas condiciones. En este caso, cambiaremos el número de veces que se ha montado el filesystem:
bdispatcher@server:~$ sudo tune2fs -C 35 /dev/sda1
tune2fs 1.41.11 (14-Mar-2010)
Se pone la cuenta de montajes actual a 35
bdispatcher@server:~$ sudo tune2fs -l /dev/sda1 | grep -i mount
Last mounted on:          /
Default mount options:    (none)
Last mount time:          Sat Nov 19 15:48:33 2011
Mount count:              35
Maximum mount count:      34

Si queremos chequear todos los fylesystems, podemos optar por lo siguiente:
bdispatcher@server:~$ sudo touch /forcefsck

Con esto conseguiremos que en el próximo inicio se haga un chequeo completo de todos los fylesystems. El fichero forcefsck se borrará cuando termine el chequeo.

Agur!


Last week I wanted to check the filesystems of GNU/Linux box with ext4 partitions,  because I've migrated it from phisical to virtual (P2V).
To do that I used the tune2fs command which allows you to adjust tunable parameters on ext2/ext3/ext4 fylesystems.
Normally a fylesystem check occurs for the following reasons:
 - some inconsistency detected
 - the check interval has expired (Check interval)
 - the max mount count has been reached (Maximun mount count)

To show these parameter of the /dev/sda1 fylesystem, let's enter the following on a console:
bdispatcher@server:~$ sudo tune2fs -l /dev/sda1

And this is a brief summary of the info we get:
tune2fs 1.41.11 (14-Mar-2010)
Filesystem volume name:   <none>
Last mounted on:          /
Filesystem UUID:          3c30b294-a5f9-43d5-a679-ec12fee8f013
Filesystem magic number:  0xEF53
Default mount options:    (none)
Filesystem state:         clean
Filesystem OS type:       Linux
Mount count:              8
Maximum mount count:      34
Last checked:             Sat Oct 29 12:44:27 2011
Check interval:           15552000 (6 months)
Next check after:         Thu Apr 26 12:44:27 2012

So to force the filesystem chek on next boot we could change one o those conditions. In this case we'll change the Mount count value:
bdispatcher@server:~$ sudo tune2fs -C 35 /dev/sda1
tune2fs 1.41.11 (14-Mar-2010)
Setting mount count to 35
bdispatcher@server:~$ sudo tune2fs -l /dev/sda1 | grep -i mount
Last mounted on:          /
Default mount options:    (none)
Last mount time:          Sat Nov 19 15:48:33 2011
Mount count:              35
Maximum mount count:      34

We can also force a full filesystem check just 'touching' the following file:
bdispatcher@server:~$ sudo touch /forcefsck

After entering this command will get a full fylesystem check on the next boot. The  forcefsck file will be deleted on the next boot.

Ciao!

PS. I know, I know. My English is not good enought but, the more you help me, the more I learn.

20111105

Modo VI en la línea de comandos - VI mode on the command line

Desde los primeros días de mi primer trabajo en el que tuve que enfrentarme con la consola de equipos GNU/Linux me acostumbré, por consejo de un ex-jefe y amigo, a utilizarla en modo de comandos vi.
Para conseguir esto, basta con introducir lo siguiente:
set -o vi

A partir de ese momento, la consola funciona como el editor vi, así tienes un modo de inserción y un modo de ejecución de comandos. Desde este, por ejemplo, puedes realizar búsquedas en tu historial de comandos, como si buscases dentro de un documento de texto con vi.
Para volver al modo habitual, introduce lo siguiente:
set -o emacs

Por defecto los sistemas suelen venir en modo emacs, por lo que si como yo, prefieres el modo vi, puedes hacer que sea el predeterminado añadiendo la siguiente entrada al fichero /etc/inputrc:
set editting-mode vi

A disfrutarlo (o sufrirlo según el caso ;P)

Since first days I start working with GNU/Linux I got used to type and work with the vi mode enabled on the command line. To achieve this, just type the following:
set -o vi

Once you have change into the vi mode, the command line works as the vi editor, so it has the insert and the commands modes to work with. So if you, for instance, wants to search for a recently typed command, you can look for it on the same way you'll do on the vi editor.
To return to the previos configuration, just type:
set -o emacs

By default, the systems use to be configured on the emacs mode, but if you like the vi mode, you can do it the the default mode just adding to the /etc/inputrc the following line:
set editting-mode vi

Enjoy it (or suffer with it ;P)

PS. I know, I know. My English is not good enought but, the more you help me, the more I learn.

20111020

fdupes: Buscar ficheros duplicados - fdupes: Find duplicate files

Seguro que a muchos de vosotros se os ha presentado la situación de tener que buscar duplicados en vuestros sistemas GNU/Linux, ya sea en local o en red.
Buscando por la red puedes encontrar utilidades ya sea para la línea de comandos o con GUI. La cosa es que yo suelo utilizar fdupes.
Esta utilidad nos permite buscar y, si los encuentra, borrar los ficheros duplicados en nuestros discos.
Instalar esta utilidad en (K)Ubuntu es tan sencillo como:
sudo apt-get install fdupes

Una vez instalado sólo debemos ejecutarlo sobre la unidad que queramos y esperar el resultado.
bdispatcher@laptop:~$ sudo fdupes -r /home/bdispatcher/docs/web/
/home/bdispatcher/docs/web/backup/diptico_trip.FH11
/home/bdispatcher/docs/web/diptico_trip.FH11

/home/bdispatcher/docs/web/backup/fonfo1.jpg
/home/bdispatcher/docs/web/fonfo1.jpg

/home/bdispatcher/docs/web/backup/NORMAL
/home/bdispatcher/docs/web/NORMAL

/home/bdispatcher/docs/web/backup/Gothic.TTF
/home/bdispatcher/docs/web/Gothic.TTF

Cómo muchos de vosotros supondréis, fdupes hace uso del MD5 de los ficheros para ver si se encuentran duplicados o no.
Para más info sobre el uso de este comando, you know, man.

Probably most of you have wondered yourselves about the amount of disk wasted becouse of duplicate files on your GNU/Linux systems.
You could find some utils searching the web, but I'll reccomend you fdupes which would allow you to search and delete, if exists, the duplicate files on your filesystem.
To install this utility on your K(Ubuntu) system you only have to type is:
sudo apt-get install fdupes

Once installed, you just have to run it and wait for the result:
bdispatcher@laptop:~$ sudo fdupes -r /home/bdispatcher/docs/web/
/home/bdispatcher/docs/web/backup/diptico_trip.FH11
/home/bdispatcher/docs/web/diptico_trip.FH11

/home/bdispatcher/docs/web/backup/fonfo1.jpg
/home/bdispatcher/docs/web/fonfo1.jpg

/home/bdispatcher/docs/web/backup/NORMAL
/home/bdispatcher/docs/web/NORMAL

/home/bdispatcher/docs/web/backup/Gothic.TTF
/home/bdispatcher/docs/web/Gothic.TTF

As you could guess fdupes use MD5 to find out if two files are the same.
To get more info about this command, you know, man. 

PS. I know, I know. My English is not good enought but, the more you help me, the more I learn.

20110829

Renombrado de ficheros por lotes - Batch renaming files

Me ha vuelto a pasar!!! He ejecutado el siguiente script desde la línea de comandos para el renombrado de archivos en lotes:
for i in `ls`; do mv $i BKP_$i; done

mediante el cual, añado el prefijo BKP_ a todos los ficheros del directorio de trabajo, peeeeero lo he hecho en la ruta equivocada!!! Así que tengo un montón de archivos a los que les he añadido un prefijo que tengo que quitar.
La solución (o una de ellas) me la ofrece el comando cut. Con él, podemos seleccionar de una cadena de texto, los caracteres que queramos mostrar o quitar (--complement).
El nuevo script para reparar el entuerto sería:
for i in `ls`; do mv $i `echo $i| cut -c 1-4 --complement`; done

Y problema resuelto.

Ups, I did it again!!! I have run the following script from the command line to rename some files:
for i in `ls`; do mv $i BKP_$i; done

to add the prefix BKP_ to all files in the current directory, but I did it on the wrong path!!! So I have lots of files with a prefix to remove.
The solution (or at least, one of them) is to use the command cut. We can use it to choose some characters from a string.
The script to repair my mistake and remove (--complement) this prefix is:
for i in `ls`; do mv $i `echo $i| cut -c 1-4 --complement`; done

And its done!!!

PS. I know, I know. My English is not good enought but, the more you help me, the more I learn.

20110717

Comprobando los marcadores con wget- Testing your bookmarks with wget

Hoy, ojeando la página man de wget, me he topado con un método para checkear el fichero de marcadores, favoritos o bookmarks según nos guste, sin necesidad de instalar una extensión.
El comando en cuestión es el siguiente:
wget --spider --force-html -i bookmarks.html

Donde bookmarks.html son los marcadores una vez exportados desde nuestro navegador.
Al ejecutarlo, wget se encarga de ir comprobando los enlaces obteniendo una respuesta HTTP, así que todo lo que no sea 200 ok, es que algo no está funcionando como debiera.

Today, reading the man page of wget, I bumped into a way to check our bookmarks file without any extension.
The only thing we have to do is to run the following command:
wget --spider --force-html -i bookmarks.html

Once done that, wget will check every link on the bookmarks.html file and will return a HTTP response. If we get something different to 200 ok is that there is something wrong.

PS. I know, I know. My English is not good enought but, the more you help me, the more I learn.