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

26 de junio de 2014

How to merge two folders in Mac OS X or Linux


Short answer


Using the command line (Terminal):
cp -r -n ~/Desktop/src/* ~/Desktop/destination/
The command above adds the src content and the subdirectories to the destination without overwriting the content already present in the destination.

Long answer

Even if the content overlaps, you can still use cp to do it. Assume that you have two folders on your desktop: the src and the destination folders and you want to merge src into destination:
enter image description here
To merge, just do:
cp -r ~/Desktop/src/* ~/Desktop/destination/
NOTE When you use this, the content in src overwrites the content in the destination folder and adds the extra stuff that are missing in the destination. It shouldn't matter if you just want to add the missing files from src into destination.
ALSO it doesn't matter how many subdirectories are there, it will just go through each folder recursively and it will overwrite the content and will add the stuff that is missing in the destination folder.
BUT
PITFALL If you have huge files (like video files), you don't want to wait until everything is overwritten, it adds a lot of overhead.
PITFALL SOLUTION: Instead, you can use the -n flag to skip the overwriting:
cp -r -n ~/Desktop/src/* ~/Desktop/destination/
This is the description of the -n flag from the man page:
man cp
 -n    Do not overwrite an existing file.  (The -n option overrides any
       previous -f or -i options.)
Further Reading
  1. http://stackoverflow.com/questions/5088332/overhead-of-a-flag-in-cp-command
Source:

5 de noviembre de 2013

List merge conflicts with GIT


Made a merge, particularly, a big one and you want to know which where the files that had conflicts?

Then, this command might come handy:



You can also make a GIT alias this way:



and then use it like this:

24 de septiembre de 2013

Pimp my GIT: mejorando la interfaz para el uso de GIT

Siguiendo con el post de ayer, acá les comparto otras cosas del setup que tengo para git.

El setup este, y va dentro del .git/config de su clone git:


Con esto seteado, verán, por ejemplo, los git status con colores:




Podrán usar abreviaciones de los comandos, como:

- "git st" en vez de "git status"
- "git ci" en vez de "git commit"

Podrán ver un log más interesante y con colores con git log.

Verán los diff coloreados y con formato piola:



Git branch muestra coloreado el branch actual (los branches locales aparecen en amarillo):



Y los branches remotos aparecen en verde:

Inline image 4


Saludos!

23 de septiembre de 2013

Mostrar el branch de GIT y el status actual en el shell prompt y más!

Algunos trucos para configurar nuestro setup local de GIT:

Hace algunos años encontré algo como eso y, con el tiempo, armé una serie de scripts (algunas cosas que hice yo, algunas cosas que fui encontrando en la web), que hacen varias cosas con bash, que están piolas.

¿Qué cosas?

- que se detecte automáticamente si se está en una carpeta perteneciente a un repo git, y que, en el caso que sí lo sea, el prompt muestre información relevante del repo en que se está: branch y estado. Ejemplo:



en ese caso, estoy en el branch "master" y tengo archivos modificados (por eso la "m") y archivos que borré (por eso la "d").

- otra cosa muy piola es tener tab completion (que al apretar tab, con un comando a medio escribir, se muestren opciones para completar ese comando -o que se completen, si hubiera una opción posible). Imaginen eso aplicado a nombres de branch, comandos git y comandos de django (como "python manage.py runserver", por ejemplo).

- Algunas cosas más, como:
-- aumentar el tamaño del history de bash, pero eliminando duplicados, para que al hacer "ctrl r" en la consola, podamos buscar en el historial de los comandos que hicimos y encontrar resultados interesantes.
-- Una larga lista de colores definidos, para directamente poder usarlos en la definición del prompt.

Etc!

Les paso adjuntas las scripts para hacer todo esto:


Las dos primeras las ponen derecho en el home. El .profile pueden ponerlo derecho en el home (si usan Mac y no tienen otro .profile armado) o copiar su contenido a su .profile existente. Si usan Linux, pueden hacer esto mismo con el archivo .bashrc.
(notar que tienen un underscore los archivos, a propósito, para que no sobreescriban cosas sin querer y para que no los tome el file browser como archivos ocultos).


Un abrazo y may the bash be with you (?),


21 de mayo de 2012

Find what you are looking for with grep + find + xargs

Sometimes (very often) you are looking for this particular word of string that you think is in one file of a given project... but you don't know which file, and the project has a zillion files. And you feel like crying.

Well, don't, that's what this post is for :)

Let's go for the command:

$ find -iname | xargs grep -in

Where:
[1] a folder name: for instance, to look from the current folder, use ".".
[2] for instance, for files ending in .py, use this: "*.py"
[3] a string to look for. Case insensitively.

Example: Let's look for the string "hello", case insensitively, between the files of the current folder and its subfolders, inside files with filename ending in .py:

$ find . -iname '*.py' | xargs grep -in 'hello'

The output will say the file(s) and line numbers in those files where 'hello' was found.

25 de octubre de 2011

Add forwards search to bash command history

Hi!

While using the bash console, the ctrl+r command comes extremely handy to search backwards through the command history.

But while searching backwards, we may want to be able to navigate both ways (i.e., backwards and forwards). This is not activated by default.

How to activate it? Just run this command:

$ stty -ixon -ixoff 

Tadaa! And now you can do ctrl+r and ctrl+s to navigate backwards and forwards.

You can also add this to your .profile file (in Mac OS X) or your .bashrc file (in Linux) for this to be available every time you open a Bash terminal.

Cheers!