Posts

Move directory in one git repository to another repository

I've been looking for a way to move a directory in a git repository to a new repository and preserve the history. We are reorganizing some code at work so that's what prompted me to start looking. The scenario is I have a repository and structure that looks like the following: repoA/  file1  file2  file3  directory1/   file1a   file1b   file1c  directory2/   file2a   file2b I want to move directory1 and all of the files in that directory(file1a, file1b, file1c) to a new git repository and preserve the change history. I want to end up with the following: repoB/  directory1/   file1a   file1b   file1c The  solution is here . I started with  this solution  but with the second solution I ended up with the files from my directory1 in the root of the repo. By the time I moved the files into a new directory1 the change history was stored in the root directory of the new repo so if I was i...

Get PID from running process

pgrep -f processname(i.e. vim, emacs, postgres, etc.)

Too many files for ls

Using ls you receive the error that there are too many arguments: Example: find /path/to/files/ -name "*.ZIP" -exec basename {} \;

Get path to current script in Python

import os os . path . dirname ( os . path . realpath ( __file__ ))   Source

Python string formatting in print statements

#!/usr/bin/env python # Format using a dictionary print '%(language)s has %(number)03d quote types.' % { "language" : "Python" , "number" : 2 } # Format using a list print '%s has %03d quote types.' % ( "Python" , 2 ) # Best method print '{} has {} quote types.'.format ( "Python" , 2 ) Planning to post more code snippets this year to remind me of how to do various things in Python. Source: Pyformat

Use rsync to copy a directory structure

To copy the directory structure only without copying any files: rsync -a -f"+ */" -f"- *" source destination/ If you don't put the trailing / on source you'll get the source directory created in destination. If you put the trailing / after source, you'll get all of the subdirectories of source created in destination without the top source directory. Source

Getting a list of databases from PostgreSQL at the command line

psql -Alxt|grep 'Name'|cut -d '|' -f 2