Report inadequate content

Bash in Harecoded


OS X renaming using parameter expansion

When it comes to rename files via command line there is no rename utility under OS X without installing Homebrew. But I still never needed to install it since there is a lot you can do by just making use of the shell parameter expansion.

The parameter expansion allows you to manipulate variables in a very convenient way and when mixed with the mv command you have an...


Terminal tuning for Git developers in Mac

If you work with Git in the terminal there are some tweaks you might want to apply to your prompt for safer and faster coding. The following lines are part of my ~/.bash_profile file. I use it on Mac although that might work in Linux as well.

You can copy and paste this code in your ~/.bash_profile (create it if it doesn't exist), save and open a new terminal to see the...


Kill processes using string search

A lot of Linux distributions (and Mac) come with a handy command named pkill installed by default. This command is very useful to kill processes in a more natural way.

Instead of doing a kill/killall based on the ID of the process or the binary name, you can just pass a string that appears in any part of the process list, including the parameters you used to start a...


Finding abusers. List of most frequent IPs in Apache log

Internet is full of malware and people with leisure time who will hammer your server with no good intentions, most of them will try to access well-known URLs looking for exploits of software like Wordpress (/wp-admin.php, /edit, etc...).

If you monitor for a while your access_log it's easy to find out unwanted behaviour. If you want to get a list of the most frequent IPs in...


Converting a CSV to SQL using 1 line in bash

The command line is very powerful and can do amazing stuff in one single line by pipelining a series of commands. This post is inspired after creating a line that mixed sed and awk, but with just only awk I'll show you an example on how to convert a CSV file to an SQL insert

Let's take an input CSV named events-2013-06-06.csv with 16 columns per line. It looks like...


Autocompletar hosts al escribir ssh en la terminal

Esta mañana mi compañero Borja me ha enseñado un pequeño truquito para olvidarse de los bookmarks en la terminal. Se trata de autocompletar el comando ssh con los hosts conocidos.

De este modo, cuando escribes ssh en la terminal puedes darle al tabulador para que sugiera o escriba el resto de host por ti. Ejemplo:

Existen múltiples maneras de hacer esto, leyendo...


Contar veces que se pide una URL (y las que no es esa URL)

Hay veces que queremos saber cuántas veces se ha pedido una URL en nuestro servidor y Google Analytics o otro servicio de monitorización basado en Javascript no está disponible. Entonces siempre podemos recurrir a la fuente original de datos, los logs de acceso (esos gran incomprendidos y frecuentemente abandonados) de Apache, Nginx o donde sea.

Si por ejemplo queremos...


Comando `tree` para Mac

Existe una utilidad llamada "tree" en Windows y Linux que sirve para ver un listado de directorio en un formato ASCII un poco más agradable a la vista. Si no quieres bajarte los MacPorts para esta pequeña utilidad lo más fácil es crear un script de una línea y enlazarlo en /bin para poder llamarlo directamente.

El comando en cuestión es este:

find . -print | sed -e...


Script for compressing files with gzip within the terminal with date

This is a simple bash script to compress in tar.gz (gzip) format a file or folder appending date to file name.

Save this file as and give it execution permissions. From terminal i could be: chmod 755 This script does the following:

Checks if you passed exactly 2 arguments Compresses your source Adds the date on the resulting filename Optionally changes permissions of...